Garry's Mod Wiki

Numbers & Integers

All numbers in Lua use the double-precision floating-point format. Even integers are stored in this format. The math library is the primary number operation library that contains trigonometric, rounding and useful constants. The following is a comprehensive list of all valid ways to define numbers in Lua. You can find the complete implementation of the number tokenization function in the LuaJIT source code.

print( 123, --- 123 123.456, --- 123.456 0x0FF.123, --- 255.071... -- Numbers can have an exponent part declared with 'e' or 'E' as a suffix -- This multiplies the base number by 10 to the power of the number after the 'e' -- As in, 123e4 is (123 * (10 ^ 4)) -- The number after the marker can be positive or negative, as seen below (handled at Lex time) 123e4, --- 1230000 123e+4, --- 1230000 123e-4, --- 0.0123 123.4e5, --- 12340000 --- Hexadecimal numbers can have an exponent part too, but its marked with a 'p' or 'P' --- Follows the same syntax rules as above 0x0FFp2, --- 1020 (0x0FF * (10 ^ 2)) 0x0FFp+2, --- 1020 0x0FFp-2, --- 63.75 -- 123e4.5 is not valid -- 0x0FFp123.456 is not valid )