Skip to content

constants

a constant is something whose value doesnt depend on anything and doesnt change unless the universe changes. under this definition, daamath has a few kinds of constants:

rational approximations

an irrational constant may be stored as a rational approximation:

  • each constant has 5 IEEE 754 basic formats: f32, f64, f128, d64, d128
  • each format has 2 residuals: the [nearest_even]-rounded value and the error of that rounded value
  • each residual has 3 integers: significand, radix, exponent

the advantages of this are:

  • the approximation is explicit, and not implicit in machine/language datatype
  • a box (lower, upper) or a ball (centre, radius) interval can be constructed
  • the constant can be easily hydrated into a float/fraction/string/int/interval/…

for convenience, an implementation may also store hydrated versions of the integer triple

the following irrational constants are approximated:

examples

# get τ as an f32 approximation in the float datatype

TAU = dm.hartl.binary16.nearest.float
# create e as a box interval of f64

E = dm.euler_bernoulli.binary64.nearest
residual = dm.euler_bernoulli.binary64.residual
E = (dm.pred(E), E) if residual < 0 else (E, dm.succ(E))
# create e as a ball interval of f32

E = (dm.euler_bernoulli.binary32.nearest.float, abs(dm.euler_bernoulli.binary32.residual.float))