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