langur

Numbers in langur are decimal floating point.

As of 0.8, langur uses a modified version of github.com/shopspring/decimal, a native Go library with arbitrary precision.

Prior to 0.8, langur uses Mike Cowlishaw's decimal C library, via the Go wrapper library github.com/rin01/decnum.

number literals

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 with an underscore.

E-notation may be used, but always requires a + or - after the e.

Rounding defaults to round-half-even.

The division maximum scale (digits after a decimal point) defaults to 33, but this can be set to something else. Being arbitrary precision, there has to be a set stopping point for division.

mode divMaxScale = 7 # sets max digits after decimal (for division) to 7

basex notation

Integer literals may use basex notation, such as 16xFF or 2x1010_0010 or -4x123.

Any base from 2 to 36 may be used, using the ASCII alphabet for digits higher than 9 (uppercase or lowercase).

At this time, basex notation is only available for integers within the range of a signed 64-bit int.

math operators

+ add
- subtract
x 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.

roots and exponents

Only 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.

division

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 and modulus

Remainder (rem) and modulus (mod) are not the same operator, but for positive operands will return the same result.

I, Anthony, barely know the difference between remainder and modulus, but I'd say if you don't know, you want the rem operator, not the mod operator (which involves more calculation).

constants

The following constants are available by using the keyword.

pi Archimedes' constant
phi the Golden Ratio
e Euler's number
n2 natural logarithm of 2
n10 natural logarithm of 10

So, to calculate the circumference of a circle with radius of 7, you could use the following.

# 2𝛑r 14 x pi # result == 43.98229715025710533847700736591304037876037159125148149364922429230942968800692598079248755478963895174996