Language docs

Math library

Reference for the numeric, transcendental, number-theory, and formatting words exported by the top-level `math` module.

This page groups the public words from the files imported by ff/lib/math/math.ffp.

pred.ffp

Source: ff/lib/math/pred.ffp
Import: .import <math/pred>

WordStack effectDescription
negitive?n -- flagTests whether a number is negative.
positive?n -- flagTests whether a number is positive.
divisor?n d -- flagTests whether d divides n evenly.
even?n -- flagTests whether a number is even.
odd?n -- flagTests whether a number is odd.

arith.ffp

Source: ff/lib/math/arith.ffp
Import: .import <math/arith>

WordStack effectDescription
sgnx -- sgn(x)Returns the sign of a number.
absx -- |x|Returns the absolute value.
sqrx -- x²Squares a number.
mina b -- minReturns the smaller of two values.
maxa b -- maxReturns the larger of two values.
clamplo hi x -- x'Constrains a value to an inclusive range.
divrema b -- q rReturns quotient and remainder together.

num.ffp

Source: ff/lib/math/num.ffp
Import: .import <math/num>

WordStack effectDescription
!n -- n!Computes factorial.
nckn k -- C(n,k)Computes a binomial coefficient.
^^a b -- a↑↑bApplies Knuth up-arrow tetration.
^^^a b -- a↑↑↑bApplies the next higher Knuth hyper-operator.

atan.ffp

Source: ff/lib/math/atan.ffp
Import: .import <math/atan>

WordStack effectDescription
iatanx -- ⌊atan(x)⌋₀Integer arctangent with zero decimal places.
natann x -- ⌊10ⁿ*atan(x)⌋₀Fixed-point arctangent at decimal precision n.
qatanu v -- ⌊atan(u/v)⌋₀Integer arctangent of a rational input.
atan-invn x -- ⌊10ⁿ*atan(1/x)⌋₀Fixed-point arctangent of the reciprocal input.

atanh.ffp

Source: ff/lib/math/atanh.ffp
Import: .import <math/atanh>

WordStack effectDescription
iatanhx -- ⌊atanh(x)⌋₀Integer inverse hyperbolic tangent with zero decimal places.
natanhn x -- ⌊10ⁿ*atanh(x)⌋₀Fixed-point inverse hyperbolic tangent at decimal precision n.
qatanhu v -- ⌊atanh(u/v)⌋₀Integer inverse hyperbolic tangent of a rational input.
atanh-invn x -- ⌊10ⁿ*atanh(1/x)⌋₀Fixed-point inverse hyperbolic tangent of the reciprocal input.

sqrt.ffp

Source: ff/lib/math/sqrt.ffp
Import: .import <math/sqrt>

WordStack effectDescription
isqrtx -- ⌊sqrt(x)⌋Returns the integer square root of a non-negative input.
isqrtremx -- ⌊sqrt(x)⌋ x-⌊sqrt(x)⌋²Returns the integer square root and leftover remainder.
nsqrtn x -- ⌊10ⁿ*sqrt(x)⌋Returns a fixed-point square root with n decimal digits.

cbrt.ffp

Source: ff/lib/math/cbrt.ffp
Import: .import <math/cbrt>

WordStack effectDescription
icbrtx -- ⌊cbrt(x)⌋₀Returns the integer cube root, truncated toward zero.

gcd.ffp

Source: ff/lib/math/gcd.ffp
Import: .import <math/gcd>

WordStack effectDescription
gcda b -- gcdComputes the greatest common divisor.
lcma b -- lcmComputes the least common multiple.

ack.ffp

Source: ff/lib/math/ack.ffp
Import: .import <math/ack>

WordStack effectDescription
ackm n -- ack(m,n)Computes the Ackermann function, with fast paths for small m.

primes.ffp

Source: ff/lib/math/primes.ffp
Import: .import <math/primes>

WordStack effectDescription
maybe_prime?n -- flagProbabilistic Miller-Rabin primality screen.
prime?n -- flagExact primality test using the screen plus trial division.
next-primen -- pReturns the smallest prime greater than or equal to n.
th-primen -- pReturns the nth prime by repeated search.

log.ffp

Source: ff/lib/math/log.ffp
Import: .import <math/log>

WordStack effectDescription
nln2n -- ⌊10ⁿ*ln(2)⌋Computes a fixed-point approximation of ln(2).
ilbx -- ⌊log2(x)⌋Returns the integer base-2 logarithm.
ilogx -- ⌊log10(x)⌋Returns the integer base-10 logarithm.
ilnx -- ⌊ln(x)⌋Returns an integer natural logarithm approximation.

exp.ffp

Source: ff/lib/math/exp.ffp
Import: .import <math/exp>

WordStack effectDescription
iexpx -- ⌊eˣ⌋Computes a floored integer exponential using a fixed fast path.
nexpn x -- ⌊10ⁿ*eˣ⌋Computes a fixed-point exponential at decimal precision n.
ncoshn x -- ⌊cosh(x)*10ⁿ⌋Computes fixed-point hyperbolic cosine.
nsinhn x -- ⌊sinh(x)*10ⁿ⌋Computes fixed-point hyperbolic sine.
icoshx -- ⌊cosh(x)⌋Integer hyperbolic cosine wrapper around ncosh.
isinhx -- ⌊sinh(x)⌋Integer hyperbolic sine wrapper around nsinh.

pi.ffp

Source: ff/lib/math/pi.ffp
Import: .import <math/pi>

WordStack effectDescription
npin -- ⌊10ⁿ*π⌋Computes pi to n decimal places in fixed-point form.
taun -- ⌊10ⁿ*2*π⌋Computes tau to n decimal places in fixed-point form.
half_pin -- ⌊10ⁿ*π/2⌋Computes pi/2 to n decimal places in fixed-point form.

trig.ffp

Source: ff/lib/math/trig.ffp
Import: .import <math/trig>

This file is currently a placeholder and does not define public words yet.

prn.ffp

Source: ff/lib/math/prn.ffp
Import: .import <math/prn>

WordStack effectDescription
nputnn x -- {prints x with n fractional digits}Prints a fixed-point decimal with zero-padded fractional digits.
qputnp q -- {prints reduced p/q}Prints a reduced rational number as p/q.