#deviation #value #measure #range #math #accuracy #representation

tolerance

Math representation of the physically needed permissible deviation of measures

8 stable releases

1.1.2 Nov 10, 2024
1.1.1 Oct 14, 2024
1.0.4 Sep 12, 2024
1.0.3 Aug 29, 2024
1.0.2 Jun 29, 2023

#294 in Algorithms

Download history 88/week @ 2024-08-24 16/week @ 2024-08-31 165/week @ 2024-09-07 49/week @ 2024-09-14 13/week @ 2024-09-21 134/week @ 2024-09-28 28/week @ 2024-10-05 166/week @ 2024-10-12 11/week @ 2024-10-19 104/week @ 2024-11-09 11/week @ 2024-11-16 2/week @ 2024-11-23 11/week @ 2024-11-30

128 downloads per month

MIT license

83KB
2K SLoC

Tolerance

crates.io crates.io Documentation

Math representation of the physically needed permissible deviation of measures. Avoiding floating point inaccuracy by calculating with 4 fractional digits. Allows to calculate with tolerance ranges in a consistent way.

Description

The two tolerance-types T128 and T64 handles the 3 values of the tolerance: the par (value) and it's 2 deviations (plus & minus). Based of own types Myth64, Myth32, Myth16 with a accuracy of 1/10th my-meter (= 0.1μ).

T128

Based on a Myth64 (64bit) for the value it could handle sizes up to +/-922_337_203 km with a deviation of +/-214 m (Myth32).

T64

Based on a Myth32 (32bit) for the value it could handle sizes up to +/-214 m with a deviation of +/-3 mm (Myth16).

Example

use tolerance::T128;

let width1 = T128::new(100.0, 0.05, -0.2);
let width2 = T128::with_sym(50.0, 0.05);

// Adding two `T128`s is straightforward.
assert_eq!(width1 + width2, T128::new(150.0, 0.1, -0.25));

// `!` inverts the direction of tolerance to /subtract/ measures.
assert_eq!(!width1, T128::new(-100.0, 0.2, -0.05));

// Adding an inverted `T128` wides the tolerance.
assert_eq!(width1 + !width1, T128::new(0.0, 0.25, -0.25));

Serde

Serde-support can be activated by the serde-feature.

History

Started as AllowanceValue renamed and moved for better usability.

License

Licensed under MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.

Dependencies

~160KB