#plus #value #approx-eq #round-to-fraction

no-std float_plus

Additional features for float values

12 stable releases

new 2.0.1 Apr 23, 2025
2.0.0 Jan 16, 2025
1.5.5 Aug 27, 2024

#262 in Math

Download history 10/week @ 2025-01-08 142/week @ 2025-01-15 9/week @ 2025-01-22 24/week @ 2025-01-29 32/week @ 2025-02-05 22/week @ 2025-02-12 14/week @ 2025-02-19 14/week @ 2025-02-26 64/week @ 2025-03-05 48/week @ 2025-03-19 60/week @ 2025-03-26 133/week @ 2025-04-02 161/week @ 2025-04-09 205/week @ 2025-04-16

588 downloads per month

MIT/Apache

43KB
1K SLoC

FLoat Plus

This library contains traits that extend the capabilities of f32 and f64.

RoundToSigDig::round_to_sf(..)

    let before = 123.123_456_789_f64;
    let after = before.round_to_sf(9);
    assert_eq!(after, 123.123_457_f64);

ApproxEqSf::aeq_sf(..)

    let a = 100.123_456_789_f64;
    let b = 100.123_457;
    assert!(a.aeq_sf(b, 9));

    let a = 100.123_454_789_f64;
    let b = 100.123_457;
    assert!(!a.aeq_sf(b, 9));

NApproxEqSf::nae_sf(..)

    let a = 100.123_456_789_f64;
    let b = 100.123_457;
    assert!(!a.nae_sf(b, 9));

    let a = 100.123_454_789_f64;
    let b = 100.123_457;
    assert!(a.nae_sf(b, 9));

ApproxEq::aeq(..)

    use float_plus::approx_eq::ApproxEq;

    let a = 100.123_456_789_f64;
    let b = 100.123_456_712_f64;

    assert!(a.aeq(b, 7));
    assert!(!a.aeq(b, 8));

NApproxEq::nae(..)

    use float_plus::approx_eq::ApproxNe;
    
    let a = 100.123_456_789_f64;
    let b = 100.123_456_712_f64;

    assert!(!a.nae(b, 7));
    assert!(a.nae(b, 8));

RoundToFraction

    use float_plus::RoundToFraction;

    let before = 100.123_456_789_f64;
    let after = before.round_to_fraction(5);
    assert_eq!(after, 100.123_46);

Dependencies

~625KB
~12K SLoC