Crate amplify_apfloat

source ·
Expand description

Port of LLVM’s APFloat software floating-point implementation from the following C++ sources (please update commit hash when backporting): https://github.com/llvm-mirror/llvm/tree/23efab2bbd424ed13495a420ad8641cb2c6c28f9

  • include/llvm/ADT/APFloat.h -> Float and FloatConvert traits
  • lib/Support/APFloat.cpp -> ieee and ppc modules
  • unittests/ADT/APFloatTest.cpp -> tests directory

The port contains no unsafe code, global state, or side-effects in general, and the only allocations are in the conversion to/from decimal strings.

Most of the API and the testcases are intact in some form or another, with some ergonomic changes, such as idiomatic short names, returning new values instead of mutating the receiver, and having separate method variants that take a non-default rounding mode (with the suffix _r). Comments have been preserved where possible, only slightly adapted.

Instead of keeping a pointer to a configuration struct and inspecting it dynamically on every operation, types (e.g. ieee::Double), traits (e.g. ieee::Semantics) and associated constants are employed for increased type safety and performance.

On-heap bigints are replaced everywhere (except in decimal conversion), with short arrays of type Limb = u128 elements (instead of u64), This allows fitting the largest supported significands in one integer (ieee::Quad and ppc::Fallback use slightly less than 128 bits). All of the functions in the ieee::sig module operate on slices.

§Note

This API is completely unstable and subject to change.

Modules§

Macros§

Structs§

Enums§

  • Category of internally-represented number.
  • IEEE-754R 4.3: Rounding-direction attributes.

Constants§

Traits§

  • A self-contained host- and target-independent arbitrary-precision floating-point software implementation.

Type Aliases§

  • A signed type to represent a floating point number’s unbiased exponent.