Introduces a type constructor math.F for various IEEE-754 floating-point formats and a set of operations to calculate with instances of these types. All operations with the exception of math.conv expect a Nat as their very first argument. Via this mode you can fine-tune how strictly floating-point transformations must obey IEEE semantics. It comes before the implicit pe so that currying it - math.arith.add 0 - still yields a value polymorphic in pe.
A floating-point type with p bits of precision and e exponent bits. The sign bit is neither included in p nor in e. Thus, the total number of bits occupied by a value of this type is p + e + 1. Current constant folding only supports IEEE binary16/binary32/binary64 literals, subject to host f16 support.
Fine-tunes how strictly a floating-point operation must obey IEEE semantics - see mim::plug::math::Mode.
Arithmetic operations.
Minimum and maximum:
| Subtag | Alias | I | M |
|---|---|---|---|
| im | fmin | o | o |
| iM | fmax | o | x |
| Im | ieee754min | x | o |
| IM | ieee754max | x | x |
Trigonometric and hypberbolic functions.
| Subtag | Alias | A | H | FF | Meaning | Semantics |
|---|---|---|---|---|---|---|
| ahff | sin | o | o | oo | sine | \(\sin x\) |
| ahfF | cos | o | o | xo | cosine | \(\cos x\) |
| ahFf | tan | o | o | ox | tangent | \(\tan x\) |
| ahFF | o | o | xx | unused | - | |
| aHff | sinh, h | o | x | oo | hyperbolic sine | \(\sinh x\) |
| aHfF | cosh | o | x | xo | hyperbolic cosine | \(\cosh x\) |
| aHFf | tanh | o | x | ox | hyperbolic tangent | \(\tanh x\) |
| aHFF | o | x | xx | unused | - | |
| Ahff | asin , a | x | o | oo | arcus sine | \(\textrm{asin}\,x\) |
| AhfF | acos | x | o | xo | arcus cosine | \(\textrm{acos}\,x\) |
| AhFf | atan | x | o | ox | arcus tangent | \(\textrm{atan}\,x\) |
| AhFF | x | o | xx | unused | - | |
| AHff | asinh | x | x | oo | area hyperbolic sine | \(\textrm{asinh}\,x\) |
| AHfF | acosh | x | x | xo | area hyperbolic cosine | \(\textrm{acosh}\,x\) |
| AHFf | atanh | x | x | ox | area hyperbolic tangent | \(\textrm{atanh}\,x\) |
| AHFF | x | x | xx | unused | - |
Power function: \(x^y\)
| Name | Meaning | Semantics |
|---|---|---|
| math.rt.sq | square root | \(\sqrt{x}\) |
| math.rt.cb | cube root | \(\sqrt[3]{x}\) |
Exponential function and logarithm:
| Subtag | Alias | L | BB | Meaning | Semantics |
|---|---|---|---|---|---|
| lbb | exp | o | oo | natural exponential | \(e^x\) |
| lbB | exp2, bin | o | ox | exponential with base 2 | \(2^x\) |
| lBb | exp10, dec | o | xo | exponential with base 10 | \(10^x\) |
| lBB | unused | o | xx | - | unused |
| Lbb | log | x | oo | natural logarithm | \(\ln x\) |
| LbB | log2 | x | ox | logarithm with base 2 | \(\log_2 x\) |
| LBb | log10 | x | xo | logarithm with base 10 | \(\log_{10} x\) |
| LBB | unused | x | xx | - | unused |
Error and complementary error function.
| Name | Meaning | Semantics |
|---|---|---|
| math.er.f | error function | \(\frac{2}{\sqrt\pi}\int_0^x e^{-t^2}\,dt\) |
| math.er.fc | complementary error function | \(\frac{2}{\sqrt\pi}\int_x^\infty e^{-t^2}\,dt = 1 - \textrm{erf}(x)\) |
Gamma function and its natural logarithm.
| Name | Meaning | Semantics |
|---|---|---|
| math.gamma.t | gamma function | \(\Gamma(x) = \int_0^\infty t^{x-1} e^{-t}\,dt\) |
| math.gamma.l | natural logarithm of gamma function | \(\ln \mid \int_0^\infty t^{x-1} e^{-t}\,dt \mid\) |
Absolute value of a floating-point number.
Common rounding operations for floating-point numbers:
| Name | Meaning | Semantics |
|---|---|---|
| math.round.f | round down | \(\lfloor x \rfloor \) |
| math.round.c | round up | \(\lceil x \rceil \) |
| math.round.r | round to nearest integer | \(round (x)\) |
| math.round.t | round towards zero | \(trunc (x)\) |
Floating-point comparison is composed of 4 disjoint relations:
| Subtag | Alias | U | G | L | E | Meaning |
|---|---|---|---|---|---|---|
| ugle | f | o | o | o | o | always false |
| uglE | e | o | o | o | x | ordered and equal |
| ugLe | l | o | o | x | o | ordered and less |
| ugLE | le | o | o | x | x | ordered and less or equal |
| uGle | g | o | x | o | o | ordered and greater |
| uGlE | ge | o | x | o | x | ordered and greater or equal |
| uGLe | ne | o | x | x | o | ordered and not equal |
| uGLE | o | o | x | x | x | ordered (no NaNs) |
| Ugle | u | x | o | o | o | unordered (either is NaN) |
| UglE | ue | x | o | o | x | unordered or equal |
| UgLe | ul | x | o | x | o | unordered or less |
| UgLE | ule | x | o | x | x | unordered or less or equal |
| UGle | ug | x | x | o | o | unordered or greater |
| UGlE | uge | x | x | o | x | unordered or greater or equal |
| UGLe | une | x | x | x | o | unordered or not equal |
| UGLE | t | x | x | x | x | always true |
Returns tt if the float is finite and ff if not (i.e. if it is ±∞ or NaN).
Conversion between floating-point and index types - both signed and unsigned - of different sizes.
Standard logistic function of a floating-point number ( \(\textrm{slf}(x) = \frac{1}{1+e^{-x}}\))
Reciprocal of the square root ( \(\textrm{rrt}(x) = \frac{1}{\sqrt{x}}\))
Bindings for the infix operators, which are sugar for an application of the escaped name. use the module whose math.mode matches the accuracy you are willing to trade:
| Module | Mode |
|---|---|
| math.ops.none | math.mode.none |
| math.ops.finite | math.mode.finite |
| math.ops.unsafe | math.mode.unsafe |
| math.ops.fast | math.mode.fast |