@@ -37,13 +37,13 @@ pub trait WasmFloat {
37
37
impl WasmFloat for f32 {
38
38
#[ inline]
39
39
fn wasm_trunc ( self ) -> f32 {
40
+ if self . is_nan ( ) {
41
+ return f32:: NAN ;
42
+ }
40
43
#[ cfg( feature = "std" ) ]
41
44
if !cfg ! ( windows) && !cfg ! ( target_arch = "riscv64" ) {
42
45
return self . trunc ( ) ;
43
46
}
44
- if self . is_nan ( ) {
45
- return f32:: NAN ;
46
- }
47
47
libm:: truncf ( self )
48
48
}
49
49
#[ inline]
@@ -56,24 +56,24 @@ impl WasmFloat for f32 {
56
56
}
57
57
#[ inline]
58
58
fn wasm_floor ( self ) -> f32 {
59
+ if self . is_nan ( ) {
60
+ return f32:: NAN ;
61
+ }
59
62
#[ cfg( feature = "std" ) ]
60
63
if !cfg ! ( target_arch = "riscv64" ) {
61
64
return self . floor ( ) ;
62
65
}
63
- if self . is_nan ( ) {
64
- return f32:: NAN ;
65
- }
66
66
libm:: floorf ( self )
67
67
}
68
68
#[ inline]
69
69
fn wasm_ceil ( self ) -> f32 {
70
+ if self . is_nan ( ) {
71
+ return f32:: NAN ;
72
+ }
70
73
#[ cfg( feature = "std" ) ]
71
74
if !cfg ! ( target_arch = "riscv64" ) {
72
75
return self . ceil ( ) ;
73
76
}
74
- if self . is_nan ( ) {
75
- return f32:: NAN ;
76
- }
77
77
libm:: ceilf ( self )
78
78
}
79
79
#[ inline]
@@ -94,13 +94,13 @@ impl WasmFloat for f32 {
94
94
}
95
95
#[ inline]
96
96
fn wasm_nearest ( self ) -> f32 {
97
+ if self . is_nan ( ) {
98
+ return f32:: NAN ;
99
+ }
97
100
#[ cfg( feature = "std" ) ]
98
101
if !cfg ! ( windows) && !cfg ! ( target_arch = "riscv64" ) {
99
102
return self . round_ties_even ( ) ;
100
103
}
101
- if self . is_nan ( ) {
102
- return f32:: NAN ;
103
- }
104
104
let round = libm:: roundf ( self ) ;
105
105
if libm:: fabsf ( self - round) != 0.5 {
106
106
return round;
@@ -162,13 +162,13 @@ impl WasmFloat for f32 {
162
162
impl WasmFloat for f64 {
163
163
#[ inline]
164
164
fn wasm_trunc ( self ) -> f64 {
165
+ if self . is_nan ( ) {
166
+ return f64:: NAN ;
167
+ }
165
168
#[ cfg( feature = "std" ) ]
166
169
if !cfg ! ( windows) && !cfg ! ( target_arch = "riscv64" ) {
167
170
return self . trunc ( ) ;
168
171
}
169
- if self . is_nan ( ) {
170
- return f64:: NAN ;
171
- }
172
172
libm:: trunc ( self )
173
173
}
174
174
#[ inline]
@@ -181,24 +181,24 @@ impl WasmFloat for f64 {
181
181
}
182
182
#[ inline]
183
183
fn wasm_floor ( self ) -> f64 {
184
+ if self . is_nan ( ) {
185
+ return f64:: NAN ;
186
+ }
184
187
#[ cfg( feature = "std" ) ]
185
188
if !cfg ! ( target_arch = "riscv64" ) {
186
189
return self . floor ( ) ;
187
190
}
188
- if self . is_nan ( ) {
189
- return f64:: NAN ;
190
- }
191
191
libm:: floor ( self )
192
192
}
193
193
#[ inline]
194
194
fn wasm_ceil ( self ) -> f64 {
195
+ if self . is_nan ( ) {
196
+ return f64:: NAN ;
197
+ }
195
198
#[ cfg( feature = "std" ) ]
196
199
if !cfg ! ( target_arch = "riscv64" ) {
197
200
return self . ceil ( ) ;
198
201
}
199
- if self . is_nan ( ) {
200
- return f64:: NAN ;
201
- }
202
202
libm:: ceil ( self )
203
203
}
204
204
#[ inline]
@@ -219,13 +219,13 @@ impl WasmFloat for f64 {
219
219
}
220
220
#[ inline]
221
221
fn wasm_nearest ( self ) -> f64 {
222
+ if self . is_nan ( ) {
223
+ return f64:: NAN ;
224
+ }
222
225
#[ cfg( feature = "std" ) ]
223
226
if !cfg ! ( windows) && !cfg ! ( target_arch = "riscv64" ) {
224
227
return self . round_ties_even ( ) ;
225
228
}
226
- if self . is_nan ( ) {
227
- return f64:: NAN ;
228
- }
229
229
let round = libm:: round ( self ) ;
230
230
if libm:: fabs ( self - round) != 0.5 {
231
231
return round;
0 commit comments