Expand description
Floating-point’s four arithmetic operations (including fused multiply-add) and square root with strict rounding mode.
use srmfpa::prelude::*;
// Support add, sub, mul, div, mul_add (fma) and sqrt
assert_eq!(0.1f64.round_ties_even_add(0.2), 0.30000000000000004);
assert_eq!(0.1f64.ciel_add(0.2), 0.30000000000000004);
assert_eq!(0.1f64.floor_add(0.2), 0.3);
assert_eq!(0.1f64.trunc_add(0.2), 0.3);
assert_eq!((-0.1f64).round_ties_even_add(-0.2), -0.30000000000000004);
assert_eq!((-0.1f64).ciel_add(-0.2), -0.3);
assert_eq!((-0.1f64).floor_add(-0.2), -0.30000000000000004);
assert_eq!((-0.1f64).trunc_add(-0.2), -0.3);
// Generic ops
assert_eq!(0.1.round_add(0.2, &RoundingMode::NearestTiesEven), 0.30000000000000004);
// Functions are available
use srmfpa::f64::{ciel_add, floor_add};
assert_eq!(ciel_add(0.1, 0.2), 0.30000000000000004);
assert_eq!(floor_add(0.1, 0.2), 0.3);§Features
softfloat: use softfloat forf32andf64(enablef32_softfloatandf64_softfloat).f32_softfloat: support softfloatf32by Berkeley SoftFloat 3.f64_softfloat: support softfloatf64by Berkeley SoftFloat 3.f16_softfloat: support softfloatf16by Berkeley SoftFloat 3.f128_softfloat: support softfloatf128by Berkeley SoftFloat 3.
§Notes on Correctness and Configuration
As default, srmfpa uses C lang floating-point ops,
it maps f32 (f64) to float (double) and controls rounding mode by <fenv.h>.
Thus, rounding correctness depends on the environment (C compiler, libc, CPU etc.).
srmfpa supports softfloat ops by Berkeley SoftFloat 3 with fN_softfloat features.
It provides correct rounding ops for evey IEEE 754 rounding modes.
srmfpa uses the default C compiler options of cc,
and does not (explicitly) specify other options.
It is recommended to pass corresponding options (-std=c11, -lm, -frounding-math, -mfma etc.)
to obtain the desired result.
See cc crate document for detail of configuration.
Modules§
- f16
f16_softfloat - Functions for
f16. - f32
- Functions for
f32. - f64
- Functions for
f64. - f128
f128_softfloat - Functions for
f128. - prelude
- fpa_specr’s prelude.
Enums§
- Rounding
Mode - IEEE 754 rounding mode
Traits§
- Ciel
Arithmetic - Provides arithmetics (add, sub, mul, div and mul_add) as rounding toward +∞.
- Ciel
Math - Provides a math function (
sqrt) as rounding toward +∞. - Floor
Arithmetic - Provides arithmetics (add, sub, mul, div and mul_add) as rounding toward -∞.
- Floor
Math - Provides a math function (
sqrt) as rounding toward -∞. - Round
Ties Even Arithmetic - Provides arithmetics (add, sub, mul, div and mul_add) as rounding to nearest, ties to even.
- Round
Ties Even Math - Provides a math function (
sqrt) as rounding to nearest, ties to even. - Rounding
Arithmetic - Provides arithmetics (add, sub, mul, div and mul_add) with specified rounding mode.
- Rounding
Math - Provides a math function (
sqrt) with specified rounding mode. - Trunc
Arithmetic - Provides arithmetics (add, sub, mul, div and mul_add) as rounding toward 0.
- Trunc
Math - Provides a math function (
sqrt) as rounding toward 0.