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 #[cfg(android_dylib)]
16 extern crate std;
17 
18 mod libm_helper;
19 mod math;
20 
21 use core::{f32, f64};
22 
23 pub use self::math::*;
24 pub use libm_helper::*;
25 
26 /// Approximate equality with 1 ULP of tolerance
27 #[doc(hidden)]
28 #[inline]
_eqf(a: f32, b: f32) -> Result<(), u32>29 pub fn _eqf(a: f32, b: f32) -> Result<(), u32> {
30     if a.is_nan() && b.is_nan() {
31         Ok(())
32     } else {
33         let err = (a.to_bits() as i32).wrapping_sub(b.to_bits() as i32).abs();
34 
35         if err <= 1 {
36             Ok(())
37         } else {
38             Err(err as u32)
39         }
40     }
41 }
42 
43 #[doc(hidden)]
44 #[inline]
_eq(a: f64, b: f64) -> Result<(), u64>45 pub fn _eq(a: f64, b: f64) -> Result<(), u64> {
46     if a.is_nan() && b.is_nan() {
47         Ok(())
48     } else {
49         let err = (a.to_bits() as i64).wrapping_sub(b.to_bits() as i64).abs();
50 
51         if err <= 1 {
52             Ok(())
53         } else {
54             Err(err as u64)
55         }
56     }
57 }
58 
59 // PowerPC tests are failing on LLVM 13: https://github.com/rust-lang/rust/issues/88520
60 #[cfg(not(target_arch = "powerpc64"))]
61 #[cfg(all(test, feature = "musl-reference-tests"))]
62 include!(concat!(env!("OUT_DIR"), "/musl-tests.rs"));
63