5 releases

0.1.4 Jul 3, 2023
0.1.3 Apr 18, 2023
0.1.2 Feb 18, 2023
0.1.1 Feb 7, 2023
0.1.0 Feb 7, 2023

#16 in No standard library

Download history 9968/week @ 2024-01-01 11732/week @ 2024-01-08 12856/week @ 2024-01-15 12801/week @ 2024-01-22 11861/week @ 2024-01-29 11536/week @ 2024-02-05 13182/week @ 2024-02-12 15634/week @ 2024-02-19 15444/week @ 2024-02-26 15575/week @ 2024-03-04 13166/week @ 2024-03-11 14497/week @ 2024-03-18 13474/week @ 2024-03-25 15178/week @ 2024-04-01 13124/week @ 2024-04-08 13536/week @ 2024-04-15

56,905 downloads per month
Used in 409 crates (4 directly)

MIT/Apache

165KB
3K SLoC

Rust float-point in constant context

Floating-point code is from compiler_builtins = "0.1.94" and libm = "0.2.6", and has been rewritten for use in a constant context.

Fuzzing of all operations is performed against the relevant reference code to ensure correctness of the port, but please open an issue if there is any inconsistent behavior.

Exported Soft Float Types:

  • SoftF32
  • SoftF64

Features:

  • no_std - Enabled by default
  • const_trait_impl - For const operator implementations
  • const_mut_refs - For const operator with assignment implementations

On stable:

const fn const_f32_add(a: f32, b: f32) -> f32 {
    SoftF32(a).add(SoftF32(b)).to_f32()
}

On nightly with const_trait_impl usage:

const fn const_f32_add(a: f32, b: f32) -> f32 {
    (SoftF32(a) + SoftF32(b)).to_f32()
}

On nightly with const_mut_refs usage:

const fn const_f32_add(a: f32, b: f32) -> f32 {
    let mut x = SoftF32(a);
    x += SoftF32(b);
    x.to_f32()
}

Implemented const Functions:

  • from_(f32/f64)
  • to_(f32/f64)
  • from_bits
  • to_bits
  • add
  • sub
  • mul
  • div
  • cmp
  • neg
  • sqrt
  • powi
  • copysign
  • trunc
  • round
  • floor
  • sin
  • cos

No runtime deps