Chapter III ·
The standard library
/
Lesson 17 of 27
Numbers: int & float
You'll learn: Tell integers from floats, convert between them, and know which operator returns which.
Lua 5.3 has two number subtypes: 64-bit *integer* and *float*
(double). / always returns a float; // floor-divides and
stays integer when both operands are integers. math.type(x)
reports the subtype; math.tointeger(x) narrows or returns
nil when the value isn't representable as an integer.
Output
idle
Hit Run to execute.
Try it:
Predict
math.type(1/1) and math.type(2^10). Then run and confirm. Why does 2^10 *not* return an integer?
See also
Values & types