Crate xenon

source ·
Expand description

Fixed-point math, for any static or dynamic precision in any base.

Differences from floating-point:

  • exact results, except where explicitly rounded
  • supports rounding in any base, such as decimal
  • simpler interface (no NaN, infinities)
  • better performance
  • more compact storage for some value ranges
  • unnormalized, so sigfigs of result can be determined by sigfigs of inputs

Differences from bignums:

  • if you know the “shape” of your inputs/calculations, the statically typed fixed-points can be more efficient
  • XeN is optimized for values that fit in a relatively small range

Dynamic precision? Isn’t that floating point?

Technically yes, but the Xe API is much simpler than typical floating point; it’s designed for applications like working with a collection of values that are known to be fixed-precision decimal of the same type, but the number of decimal places won’t be known until runtime.



Type Definitions