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: How much? 32 octahedra/m³?
gollark: Our apiologists agree; you are *not* likely to sleep.
gollark: !time LyricLy
gollark: If we had access to raw source and not just the function, it would be possible to check for recursive behavior via looking for `eval`.
gollark: Maybe I should make reflector PRETEND you are playing against angel or something instead?
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.