#floating-point #arithmetic-operations #square-root #rounding-mode #correct-rounding

srmfpa

Floating-point's four arithmetic operations (including fused multiply-add) and square root with strict rounding mode

2 releases

0.1.1 Jun 30, 2024
0.1.0 Jun 29, 2024

#694 in Math

MIT/Apache

510KB
8K SLoC

C 5K SLoC // 0.5% comments Rust 3K SLoC // 0.0% comments

srmfpa

Crates.io Version Crates.io MSRV GitHub Actions Workflow Status docs.rs Crates.io License

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.1.round_ties_even_add(0.2), 0.30000000000000004);
assert_eq!(0.1.ciel_add(0.2), 0.30000000000000004);
assert_eq!(0.1.floor_add(0.2), 0.3);
assert_eq!(0.1.trunc_add(0.2), 0.3);

assert_eq!((-0.1).round_ties_even_add(-0.2), -0.30000000000000004);
assert_eq!((-0.1).ciel_add(-0.2), -0.3);
assert_eq!((-0.1).floor_add(-0.2), -0.30000000000000004);
assert_eq!((-0.1).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

Licence

MIT or Apache-2.0

Dependencies

~0–280KB