Arithmetic

Arithmetics are traditional number operations such as addition, subtraction, multiplication, division and more derivatives.


Operators

The Lua core is capable of the following arithmetics:

Addition: + Adds two numbers to each other. For example: 5 + 3 returns 8
Subtraction: - Subtracts a number from an other number. For example: 5 - 3 returns 2
Multiplication: * Multiplies a number by an other number. For example: 5 * 3 returns 15
Division: / Divides a number by an other number. For example: 5 / 3 returns 1.6666666666667
Negation: - Negates a number. For example: - 5 returns -5
Exponentiation: ^ Raises a number by the power of an other number. For example: 5 ^ 3 returns 125
Modulus: % Gets the remainder of a number when dividing by another number. For example: 5 % 3 returns 2

Special Cases

print( 1 / 0 )
inf

print( - 1 / 0 )
-inf

print( 0 / 0 )
nan

print( 0 / 0 / 0 ) --   nan / inf
-inf

print( 1 / ( 1 / 0 ) ) --   1 / inf
0

print( 0 ^ 0 )
1

print( ( 1 / 0 ) - ( 1 / 0 ) ) --   inf - inf
nan
gollark: !q give 1 brick <@!258639553357676545>
gollark: !q take 1 clay <@!258639553357676545>
gollark: ... why do I keep DOING that?
gollark: !q take 15 fuel <@!258639553357676545>
gollark: !q give 1 clay <@!258639553357676545>
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.