Expand description
Maths in plain Rust. Its float functions take f16, f32 and f64, each within 4 units in the last place (ulps) of the correctly rounded result. The README lists the functions with wider bounds. The crate also has APL’s tolerant comparison, exact rationals, linear algebra, number theory and polynomials. Its Python functions evaluate eagerly and return Rustymath arrays or Python scalars.
Re-exports§
pub use slice::Arg;pub use slice::Binary;pub use slice::CHUNK;pub use slice::Flipped;pub use slice::KernelItem;pub use slice::Results;pub use slice::Ternary;pub use slice::Unary;pub use slice::Wrapped;pub use slice::pairs;pub use half;pub use num_complex;
Modules§
- agreement
- Broadcasting: pairing the axes of two layouts, and reading each argument’s items in the order of the result.
- array
- Borrowed array storage, layouts and positional reads.
- buffer
- Compact buffers: owned items of one element type, borrowed views of them, and the
DTypethat names each. Booleans take one byte each. Integers come in four widths, floats in three and complex numbers in two, named by the width of their parts.Sourcereads an item of one element type as another. - characters
- Character arithmetic uses ordinary numerical kernels on borrowed Unicode code points. Numbers order before characters.
- convert
- Conversions between floats and integers whose loops vectorize on every target. AVX2 and wasm have no vector instruction for converting between
f64and a 64-bit integer. AArch64 converts bytes to floats two lanes at a time. A loop that converts such types withasruns one item at a time on those targets.intandfloatconvert them through a float’s bits. They use the conversion instruction for types that every target converts in vector form, and for 64-bit integers where the target can.countwrites runs of whole numbers as floats. Where the target can’t convert 64-bit integers in vector form, it converts one item in 8.saturatedalso converts big integers andu64s, saturating them at an integer type’s range. - derivative
- Partial-derivative recipes shared by
Formularows. They useOpson the original arguments and result.Slopepresents a selected partial as another formula. A masked case keeps discarded intermediate values finite before selecting the slope. - distribution
- Probability distributions. Each has a density, a cumulative distribution, a quantile function and a sampler. The first three are also function objects,
Pdf,CdfandQuantile, which hold the distribution. Their slice forms choose the distribution’s formulas once, outside the loop, so the loops of the closed-form distributions vectorize. Their one-item forms run the slice forms on one item. An item of a slice form fails where its result is NaN and its argument isn’t, as for a quantile of p outside 0 to 1. A discrete distribution’s density is its mass at a whole x, and its quantile function and sampler give whole numbers. - domain
- What a kernel computes over: a call’s dtype and overflow policy (
Variant), and the values that an argument or a result can take (Range). Formulas (facts), recipes and kernels read both. - error
- Errors from rustymath’s functions on arrays. Each error has a kind, and a message that says what went wrong.
- events
- Diagnostic capture shared by mathematical kernels and their callers. Rows own diagnostic data and never retain runtime values. Capture includes worker threads and permits nesting on one thread.
- exact
- Exact numbers: rationals of any integer type, such as
BigRational, which isRatio<BigInt>. These functions give exact results, where the float functions round.linalg::exactsolves matrices of them,polynomialevaluates polynomials with them, andnumber_theoryworks on whole numbers. - facts
- Shared function definitions for numerical frontends. Each
Formularow owns its kind and character policies, numerical body, validity and repair predicates, ranges, identities, partial derivatives and exact cases.rustymath::operation::Kernelerases the arity for execution.facts!lists typed product pairs and Python names. - fused
- rustymath’s functions with
mlafused, whatever the target’sFUSED. Code compiled with FMA enabled for itself, such as an AVX2 version of a loop chosen when the program runs, calls these on a target whose baseline lacks FMA. - gather
- Copying the items of a slice into a buffer by position: repeating each, keeping those a mask selects, taking them at indices, walking an n-dimensional pattern of offsets over them, and writing them at offsets.
positionswrites the positions that a mask selects. Each applies a conversion to each item it writes, so a caller can widen items as it gathers them. Most are generic and#[inline], so they compile in the caller, with the caller’s types and conversion.walkandscatter_walkinstead compile their walk once for each item type, and run any other conversion as a separate contiguous pass. Their fixed-width loops moveUnits, which compile once for each size of item. Booleans and integers convert intof64through fixed-width loops of their own as they write (Item::cells_from). - hashing
- The hash maps and sets rustymath uses.
Hashingis foldhash’s fast hasher with its fixed seed (FixedState), withhash_onemarked#[inline(always)]. With one seed in every process, maps hash and iterate alike between runs, and instruction counts repeat. hashbrown 0.17 hashes every key throughBuildHasher::hash_one, and core’s default body for it has no inline hint, so incremental builds can call it out of line on every lookup. - integer
- Functions of
i64s: greatest common divisor, least common multiple, binomial coefficients, powers, square roots and residues. Each givesNonewhere its result isn’t ani64. Their function objects are the ones that floats and complex numbers use:Gcd,LcmandResiduefromtolerant, whose integer forms ignore the tolerance they hold, andBinomandPow. A slice form appends results to a vector and reports whether every item fitted.Divisordivides many integers by one, with multiplications in place of division instructions. Where every item has the same divisor,Residue’s slice form divides throughFloatDivisor, which multiplies by the divisor’s reciprocal inf64and vectorizes, for divisors and dividends below 2⁵¹ in magnitude. At types of 16 bits or fewer it multiplies 32-bit integers instead, and it takesDivisorfor 64-bit dividends of 2⁵¹ or more. - interrupt
- The process’s interrupt check. Long computations call
checkbetween steps, about everyBETWEEN_CHECKSitems, and stop with its error. A frontend installs its check withinstall: basedpl’s stops the running evaluation at an interrupt or a passed deadline, and rustymath’s Python bindings’ raise the exception of a pending signal. Until a frontend installs one,checkpasses. - layout
- Array shapes, axis keys and names, and their limits.
- linalg
- Inner products of row-major matrices. The inner product
f.gof anm×kmatrixaand ak×nmatrixbis them×nmatrix whose item at rowiand columnjfoldsfoverg(a[i][p], b[p][j])for eachp.+.×is the matrix product. The specialized pairs have associativef, and their loops combine its steps in whatever order suits them. A float result can therefore differ in its last bits from a fold taken in order.inner_withruns other native pairs through bounded term blocks and a caller’s right fold, which preserves the association of non-associative functions. - memory
- The process’s memory guard. A binary that registers
Guardas its global allocator counts the bytes it holds in large allocations, of at leastLARGEbytes each. The process’s limit is half of physical memory, unlessset_limitsets another. The guard refuses an allocation that would take its count past the limit. It writes one line to stderr naming the limit. Rust then aborts the process, before the machine runs out of memory. Before a function makes an array,generated_lenasksadmit, which gives a Limit error where the array would pass the limit.peak_heldgives the most bytes that a call held at once, which the speed tests count in a case’s footprint. On Linux, the guard also asks the kernel for transparent huge pages for each allocation of at least 4 MiB. The kernel gives them where/sys/kernel/mm/transparent_hugepage/enabledismadviseoralways. Without huge pages, each 4 KB page of a new block pays a page fault on its first write. On some hosts those faults take several times as long as the elementwise work that fills the block. basedpl’sbpl, Python extension, browser build, reference test and speed test register the guard, as do rustymath’s Python extension and speed test.set_checksturns on test-only checks: of the size that each free of a large block passes, and, in basedpl’s reference and speed tests, ofheldafter each case. A binary that doesn’t register it counts nothing. There,admitrefuses only an array that alone would pass the limit. - number_
theory - Number theory on unsigned integers: primality, factorisation, next and previous primes, Euler’s totient, and the enumeration and counting of primes.
- optimize
- Minimizing a function of several variables, and solving equations, nonlinear or linear.
- parallel
- Splitting work across threads. [
pieces] cuts a call’s items into pieces of the sizes its caller gives, andrangesinto as many pieces as the time of its first unit justifies. The pieces run on a Rayon pool with Rayon’s default number of threads:RAYON_NUM_THREADSwhere it’s set, and otherwise one for each core.set_threadschanges that number for the whole process. A call made on one of a pool’s threads, such as a function that another call’s piece runs, doesn’t split again. In the browser build, which has no threads, every call runs its pieces in turn on the calling thread. - polynomial
- Polynomials of one variable. A polynomial is the slice of its coefficients in ascending order, so
cstands forc[0] + c[1]x + c[2]x² + …. Trailing zero coefficients don’t count towards the degree.evaluatetherefore never multiplies an infinite x by one of them.from_roots,derivative,valueandfactoredcheck for an interrupt between roots, or between groups ofBETWEEN_CHECKScoefficients or roots, and return its error as soon as they get one, aslinalg::exact’s functions do. A call too short for a second group makes no check, so evaluating a short polynomial at each of many points costs no checks. - random
- Random sampling from counter streams. Each call reads one ChaCha8 stream selected by a key and stream number. Item
kreads its firstwwords at positionk*w, and rejection sampling uses that item’s separate region. Floats, rolls and distribution samplers share this word addressing. - recipe
- Formulas that rustymath’s kernels compute and basedpl’s JIT compiles, each written once over the operations it uses (
Ops): tolerant closeness, comparison (each item, or through the range of floats equal to one number), floor, ceiling and the residue; Mathish division, sign, the reciprocal andπ’s two forms; and the powers thatExponentroutes off the general route, with the square root they take for halves.Floatsruns a recipe on floats, as the kernels do. A compiler’sOpsrecords the same operations as steps, so both routes round alike, step for step. - reduce
- Reductions and scans over a contiguous slice: sums, products, maximums and minimums, and their running versions. Each compiles inside rustymath once for each item type. A float sum or product may combine the items in any order, which lets its loop vectorize, so its last bits can differ from a sum taken item by item. Beside NaN, a float maximum or minimum gives NaN or the greatest or least of the items that aren’t NaN, and never any other number. Which of the two it gives can depend on the target and the loop. An empty slice gives -∞ or ∞.
f16items compute inf32. Their sum or product is anf32total. An integer sum or product computes ati64, or atu64foru64items. Where it doesn’t fit, it wraps, and reports that it doesn’t fit, as the running versions do. - search
- Search and sort over slices of keys. A key is an item read as a whole number (
Key), or an unsigned word whose order is the order you want (RadixKey).Float::order_keygives each float such a word, as wide as the float. Positions take 32 bits inside these functions, so a slice holds at mostu32::MAXitems.tolerantbuilds its searches over floats on these functions. - signal
- Correlations and convolutions, which slide a kernel along an array’s leading axes, and overlap-add, which adds windows back where they were read.
- slice
- Slice forms of rustymath’s functions. Each function object, such as [
Pow], has a scalar formoneand a slice formmany. Both run code that rustymath compiles once for each item type, inside its own crate. A caller’s build settings can’t change that code, and rustymath’s speed test times what callers run. An edit to a function’s body rebuilds only rustymath. - stats
- Statistics through the shared reductions and matrix products. Means and norms use the ordinary parallel folds. Variance makes two passes, without an array-sized buffer of deviations. No compensated sums or reproducibility rules are imposed.
- structure
- Plans for structural operations: take and drop, rotate and reverse, windows, transpose and catenate. A plan gives the result’s layout, and
Stepsthat read the result’s items from the argument’s items in order.gather::walkcopies a compact array by a plan, and basedpl copies its other arrays by the same plan. Each plan checks its arguments. - tolerant
- Tolerant comparison of floats:
xequalsywithin a relative tolerancetwhen|x-y|is less thanttimes the larger of|x|and|y|. APL’s definition says at most, which differs only where|x-y|lands exactly on that bound. Dyalog APL callstthe comparison tolerance,⎕CT, and its default is 1e-14. A tolerance has no effect when either number is zero. - unfused
- rustymath’s functions with
mlaunfused, whatever the target’sFUSED.
Macros§
- function_
doc - Each function’s doc by its name, as
function_doc!(ln), with its lines joined by newlines. - with_
complex_ width - with_
complexes - with_
dtype - Runs the body with its type name standing for the element type of the dtype.
- with_
float_ width - with_
floats - with_
inexact - Runs
$bodywith$tstanding for the element type of$dtype, a computing dtype thatDType::inexactgives: a 32- or 64-bit float, or a complex number. Any other dtype panics. - with_
int_ pair - Runs
$bodywith$xand$ybound to the integers of$aand$bat one width: their own when they share it, and otherwise both widened to 64 bits. - with_
ints - with_
reduce - Runs
$bodywith the type$tstanding for the reduction that$r(aReduce) names. - with_
tolerance - Runs
$bodywith$tbound toExactlywhen theTolerance$toleranceis 0, and to the tolerance otherwise. Each binding has its own compiled copy of$body. The choice happens once, outside any loop in$body. - with_
width
Structs§
- Abs
- |x|, or the magnitude |z| of a complex z, which is real, as a function object.
- Acos
acosas a function object.- Acosh
acoshas a function object.- Add
- x + y.
- Angle
- The angle from the positive real axis, from -π to π, as a function object. It is real for complex items too. A real x has angle 0, or π where its sign bit is set, as the angle of x + 0i is.
- Asin
asinas a function object.- Asinh
asinhas a function object.- Atan
atanas a function object.- Atan2
atan2as a function object.- Atanh
atanhas a function object.- Beta
betaas a function object.- Betainc
betaincas a function object.- Betainc
At - The regularized incomplete beta CDF with shape parameters a and b fixed.
- Betaincinv
betaincinvas a function object.- Binom
binomas a function object.- BinomDk
binom_dkas a function object.- BinomDn
binom_dnas a function object.- BitAnd
- Bitwise AND, or logical AND of Booleans.
- BitOr
- Bitwise OR, or logical OR of Booleans.
- Bitwise
bitwisewith the truth table it holds, as a function object. One argument is the second, with 0 as the first. Booleans and the signed types hold every result, because each leading sign bit takes the same entry of the table. An unsigned byte computes ati64, where its leading zeros can become ones, and fails where the result doesn’t fit.- Cbrt
cbrtas a function object.- Choose
xwheremis nonzero andywhere it’s zero, item by item: a select, with the maskmas lanes of the items’ type.- Cis
- e^(iz), the cis of z, as a function object, which is cos z + i sin z for a real z. It takes real and complex items.
- Clip
- Clipping x between lower and upper bounds in one pass:
minimum(upper, maximum(lower, x)). A lower bound above the upper one gives the upper. A NaN argument gives NaN, x or a bound, depending on the target. - Conj
- The complex conjugate, with a real number unchanged.
- Cos
- Cosh
coshas a function object.- Digamma
digammaas a function object.- Divide
- x ÷ y, at every float and complex type. Complex numbers divide by
divide. - Erf
erfas a function object.- Erfc
erfcas a function object, with the slice formmany, which runserfc_blockson a slice.- Erfcinv
erfcinvas a function object, with the slice formmany, which runsregionson a slice of f64s.- Erfinv
erfinvas a function object, with the slice formmany, which runsregionson a slice of f64s.- Exp
expas a function object.- Expm1
expm1as a function object.- Factorial
factorialas a function object.- Gamma
gammaas a function object.- Gammainc
gammaincas a function object.- Gammaincc
gammainccas a function object.- Gammaincinv
gammaincinvas a function object.- Hypot
hypotas a function object.- Imag
- The imaginary part of a number, zero for a real number.
- Isfinite
- Whether every part of a number is finite.
- Isinf
- Whether a number has an infinite part.
- Isnan
- Whether a number has a NaN part.
- LambertW
lambertwas a function object.- Left
Shift - Left shift, discarding high bits. A negative count shifts right, and a count at least the item width saturates to 0.
- Lgamma
lgammaas a function object.- Ln
lnas a function object.- Log2
log2as a function object.- Log1p
log1pas a function object.- Log10
log10as a function object.- Logb
logbas a function object.- Mathish
Divide - Division with zero divided by zero defined as zero.
- Mathish
Logb Logbwith log base one of one defined as zero.- Multiply
- x × y.
- Nand
- See
Not. - Negate
- -x. A float or complex result never fails. An integer result fails where it doesn’t fit its type, as the negation of a signed type’s least value or of an unsigned byte other than 0 doesn’t, and holds the result wrapped to the type.
- Nor
- See
Not. - Not
- Logical NOT, NAND and NOR, of Booleans, and of integers that are 0 or 1, which give Booleans. Any other integer fails.
- PiTimes
- π × x, or π × (x ÷ y) of two arguments, at every float and complex type.
- Polygamma
polygammaas a function object.- Pow
- Real
- The real part of a number, with a real number unchanged.
- Real
Acos - The real part of acos x, or of its principal value at a complex z, as a function object: acos x for x from -1 to 1, and acos of the nearer of -1 and 1 beyond. The real part of
2○⁻¹. - Real
Acosh - The real part of acosh x, or of its principal value at a complex z, as a function object: acosh |x| for |x| at least 1, and 0 between -1 and 1. The real part of
6○⁻¹. - Real
Asin - The real part of asin x, or of its principal value at a complex z, as a function object: asin x for x from -1 to 1, and asin of the nearer of -1 and 1 beyond. The real part of
1○⁻¹. - Real
Atanh - The real part of atanh x, or of its principal value at a complex z, as a function object: atanh x for x between -1 and 1, and atanh (1 ÷ x) beyond, which is ½ ln |(1 + x) ÷ (1 - x)|. The real part of
7○⁻¹. - RealLn
- ln|x|, the real part of ln x, as a function object.
- RealPow
- Real
Sqrt - The real part of √x, or of the principal √z of a complex z, as a function object: √x for a positive x, and 0 at or below 0. Its formula is
recipe::real_sqrt. - Real
Sqrt1mx2 - The real part of √(1 - x²), or of its principal value at a complex z, as a function object: √(1 - x²) for x from -1 to 1, and 0 beyond. The real part of
0○and0○⁻¹. - Real
Sqrtm1mx2 - The real part of √(-1 - x²), or of its principal value at a complex z, negated where the flag is set, as a function object: 0 for every real x, whose
8○is imaginary. The real part of8○, and of8○⁻¹with the flag. - Real
Sqrtx2m1 - The real part of √(x - 1) √(x + 1), or of its principal value at a complex z, as a function object: x’s sign times √(x² - 1) for |x| at least 1, and 0 between -1 and 1. The real part of
4○⁻¹, on APL’s branch. - Reciprocal
- 1 ÷ x. A float or complex result never fails. An integer’s reciprocal floors, as integer
FloorDivideof 1 does: 1 gives 1, 2 or more give 0, -1 or less give -1, and 0 gives the type’s greatest value. - Right
Shift - Right shift, retaining the sign bit for signed integers. A negative count shifts left, and a count at least the item width saturates to the sign.
- Rint
- Rounding to the nearest whole number, with ties to even.
- Root
rootas a function object, with a scalar form and a slice form that work asPow’s do. A constant degree of 2 or 3 takessqrtorcbrt.- Round
- Decimal rounding to nearest, ties to even. Constructing it precomputes the scale; extreme negative/positive precisions give zero/leave inputs unchanged.
- Scale
- Multiplication by a fixed real scale, computing f16 in f32 before rounding once.
- Sign
- The sign of x as -1 or 1, or z/|z| for a complex z, as a function object. A zero gives itself, and NaN gives NaN.
- Sin
- Sinh
sinhas a function object.- Sqrt
- √x, or the principal √z of a complex z, whose real part is never negative, as a function object. A negative x gives NaN.
- Sqrt1mx2
sqrt1mx2as a function object.- Sqrt1px2
sqrt1px2as a function object.- Sqrtm1mx2
- Sqrtx2m1
sqrtx2m1as a function object.- Subtract
- x - y.
- Tan
- Tanh
tanhas a function object.- Trunc
- Rounding toward zero, with whole numbers unchanged.
Enums§
- Exponent
- How
Powraises to an exponent y. Its slice form reads it once for a constant y, and its scalar form for each item. The JIT’s lowering of a constant power reads it too.
Constants§
- BETWEEN_
CHECKS - How many items a function handles between checks for an interrupt (
interrupt::check), which keeps the check out of the loop over items. - FUSED
- Whether
mlafuses its multiply and add into one operation with one rounding. It does where the target has a fused multiply-add instruction, as on AArch64 and on x86-64 with FMA. Elsewhere, as in wasm and on baseline x86-64,mul_addcalls a softwarefma, which is slow and stops the loop around it vectorizing. Theremlamultiplies and adds with two roundings.
Traits§
- Float
- A float type that rustymath’s functions take:
half::f16,f32orf64. - Native
- A float type that rustymath’s algorithms run in:
f32orf64.
Functions§
- acos
- acos x. A real x gives a result from 0 to π and NaN beyond a magnitude of 1.
- acosh
- acosh x. A real x below 1 gives NaN.
- asin
- asin x. A real x gives a result from -π/2 to π/2 and NaN beyond a magnitude of 1.
- asinh
- asinh x.
- atan
- atan x. A real x gives a result from -π/2 to π/2.
- atan2
- The angle of the point (x, y) from the positive x axis, from -π to π, with y first as in C’s
atan2. Zeros and infinities give C99’s angles: atan2(±0, -0) is ±π, and atan2(±∞, ±∞) is an odd multiple of ±π/4. - atanh
- atanh x. ±1 gives ±∞, and a real x of magnitude beyond 1 gives NaN.
- beta
- B(a, b) = Γ(a) Γ(b)/Γ(a + b), the beta function. A pole of Γ(a) or Γ(b) gives NaN, and a pole of Γ(a + b) alone gives 0.
- betainc
- The regularized incomplete beta function I_x(a, b): the integral of t^(a-1) (1-t)^(b-1) from 0 to x, divided by B(a, b). a and b must be positive and x from 0 to 1, or the result is NaN.
- betaincinv
- The x with I_x(a, b) = p, for p from 0 to 1.
- binom
- C(n, k), the binomial coefficient. Whole n and k from 0 multiply out exactly while the result times |n| + k is a whole number the type holds, and a negative whole n gives (-1)^k C(k - n - 1, k). Other n with a whole k from 0 to 64 multiply out n(n - 1)…(n - k + 1)/k!, within 2k ulps. Other real arguments take Γ(n + 1)/(Γ(k + 1) Γ(n - k + 1)) in double words, within 4 ulps in tests against mpmath, for large n and negative arguments too.
- binom_
dk - ∂C(n, k)/∂k, the binomial coefficient’s slope in k: C(n, k)(ψ(n - k + 1) - ψ(k + 1)). At a whole n from 0 below a whole k, it is the negative of
binom_dn. Other poles of ψ, as at a negative whole k, give NaN. For a whole k from 0 to 64, its error is within 2k ulps of C(n, k) times ψ(n - k + 1) - ψ(k + 1), plus the error of that difference, so near n = 2k, where the two ψ cancel, its relative error has no bound. - binom_
dn - ∂C(n, k)/∂n, the binomial coefficient’s slope in n. For a whole k from 0 to 64 it is the slope of the polynomial n(n - 1)…(n - k + 1)/k! by the product rule, within 2k ulps. Other arguments take C(n, k)(ψ(n + 1) - ψ(n - k + 1)), with the ψ difference in double words where both arguments are from 10 up, with the polynomial’s slope where a whole n below a whole k puts those ψ at a pole. Other poles of ψ give NaN.
- bitwise
- Applies the Boolean function whose truth table is
table, indexed by2*x+y, to every bit ofxandy, the leading sign bits included. It computes the table’s algebraic normal form,a0 ^ (a1 & x) ^ (a2 & y) ^ (a3 & x & y), with each coefficient spread to every bit, so every table runs the same code. Amatchon the table would put 16 paths into each loop that inlines it. It takes any integer type, exact ones included. - cbrt
- The cube root of x.
- cos
- cos x.
cos(±0)is 1, andcos(±∞)andcos(NaN)are NaN. Beyond the magnitude thatsingives, x takes the same exact reduction. - cosh
- cosh x. It stays finite up to where cosh itself overflows, beyond the point where e^x does.
- digamma
- ψ(x), the digamma function: the derivative of ln Γ(x), Γ′(x)/Γ(x). ψ(+0) is -∞, ψ(-0) is ∞, a negative whole x and -∞ give NaN, and ψ(∞) is ∞. Near its zeros its error is within 4 ulps of 1, not of the result, and below -20 within 4 ulps of ln(1 - x).
- divide
- x / y for complex numbers, inline in the caller’s loop, by num_complex’s formula. Two real arguments divide as reals, so a real zero divisor gives ±∞ or NaN with an imaginary part of 0. Any other zero divisor gives NaN parts. |y|² overflows beyond about 1e154 at f64 and 1e19 at f32, and underflows below their inverses, where the quotient loses its digits. The decompositions’
Scalar::quotientuses Smith’s algorithm, which avoids that at the cost of speed in a vector loop. - erf
- The error function, 2/√π times the integral of e^-t² from 0 to x.
- erfc
- 1 - erf(x), without the loss of digits for large x that
1 - erf(x)has. - erfcinv
- The x with erfc(x) = q. 0 gives ∞, 2 gives -∞, and q outside 0 to 2 gives NaN.
- erfinv
- The x with erf(x) = p. ±1 gives ±∞, and a magnitude beyond 1 gives NaN.
- exp
- e^x.
exp(∞)is ∞,exp(-∞)is 0, andexp(NaN)is NaN. - expm1
- e^x - 1, without the loss of digits near 0 that
exp(x) - 1has. - factorial
- Γ(x + 1), which is x! for a whole x from 0.
- gamma
- Γ(x). Γ(±0) is ±∞, a negative whole x and -∞ give NaN, and Γ(∞) is ∞.
- gammainc
- The regularized lower incomplete gamma function P(a, x): the integral of t^(a-1) e^-t from 0 to x, divided by Γ(a). a must be positive and x nonnegative, or the result is NaN.
- gammaincc
- The regularized upper incomplete gamma function Q(a, x) = 1 - P(a, x), without the loss of digits that
1 - gammainc(a, x)has where Q is small. - gammaincinv
- The x with P(a, x) = p, for p from 0 to 1.
- hypot
- √(x² + y²), with no overflow or underflow in between. An infinite argument gives ∞, even beside NaN.
- lambertw
- W0(x), the principal branch of the Lambert W function: the w of at least -1 with w e^w = x. A real x below -1/e gives NaN, except within half an ulp of -1/e, where W0 is -1.
- lgamma
- ln |Γ(x)|. It is ∞ at 0, at the negative whole numbers and at ±∞. Near its zeros at 1 and 2 its error is within 4 ulps of 2, not of the result.
- ln
- The natural logarithm of x.
ln(0)is -∞,ln(∞)is ∞, and a negative real x or NaN gives NaN. - log2
- The logarithm of x to base 2. It is k exactly at 2^k.
- log1p
- ln(1 + x), without the loss of digits near 0 that
ln(1 + x)has.log1p(-1)is -∞. - log10
- The logarithm of x to base 10. It is k exactly at 10^k, and at the float nearest 10^k where 10^k isn’t a float.
- logb
- The logarithm of x to base b, ln x / ln b. Base 2 and base 10 take
log2andlog10, which are exact at powers of their base. - polygamma
- ψ⁽ⁿ⁾(x), the polygamma function: the nth derivative of ψ, for a whole n from 0 to 170. For n from 1, x from 0 down gives NaN, as do a fractional or negative n and an n above 170.
- pow
- x^y. Special values follow IEEE 754’s
pow: x^0 and 1^y are 1, even for NaN, and a negative x has a power only for a whole y. - root
- The real nth root of y, computed without rounding 1/n first. A negative y has one only for an odd whole n. n = 0, an infinite n and NaN give NaN.
- sin
- sin x.
sin(±0)is ±0, andsin(±∞)andsin(NaN)are NaN. Beyond a magnitude of 2^23 at f64 or 2^20 at f32, x takes a slower, exact reduction. - sinh
- sinh x. It stays finite up to where sinh itself overflows, beyond the point where e^x does.
- sqrt1mx2
- √(1 - x²), without the digits that squaring x first loses near |x| = 1. A real x of magnitude beyond 1 gives NaN.
- sqrt1px2
- √(1 + x²), with no overflow where x² would overflow.
- sqrtx2m1
- √(x - 1) √(x + 1): √(x² - 1) with the sign of a real x, without the digits that squaring x first loses near |x| = 1. A real x of magnitude below 1 gives NaN.
- tan
- tan x.
tan(±0)is ±0, andtan(±∞)andtan(NaN)are NaN. Beyond the magnitude thatsingives, x takes the same exact reduction. - tanh
- tanh x.