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: I can't really think of any technological breakthrough stuff in the past 10 years or so, though.
gollark: I mostly just assume that we'll have basically no idea what technology will be around beyond 2050 or so.
gollark: No, that's Australia, Norway is very real.
gollark: If everyone believes in Norway, is Norway a god?
gollark: I mean, nature makes horrible things like those parasitic wasps, and we humans have nice things like computers and medicine.
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.