This repository was archived by the owner on Apr 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +103
-0
lines changed Expand file tree Collapse file tree 5 files changed +103
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,8 @@ mod modf;
149
149
mod modff;
150
150
mod nextafter;
151
151
mod nextafterf;
152
+ mod nexttoward;
153
+ mod nexttowardf;
152
154
mod pow;
153
155
mod powf;
154
156
mod remainder;
@@ -159,6 +161,8 @@ mod round;
159
161
mod roundf;
160
162
mod scalbn;
161
163
mod scalbnf;
164
+ mod signbit;
165
+ mod signbitf;
162
166
mod sin;
163
167
mod sincos;
164
168
mod sincosf;
@@ -263,6 +267,8 @@ pub use self::modf::modf;
263
267
pub use self :: modff:: modff;
264
268
pub use self :: nextafter:: nextafter;
265
269
pub use self :: nextafterf:: nextafterf;
270
+ pub use self :: nexttoward:: nexttoward;
271
+ pub use self :: nexttowardf:: nexttowardf;
266
272
pub use self :: pow:: pow;
267
273
pub use self :: powf:: powf;
268
274
pub use self :: remainder:: remainder;
Original file line number Diff line number Diff line change
1
+ use super :: signbit:: signbit;
2
+
3
+ #[ inline]
4
+ #[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
5
+ pub extern "C" fn nexttoward ( x : f64 , y : /*long double*/ f64 ) -> f64 {
6
+ let mut ux_i = x. to_bits ( ) ;
7
+ if x. is_nan ( ) || y. is_nan ( ) {
8
+ return x + y;
9
+ }
10
+
11
+ if x == y {
12
+ return y;
13
+ }
14
+ if x == 0.0 {
15
+ ux_i = 1 ;
16
+ if signbit ( y) != 0 {
17
+ ux_i |= 1_u64 << 63 ;
18
+ }
19
+ } else if x < y {
20
+ if signbit ( x) != 0 {
21
+ ux_i -= 1 ;
22
+ } else {
23
+ ux_i += 1 ;
24
+ }
25
+ } else {
26
+ if signbit ( x) != 0 {
27
+ ux_i += 1 ;
28
+ } else {
29
+ ux_i -= 1 ;
30
+ }
31
+ }
32
+ let e = ux_i >> 52 & 0x7ff ;
33
+ // raise overflow if ux.f is infinite and x is finite
34
+ if e == 0x7ff {
35
+ force_eval ! ( x + x) ;
36
+ }
37
+ // raise underflow if ux.f is subnormal or zero
38
+ let ux_f = f64:: from_bits ( ux_i) ;
39
+ if e == 0 {
40
+ force_eval ! ( x * x + ux_f * ux_f) ;
41
+ }
42
+ ux_f
43
+ }
Original file line number Diff line number Diff line change
1
+ use super :: signbit:: signbit;
2
+ use super :: signbitf:: signbitf;
3
+
4
+ #[ inline]
5
+ #[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
6
+ pub extern "C" fn nexttowardf ( x : f32 , y : f64 ) -> f32 {
7
+ let mut ux_i = x. to_bits ( ) ;
8
+ if x. is_nan ( ) || y. is_nan ( ) {
9
+ return ( x as f64 + y) as f32 ;
10
+ }
11
+
12
+ if x == y as f32 {
13
+ return y as f32 ;
14
+ }
15
+ if x == 0.0 {
16
+ ux_i = 1 ;
17
+ if signbit ( y) != 0 {
18
+ ux_i |= 0x8000_0000_u32 ;
19
+ }
20
+ } else if x < ( y as f32 ) {
21
+ if signbitf ( x) != 0 {
22
+ ux_i -= 1 ;
23
+ } else {
24
+ ux_i += 1 ;
25
+ }
26
+ } else {
27
+ if signbitf ( x) != 0 {
28
+ ux_i += 1 ;
29
+ } else {
30
+ ux_i -= 1 ;
31
+ }
32
+ }
33
+ let e = ux_i. wrapping_shr ( 0x7f80_0000_u32 ) ;
34
+ // raise overflow if ux.f is infinite and x is finite
35
+ if e == 0x7f80_0000_u32 {
36
+ force_eval ! ( x + x) ;
37
+ }
38
+ // raise underflow if ux.f is subnormal or zero
39
+ let ux_f = f32:: from_bits ( ux_i) ;
40
+ if e == 0 {
41
+ force_eval ! ( x * x + ux_f * ux_f) ;
42
+ }
43
+ ux_f
44
+ }
Original file line number Diff line number Diff line change
1
+ #[ inline]
2
+ #[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
3
+ pub ( crate ) extern "C" fn signbit ( x : f64 ) -> i32 {
4
+ ( x. to_bits ( ) >> 63 ) as i32
5
+ }
Original file line number Diff line number Diff line change
1
+ #[ inline]
2
+ #[ cfg_attr( all( test, assert_no_panic) , no_panic:: no_panic) ]
3
+ pub ( crate ) extern "C" fn signbitf ( x : f32 ) -> i32 {
4
+ ( x. to_bits ( ) >> 31 ) as i32
5
+ }
You can’t perform that action at this time.
0 commit comments