math.max

math.max
Function
Syntax
math.max(
  • numbers... : number
)

Returns number
API math
Source Lua (source)

Return the greatest of all the numbers given.

ExamplePrint the maximum value of user input
Read as many lines as the user inputs, and return the greatest value that they wrote.
Code
<nowiki>
local max = -(1/0) -- negative infinity
while true do
  local l = read()
  if tonumber(l) then
    max = math.max(max, tonumber(l))
  else
    break
  end
end
print(max)
    </nowiki>
Output The line the user wrote with the greatest value, or inf if they wrote no lines.
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.