Langur uses arbitrary precision decimal floating point for numbers. This means that you can use extremely large or small numbers natively, and that fractional numbers are represented accurately.
Numbers in base 10 may be specified without qualification, such as 100 or 123.456.
Number literals may use underscores for visual clarity (such as 3_000_000), but cannot start or end with an underscore.
Scientific notation may be used, such as 1.234e+1000.
Scientific notation in langur source code always requires a + or - after the e.
Integer literals may use basex notation, such as 16xFF or 2x1010_0010 or -11x123.
Any base from 2 to 36 may be used, using the ASCII alphabet for digits higher than 9 (uppercase or lowercase).
The basex notation is presently limited to integers within the range of a signed 64-bit int.
A long number literal can be continued on the next line, but it must be formatted as shown below.
val tau = 6._ _2831853071_7958647692_5286766559_0057683943_3879875021_ _1641949889_1846156328_1257241799_7256069650_6842341359_ _6429617302_6564613294_1876892191_0116446345_0718816256
This is not to enter the fray of whether "pi is wrong" or not. :\
With numbers using arbitrary precision, there has to be a set stopping point for division.
The division maximum scale (digits after a decimal point) defaults to 33, but this can be set to something else.
mode divMaxScale = 700 # sets max digits after decimal (for division) to 700
+ | add |
- | subtract |
* | multiply |
/ | divide |
\ | truncating division |
// | floor division |
rem | remainder |
mod | modulus |
div | divisible by |
ndiv | not divisible by |
^ | exponent (right-associative) |
^/ | root (right-associative) |
Also see the operators page, which lists all operators with their precedence and associativity.
The standard division operator may yield a floating point number, even if the original numbers are integers.
Truncating division cuts off any floating point portion (analogous to the division operator in C when used with integers).
The floor division operator // may give different results than the truncating division operator \ if one of the operands is negative. See the following helpful link about floor division.
Remainder (rem) and modulus (mod) are not the same operator, but for positive operands will return the same result. You typically want to use the rem operator. The mod operator involves more calculation.
Integer roots and exponents may be calculated in the current implementation, but the left-hand operand can be a floating point number.
The root operator is very flexible, but when the result uses the full scale available (as determined by the divMaxScale mode), the last few digits might be taken as an approximation at this time.