4 releases
0.1.3 | Apr 18, 2023 |
---|---|
0.1.2 | Feb 18, 2023 |
0.1.1 | Feb 7, 2023 |
0.1.0 | Feb 7, 2023 |
#23 in No standard library
5,185 downloads per month
Used in 3 crates
(2 directly)
140KB
3K
SLoC
Rust float-point in constant context
Floating-point code is from compiler_builtins = "0.1.87"
and libm = "0.2.6"
, and has been rewritten for use in a constant context.
Some fuzzing of operations is performed to ensure correctness of the port, but please open an issue if there is any inconsistent behavior.
Features:
no_std
const_trait_impl
const_mut_refs
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()
}
lib.rs
:
Rust float-point in constant context
Features:
no_std
const_trait_impl
const_mut_refs
work in stable
:
# use const_soft_float::soft_f32::SoftF32;
const fn const_f32_add(a: f32, b: f32) -> f32 {
SoftF32(a).add(SoftF32(b)).to_f32()
}
with const_trait_impl
usage (requires nightly
):
# cfg_if::cfg_if! {
# if #[cfg(nightly)] {
# #![feature(const_trait_impl)]
# use const_soft_float::soft_f32::SoftF32;
const fn const_f32_add(a: f32, b: f32) -> f32 {
(SoftF32(a) + SoftF32(b)).to_f32()
}
# }
# }
with const_mut_refs
usage (requires nightly
):
# cfg_if::cfg_if! {
# if #[cfg(nightly)] {
# #![feature(const_trait_impl)]
# #![feature(const_mut_refs)]
# use const_soft_float::soft_f32::SoftF32;
const fn const_f32_add(a: f32, b: f32) -> f32 {
let mut x = SoftF32(a);
x += SoftF32(b);
x.to_f32()
}
# }
# }