1 | //! libm in pure Rust |
2 | #![deny (warnings)] |
3 | #![no_std ] |
4 | #![cfg_attr (all(feature = "unstable" ), feature(core_intrinsics))] |
5 | #![allow (clippy::unreadable_literal)] |
6 | #![allow (clippy::many_single_char_names)] |
7 | #![allow (clippy::needless_return)] |
8 | #![allow (clippy::int_plus_one)] |
9 | #![allow (clippy::deprecated_cfg_attr)] |
10 | #![allow (clippy::mixed_case_hex_literals)] |
11 | #![allow (clippy::float_cmp)] |
12 | #![allow (clippy::eq_op)] |
13 | #![allow (clippy::assign_op_pattern)] |
14 | |
15 | mod libm_helper; |
16 | mod math; |
17 | |
18 | use core::{f32, f64}; |
19 | |
20 | pub use self::math::*; |
21 | pub use libm_helper::*; |
22 | |
23 | /// Approximate equality with 1 ULP of tolerance |
24 | #[doc (hidden)] |
25 | #[inline ] |
26 | pub fn _eqf(a: f32, b: f32) -> Result<(), u32> { |
27 | if a.is_nan() && b.is_nan() { |
28 | Ok(()) |
29 | } else { |
30 | let err: i32 = (a.to_bits() as i32).wrapping_sub(b.to_bits() as i32).abs(); |
31 | |
32 | if err <= 1 { |
33 | Ok(()) |
34 | } else { |
35 | Err(err as u32) |
36 | } |
37 | } |
38 | } |
39 | |
40 | #[doc (hidden)] |
41 | #[inline ] |
42 | pub fn _eq(a: f64, b: f64) -> Result<(), u64> { |
43 | if a.is_nan() && b.is_nan() { |
44 | Ok(()) |
45 | } else { |
46 | let err: i64 = (a.to_bits() as i64).wrapping_sub(b.to_bits() as i64).abs(); |
47 | |
48 | if err <= 1 { |
49 | Ok(()) |
50 | } else { |
51 | Err(err as u64) |
52 | } |
53 | } |
54 | } |
55 | |
56 | // PowerPC tests are failing on LLVM 13: https://github.com/rust-lang/rust/issues/88520 |
57 | #[cfg (not(target_arch = "powerpc64" ))] |
58 | #[cfg (all(test, feature = "musl-reference-tests" ))] |
59 | include!(concat!(env!("OUT_DIR" ), "/musl-tests.rs" )); |
60 | |