Numbers and maths
Operators
Section titled “Operators”2 + 2 * 10 // 22(2 + 3) * 4 // 2010 - 4 // 620 / 4 // 52^10 // 1,02417 mod 5 // 2% is the percent operator, not modulo. Writing 17 % 5 is a parse error
because 17 % is already a complete expression. Use mod or modulo.
^ is the only operator that groups from the right. A tower of powers is
worked out from the top down, as in mathematics: 2^3^2 means 2^(3^2), which
is 2^9. Everything else groups from the left, so 10-3-2 is (10-3)-2.
2^3^2 // 512(2^3)^2 // 64Operators in words
Section titled “Operators in words”Most operators have a word form, which is often how a line reads more naturally.
8 times 9 // 722 plus 3 // 55 minus 3 // 210 divide by 2 // 53 multiplied by 4 // 12with adds and without subtracts, which reads well for a running total.
40 with 2 // 4240 without 2 // 38Suffixes
Section titled “Suffixes”2.5k // 2,5003M // 3,000,000Functions
Section titled “Functions”sqrt(16) // 4abs(-5) // 5round(3.7) // 4floor(3.7) // 3ceil(3.2) // 4min(3, 7) // 3max(3, 7) // 7gcd(12, 18) // 6Numbers can be written and displayed in hexadecimal, binary or octal.
0xFF // 255hex(255) // 0xFFbin(5) // 0b101255 as hex // 0xFF255 as binary // 0b11111111Bit shifts, bitwise operators and data-size units are on the programmer math page.
Big integers
Section titled “Big integers”Suffix an integer with n to keep full precision beyond the safe range for
ordinary numbers.
123n * 2 // 246