Crate srmfpa

Crate srmfpa 

Source
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

§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§

f16f16_softfloat
Functions for f16.
f32
Functions for f32.
f64
Functions for f64.
f128f128_softfloat
Functions for f128.
prelude
fpa_specr’s prelude.

Enums§

RoundingMode
IEEE 754 rounding mode

Traits§

CielArithmetic
Provides arithmetics (add, sub, mul, div and mul_add) as rounding toward +∞.
CielMath
Provides a math function (sqrt) as rounding toward +∞.
FloorArithmetic
Provides arithmetics (add, sub, mul, div and mul_add) as rounding toward -∞.
FloorMath
Provides a math function (sqrt) as rounding toward -∞.
RoundTiesEvenArithmetic
Provides arithmetics (add, sub, mul, div and mul_add) as rounding to nearest, ties to even.
RoundTiesEvenMath
Provides a math function (sqrt) as rounding to nearest, ties to even.
RoundingArithmetic
Provides arithmetics (add, sub, mul, div and mul_add) with specified rounding mode.
RoundingMath
Provides a math function (sqrt) with specified rounding mode.
TruncArithmetic
Provides arithmetics (add, sub, mul, div and mul_add) as rounding toward 0.
TruncMath
Provides a math function (sqrt) as rounding toward 0.