JFLib

diagram_core/src/formula/math.rs#

Source: lib/diagram_core/src/formula/math.rs

math -- the float functions formulas need, without std and without libm

Accurate to a few units in the last place over the ranges drawings use (angles of a few
turns, lengths up to kilometres): range reduction, then series on a small interval.  The
engine compares results with the values Visio stored, so plain truncated series that lose
digits are not good enough; these keep about 15 significant digits.
  • fn floor(x: f64) -> f64 largest integer not above x

  • fn ceil(x: f64) -> f64 smallest integer not below x

  • fn trunc(x: f64) -> f64 x without its fraction

  • fn round(x: f64) -> f64 x rounded half away from zero

  • fn sqrt(x: f64) -> f64 the square root (NaN below 0)

  • fn pow2(e: i64) -> f64 2^e for integer e (exact while the result is a normal number)

  • fn sincos(x: f64) -> (f64, f64) sine and cosine

  • fn sin(x: f64) -> f64 sine

  • fn cos(x: f64) -> f64 cosine

  • fn tan(x: f64) -> f64 tangent

  • fn atan(x: f64) -> f64 arc tangent

  • fn atan2(y: f64, x: f64) -> f64 the angle of (x, y): atan2(y, x) in -pi ..= pi

  • fn asin(x: f64) -> f64 arc sine (NaN outside -1..1)

  • fn acos(x: f64) -> f64 arc cosine (NaN outside -1..1)

  • fn exp(x: f64) -> f64 e^x

  • fn ln(x: f64) -> f64 the natural logarithm (NaN below 0, -inf at 0)

  • fn log10(x: f64) -> f64 the logarithm to base 10

  • fn pow(x: f64, y: f64) -> f64 x to the power y (integer y by repeated squaring, exactly as Visio's ^2 needs)

  • fn sinh(x: f64) -> f64 hyperbolic sine, cosine, tangent

  • fn cosh(x: f64) -> f64 hyperbolic cosine

  • fn tanh(x: f64) -> f64 hyperbolic tangent

  • fn modulus(x: f64, y: f64) -> f64 x modulo y with the sign of y (Visio's MODULUS); NaN for y = 0

Source: docs/API.md in the JFLib repository.