Default
Math context and dialect
Mathematical context and dialect (calc)
mod
Returns the remainder of dividing x by y.
x integer or decimal value
y integer or decimal value
returns decimal remainder of x/y
cc math |type?
; returns context
pow
Returns base raised to the power of exponent.
base integer, decimal, or complex value
exponent integer, decimal, or complex value
returns decimal result of base raised to the power of exponent for integer/decimal inputs, complex result for complex inputs
cc math |type?
; returns context
pow 2 3
; returns 8
8.000000+0.000000i
-1.000000+0.000000i
log2
Returns the binary logarithm (base-2) of x.
x integer or decimal value
returns decimal binary logarithm of x
log2 8
; returns 3
log10
Returns the decimal logarithm (base-10) of x.
x integer or decimal value
returns decimal base-10 logarithm of x
log10 100
; returns 2
log
Returns the natural logarithm of x.
x integer, decimal, or complex value (must not be zero)
returns decimal natural logarithm of x for integer/decimal input, complex logarithm for complex input
log 1
; returns 0
log 2.718281828459045
; returns 1
0.000000+0.000000i
1.000000+0.000000i
log 0
; correctly causes error:
; Word not found: log. Check spelling or ensure the word is defined in the current context.
log complex 0 0
; correctly causes error:
; Word not found: log. Check spelling or ensure the word is defined in the current context.
log1p
Returns the natural logarithm of 1 plus its argument x.
x integer or decimal value
returns decimal natural logarithm of (1 + x)
log1p 0
; returns 0
logb
Returns the binary exponent of x.
x integer or decimal value
returns decimal binary exponent of x
logb 8
; returns 3
sq
Returns the square of x.
x integer or decimal value
returns decimal square of x
sq 4
; returns 16
sin
Returns the sine of the radian argument.
x integer, decimal, or complex value in radians
returns decimal sine of x for integer/decimal input, complex sine for complex input
sin 0
; returns 0
round\to sin pi 10
; returns 0
0.000000+0.000000i
1.000000+-0.000000i
cos
Returns the cosine of the radian argument.
x integer, decimal, or complex value in radians
returns decimal cosine of x for integer/decimal input, complex cosine for complex input
cos 0
; returns 1
1.000000+-0.000000i
-1.000000+-0.000000i
tan
Returns the tangent of the radian argument.
x integer, decimal, or complex value in radians
returns decimal tangent of x for integer/decimal input, complex tangent for complex input
tan 0
; returns 0
0.000000+0.000000i
1.000000+0.000000i
sqrt
Returns the square root of x.
x integer, decimal, or complex value
returns decimal square root of x for integer/decimal input, complex square root for complex input
sqrt 9
; returns 3
0.000000+1.000000i
abs
Returns the absolute value of a number.
x integer, decimal, or complex value
returns absolute value of x (same type as input for integer/decimal, decimal for complex)
abs -5
; returns 5
abs 5
; returns 5
abs complex 3 4
; returns 5
acos
Returns the arccosine (inverse cosine) in radians.
x integer or decimal value between -1 and 1
returns decimal arccosine of x in radians
acos 1
; returns 0
acosh
Returns the inverse hyperbolic cosine.
x integer or decimal value >= 1
returns decimal inverse hyperbolic cosine of x
acosh 1
; returns 0
asin
Returns the arcsine (inverse sine) in radians.
x integer or decimal value between -1 and 1
returns decimal arcsine of x in radians
asin 0
; returns 0
asinh
Returns the inverse hyperbolic sine.
x integer or decimal value
returns decimal inverse hyperbolic sine of x
asinh 0
; returns 0
atan
Returns the arctangent (inverse tangent) in radians.
x integer or decimal value
returns decimal arctangent of x in radians
atan 0
; returns 0
atan2
Returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.
y integer or decimal value
x integer or decimal value
returns decimal arctangent of y/x in radians, using signs to determine quadrant
atan2 0 1
; returns 0
atanh
Returns the inverse hyperbolic tangent.
x integer or decimal value between -1 and 1
returns decimal inverse hyperbolic tangent of x
atanh 0
; returns 0
ceil
Returns the least integer value greater than or equal to x.
x integer or decimal value
returns decimal ceiling of x (smallest integer >= x)
ceil 3.1
; returns 4
cbrt
Returns the cube root of x.
x integer or decimal value
returns decimal cube root of x
cbrt 8
; returns 2
copysign
Returns a value with the magnitude of x and the sign of y.
x integer or decimal value
y integer or decimal value
returns decimal with magnitude of x and sign of y
copysign 1 -2
; returns -1
dim
Returns the maximum of x-y or 0.
x integer or decimal value
y integer or decimal value
returns decimal max(x-y, 0)
dim 5 3
; returns 2
dim 3 5
; returns 0
round\ o
Rounds a decimal to the specified number of decimal places.
x decimal value to round
digits integer number of decimal places to round to
returns decimal rounded to specified number of decimal places
round\to 3.14159 2
; returns 3.14
round
Rounds a decimal to the nearest integer.
x decimal value
returns decimal rounded to nearest integer
round 3.7
; returns 4
round 3.2
; returns 3
roundtoeven
Returns the nearest integer, rounding ties to even.
x integer or decimal value
returns decimal rounded to nearest integer, with ties rounded to even
roundtoeven 3.5
; returns 4
roundtoeven 2.5
; returns 2
erf
Returns the error function of value.
x integer or decimal value
returns decimal error function value of x
erf 0
; returns 0
erfc
Returns the complementary error function of value.
x integer or decimal value
returns decimal complementary error function value of x
erfc 0
; returns 1
erfcinv
Returns the inverse of erfc(x) function.
x integer or decimal value between 0 and 2
returns decimal inverse complementary error function value of x
erfcinv 1
; returns 0
erfinv
Returns the inverse error function of value.
x integer or decimal value between -1 and 1
returns decimal inverse error function value of x
erfinv 0
; returns 0
exp
Returns e**x, the base-e exponential of x.
x integer, decimal, or complex value
returns decimal e^x for integer/decimal input, complex e^z for complex input
exp 0
; returns 1
exp 1
; returns 2.718281828459045
1.000000+0.000000i
-1.000000+0.000000i
exp2
Returns 2**x, the base-2 exponential of x.
x integer or decimal value
returns decimal 2^x
exp2 3
; returns 8
expm1
Returns e**x - 1, the base-e exponential of x minus 1. It is more accurate than exp(x) - 1 when x is near zero.
x integer or decimal value
returns decimal e^x - 1
expm1 0
; returns 0
fma
Returns x * y + z, computed with only one rounding. (That is, FMA returns the fused multiply-add of x, y, and z.)
x integer or decimal value
y integer or decimal value
z integer or decimal value
returns decimal (x * y) + z computed with only one rounding
fma 2 3 4
; returns 10
j0
Returns the order-zero Bessel function of the first kind.
x integer or decimal value
returns decimal order-zero Bessel function of the first kind
j0 0
; returns 1
j1
Returns the order-one Bessel function of the first kind.
x integer or decimal value
returns decimal order-one Bessel function of the first kind
j1 0
; returns 0
y0
Returns the order-zero Bessel function of the second kind.
x integer or decimal value
returns decimal order-zero Bessel function of the second kind
y0 1
; returns 0.08825696421567697
y1
Returns the order-one Bessel function of the second kind.
x integer or decimal value
returns decimal order-one Bessel function of the second kind
y1 1
; returns -0.7812128213002887
yn
Returns the order-n Bessel function of the second kind.
n integer order
x integer or decimal value
returns decimal order-n Bessel function of the second kind
yn 2 1
; returns -1.6506826068162543
jn
Returns the order-n Bessel function of the first kind.
n integer order
x integer or decimal value
returns decimal order-n Bessel function of the first kind
jn 2 1
; returns 0.11490348493190049
trunc
Returns the integer value of input.
x integer or decimal value
returns decimal integer value of x (truncated toward zero)
trunc 3.7
; returns 3
pi
Returns the mathematical constant π (pi).
none
returns decimal value of π (pi)
round\to pi 5
; returns 3.14159
deg->rad
Converts degrees to radians.
degrees integer or decimal value in degrees
returns decimal value in radians
deg->rad 180
; returns 3.141592653589793
is-near
Returns true if two decimals are close.
x integer or decimal value
y integer or decimal value
returns integer 1 if values are very close, 0 otherwise
is-near 0.0000000000001 0
; returns 1
is-near 0.1 0
; returns 0
near-zero
Returns true if a decimal is close to zero.
x integer or decimal value
returns integer 1 if value is very close to zero, 0 otherwise
near-zero 0.0000000000001
; returns 1
near-zero 0.1
; returns 0
is-prime
Returns true if the integer is a prime number.
n integer value to check
returns integer 1 if n is prime, 0 otherwise
to-eyr
Converts math dialect to Eyr dialect.
block block containing math expressions
returns block converted to Eyr dialect
to-eyr { 1 + 2 * 3 } |type?
; returns block
calc
Evaluates expressions in math dialect.
block block containing math expressions with proper operator precedence and parentheses support
returns result of evaluating the math expressions following standard mathematical order of operations
calc { 1 + 2 * 3 }
; returns 7
calc { 2 + 3 * 4 }
; returns 14
calc { 10 - 6 / 2 }
; returns 7
calc { 2 * 3 + 4 }
; returns 10
calc { 8 / 2 - 1 }
; returns 3
calc { ( 1 + 2 ) * 3 }
; returns 9
calc { 2 * ( 3 + 4 ) }
; returns 14
calc { ( 10 - 6 ) / 2 }
; returns 2
calc { ( 2 + 3 ) * ( 4 - 1 ) }
; returns 15
calc { 2 + ( 3 * ( 4 + 1 ) ) }
; returns 17
calc { ( ( 2 + 3 ) * 4 ) - 1 }
; returns 19
gcd
Returns the greatest common divisor of two integers using Euclidean algorithm.
a integer value
b integer value
returns integer greatest common divisor of a and b
gcd 48 18
; returns 6
gcd 17 13
; returns 1
gcd 100 25
; returns 25
gcd 0 5
; returns 5
gcd 7 0
; returns 7
Validation
validation dialect for Rye values
validate
Validates and transforms data according to specified rules, returning a dictionary with converted values or an error.
data Dictionary, Context, or List to validate
rules Block containing validation rules
returns validated Dictionary/Context/List with converted values or error if validation fails
validate>ctx
Validates and transforms data according to specified rules, returning a context object for easy field access.
data Dictionary to validate
rules Block containing validation rules
returns validated Context with converted values or error if validation fails
validate>ctx dict { a: 1 } { a: optional 0 } |-> 'a
; returns 1
EYR Dialect
Stack based evaluator / dialect
eyr
Evaluates Rye block as Eyr (postfix) stack based code.
block Block of code to evaluate in EYR (postfix) mode
returns result of evaluating the block as postfix stack-based code
eyr { 1 2 }
; returns 3
eyr { 5 3 }
; returns 2
eyr { 4 2 }
; returns 8
eyr { 6 2 }
; returns 3
eyr { 1 2 3 }
; returns 3
rye0
Evaluates Rye block as Rye0 dialect.
block Block of code to evaluate in RYE0 dialect
returns result of evaluating the block in RYE0 dialect
rye00
Evaluates Rye block as Rye00 dialect (builtins and integers only).
block Block of code to evaluate in RYE00 dialect (builtins and integers only)
returns result of evaluating the block in RYE00 dialect (minimal feature set)
eyr\full
Evaluates Rye block as Eyr (postfix) stack based code.
block Block of code to evaluate in EYR mode returning full stack as block
returns block containing all values from the EYR evaluation stack
eyr\loop
Evaluates Rye block in loop as Eyr code (postfix stack based) N times.
count Integer number of times to loop
block Block of EYR code to execute in each iteration
returns result of the final EYR evaluation
to-eyr
Evaluates Rye block as Eyr (postfix) stack based code.
block Rye block to compile/convert to EYR format
returns block containing the EYR-compiled version of the input block
to-eyr { 1 + 2 } |type?
; returns block
to-eyr { 5 * 3 } |length? |> 0
; returns true