1 | //! libm in pure Rust |
2 | #![no_std ] |
3 | #![cfg_attr (feature = "unstable" , allow(internal_features))] |
4 | #![cfg_attr (feature = "unstable" , feature(core_intrinsics))] |
5 | #![allow (clippy::assign_op_pattern)] |
6 | #![allow (clippy::deprecated_cfg_attr)] |
7 | #![allow (clippy::eq_op)] |
8 | #![allow (clippy::float_cmp)] |
9 | #![allow (clippy::int_plus_one)] |
10 | #![allow (clippy::many_single_char_names)] |
11 | #![allow (clippy::mixed_case_hex_literals)] |
12 | #![allow (clippy::needless_return)] |
13 | #![allow (clippy::unreadable_literal)] |
14 | |
15 | mod libm_helper; |
16 | mod math; |
17 | |
18 | use core::{f32, f64}; |
19 | |
20 | pub use libm_helper::*; |
21 | |
22 | pub use self::math::*; |
23 | |
24 | /// Approximate equality with 1 ULP of tolerance |
25 | #[doc (hidden)] |
26 | #[inline ] |
27 | pub fn _eqf(a: f32, b: f32) -> Result<(), u32> { |
28 | if a.is_nan() && b.is_nan() { |
29 | Ok(()) |
30 | } else { |
31 | let err: i32 = (a.to_bits() as i32).wrapping_sub(b.to_bits() as i32).abs(); |
32 | |
33 | if err <= 1 { Ok(()) } else { Err(err as u32) } |
34 | } |
35 | } |
36 | |
37 | #[doc (hidden)] |
38 | #[inline ] |
39 | pub fn _eq(a: f64, b: f64) -> Result<(), u64> { |
40 | if a.is_nan() && b.is_nan() { |
41 | Ok(()) |
42 | } else { |
43 | let err: i64 = (a.to_bits() as i64).wrapping_sub(b.to_bits() as i64).abs(); |
44 | |
45 | if err <= 1 { Ok(()) } else { Err(err as u64) } |
46 | } |
47 | } |
48 | |