This repository was archived by the owner on Apr 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +35
-39
lines changed Expand file tree Collapse file tree 2 files changed +35
-39
lines changed Original file line number Diff line number Diff line change 77) ]
88
99mod math;
10-
11- use core:: { f32, f64} ;
12-
1310pub use self :: math:: * ;
14-
15- /// Approximate equality with 1 ULP of tolerance
16- #[ doc( hidden) ]
17- #[ inline]
18- pub fn _eqf ( a : f32 , b : f32 ) -> Result < ( ) , u32 > {
19- if a. is_nan ( ) && b. is_nan ( ) {
20- Ok ( ( ) )
21- } else {
22- let err = ( a. to_bits ( ) as i32 ) . wrapping_sub ( b. to_bits ( ) as i32 ) . abs ( ) ;
23-
24- if err <= 1 {
25- Ok ( ( ) )
26- } else {
27- Err ( err as u32 )
28- }
29- }
30- }
31-
32- #[ doc( hidden) ]
33- #[ inline]
34- pub fn _eq ( a : f64 , b : f64 ) -> Result < ( ) , u64 > {
35- if a. is_nan ( ) && b. is_nan ( ) {
36- Ok ( ( ) )
37- } else {
38- let err = ( a. to_bits ( ) as i64 ) . wrapping_sub ( b. to_bits ( ) as i64 ) . abs ( ) ;
39-
40- if err <= 1 {
41- Ok ( ( ) )
42- } else {
43- Err ( err as u64 )
44- }
45- }
46- }
47-
48- #[ cfg( all( test, feature = "musl-reference-tests" ) ) ]
49- include ! ( concat!( env!( "OUT_DIR" ) , "/musl-tests.rs" ) ) ;
Original file line number Diff line number Diff line change 11#![ cfg( test) ]
22
3+ use core:: { f32, f64} ;
34use libm:: * ;
45
6+ /// Approximate equality with 1 ULP of tolerance
7+ #[ inline]
8+ fn _eqf ( a : f32 , b : f32 ) -> Result < ( ) , u32 > {
9+ if a. is_nan ( ) && b. is_nan ( ) {
10+ Ok ( ( ) )
11+ } else {
12+ let err = ( a. to_bits ( ) as i32 ) . wrapping_sub ( b. to_bits ( ) as i32 ) . abs ( ) ;
13+
14+ if err <= 1 {
15+ Ok ( ( ) )
16+ } else {
17+ Err ( err as u32 )
18+ }
19+ }
20+ }
21+
22+ #[ inline]
23+ fn _eq ( a : f64 , b : f64 ) -> Result < ( ) , u64 > {
24+ if a. is_nan ( ) && b. is_nan ( ) {
25+ Ok ( ( ) )
26+ } else {
27+ let err = ( a. to_bits ( ) as i64 ) . wrapping_sub ( b. to_bits ( ) as i64 ) . abs ( ) ;
28+
29+ if err <= 1 {
30+ Ok ( ( ) )
31+ } else {
32+ Err ( err as u64 )
33+ }
34+ }
35+ }
36+
37+ #[ cfg( all( test, feature = "musl-reference-tests" ) ) ]
38+ include ! ( concat!( env!( "OUT_DIR" ) , "/musl-tests.rs" ) ) ;
39+
540#[ test]
641fn remquo_q_overflow ( ) {
742 // 0xc000000000000001, 0x04c0000000000004
You can’t perform that action at this time.
0 commit comments