Langur uses arbitrary precision decimal floating point for numbers.
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 available only for integers within the range of a signed 64-bit int.
A long number literal can be continued on the next line if the part on one line ends with an underscore and the part on the next line begins with an underscore.
val tau = 6._ _2831853071_7958647692_5286766559_0057683943_3879875021_ _1641949889_1846156328_1257241799_7256069650_6842341359_ _6429617302_6564613294_1876892191_0116446345_0718816256_ _9622349005_6820540387_7042211119_2892458979_0986076392_ _8857621951_3318668922_5695129646_7573566330_5424038182_ _9129713384_6920697220_9086532964_2678721452_0498282547
This is not to enter the fray of whether "pi is wrong" or not. :\
This can be used with basex notation if the basex portion is not split up.
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 = 7000 # sets max digits after decimal (for division) to 7000
+ | 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.