Arithmetic

From ComputerCraft
(Redirected from +)
Jump to: navigation, search

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