@@ -210,61 +210,70 @@ where
210
210
let pi_over_2 = ( pi / two) . value ;
211
211
let pi_over_4 = ( pi_over_2 / two) . value ;
212
212
213
- Some ( match ( intrinsic_name, args) {
213
+ // Remove `f32`/`f64` suffix, if any.
214
+ let name = intrinsic_name
215
+ . strip_suffix ( "f32" )
216
+ . or_else ( || intrinsic_name. strip_suffix ( "f64" ) )
217
+ . unwrap_or ( intrinsic_name) ;
218
+ // Also strip trailing `f` (indicates "float"), with an exception for "erf" to avoid
219
+ // removing that `f`.
220
+ let name = if name == "erf" { name } else { name. strip_suffix ( "f" ) . unwrap_or ( name) } ;
221
+ Some ( match ( name, args) {
214
222
// cos(±0) and cosh(±0)= 1
215
- ( "cosf32" | "cosf64" | "coshf " | "cosh" , [ input] ) if input. is_zero ( ) => one,
223
+ ( "cos " | "cosh" , [ input] ) if input. is_zero ( ) => one,
216
224
217
225
// e^0 = 1
218
- ( "expf32 " | "expf64" | "exp2f32" | "exp2f64 ", [ input] ) if input. is_zero ( ) => one,
226
+ ( "exp " | "exp2 " , [ input] ) if input. is_zero ( ) => one,
219
227
220
228
// tanh(±INF) = ±1
221
- ( "tanhf" | " tanh", [ input] ) if input. is_infinite ( ) => one. copy_sign ( * input) ,
229
+ ( "tanh" , [ input] ) if input. is_infinite ( ) => one. copy_sign ( * input) ,
222
230
223
231
// atan(±INF) = ±π/2
224
- ( "atanf" | " atan", [ input] ) if input. is_infinite ( ) => pi_over_2. copy_sign ( * input) ,
232
+ ( "atan" , [ input] ) if input. is_infinite ( ) => pi_over_2. copy_sign ( * input) ,
225
233
226
234
// erf(±INF) = ±1
227
- ( "erff" | " erf", [ input] ) if input. is_infinite ( ) => one. copy_sign ( * input) ,
235
+ ( "erf" , [ input] ) if input. is_infinite ( ) => one. copy_sign ( * input) ,
228
236
229
237
// erfc(-INF) = 2
230
- ( "erfcf" | " erfc", [ input] ) if input. is_neg_infinity ( ) => ( one + one) . value ,
238
+ ( "erfc" , [ input] ) if input. is_neg_infinity ( ) => ( one + one) . value ,
231
239
232
240
// hypot(x, ±0) = abs(x), if x is not a NaN.
233
- ( "_hypotf" | "hypotf" | "_hypot" | "hypot" , [ x, y] ) if !x. is_nan ( ) && y. is_zero ( ) =>
241
+ // `_hypot` is the Windows name for this.
242
+ ( "_hypot" | "hypot" , [ x, y] ) if !x. is_nan ( ) && y. is_zero ( ) =>
234
243
x. abs ( ) ,
235
244
236
245
// atan2(±0,−0) = ±π.
237
246
// atan2(±0, y) = ±π for y < 0.
238
247
// Must check for non NaN because `y.is_negative()` also applies to NaN.
239
- ( "atan2f" | " atan2", [ x, y] ) if ( x. is_zero ( ) && ( y. is_negative ( ) && !y. is_nan ( ) ) ) =>
248
+ ( "atan2" , [ x, y] ) if ( x. is_zero ( ) && ( y. is_negative ( ) && !y. is_nan ( ) ) ) =>
240
249
pi. copy_sign ( * x) ,
241
250
242
251
// atan2(±x,−∞) = ±π for finite x > 0.
243
- ( "atan2f" | " atan2", [ x, y] )
252
+ ( "atan2" , [ x, y] )
244
253
if ( !x. is_zero ( ) && !x. is_infinite ( ) ) && y. is_neg_infinity ( ) =>
245
254
pi. copy_sign ( * x) ,
246
255
247
256
// atan2(x, ±0) = −π/2 for x < 0.
248
257
// atan2(x, ±0) = π/2 for x > 0.
249
- ( "atan2f" | " atan2", [ x, y] ) if !x. is_zero ( ) && y. is_zero ( ) => pi_over_2. copy_sign ( * x) ,
258
+ ( "atan2" , [ x, y] ) if !x. is_zero ( ) && y. is_zero ( ) => pi_over_2. copy_sign ( * x) ,
250
259
251
260
//atan2(±∞, −∞) = ±3π/4
252
- ( "atan2f" | " atan2", [ x, y] ) if x. is_infinite ( ) && y. is_neg_infinity ( ) =>
261
+ ( "atan2" , [ x, y] ) if x. is_infinite ( ) && y. is_neg_infinity ( ) =>
253
262
( pi_over_4 * three) . value . copy_sign ( * x) ,
254
263
255
264
//atan2(±∞, +∞) = ±π/4
256
- ( "atan2f" | " atan2", [ x, y] ) if x. is_infinite ( ) && y. is_pos_infinity ( ) =>
265
+ ( "atan2" , [ x, y] ) if x. is_infinite ( ) && y. is_pos_infinity ( ) =>
257
266
pi_over_4. copy_sign ( * x) ,
258
267
259
268
// atan2(±∞, y) returns ±π/2 for finite y.
260
- ( "atan2f" | " atan2", [ x, y] ) if x. is_infinite ( ) && ( !y. is_infinite ( ) && !y. is_nan ( ) ) =>
269
+ ( "atan2" , [ x, y] ) if x. is_infinite ( ) && ( !y. is_infinite ( ) && !y. is_nan ( ) ) =>
261
270
pi_over_2. copy_sign ( * x) ,
262
271
263
272
// (-1)^(±INF) = 1
264
- ( "powf32" | "powf64 ", [ base, exp] ) if * base == -one && exp. is_infinite ( ) => one,
273
+ ( "pow " , [ base, exp] ) if * base == -one && exp. is_infinite ( ) => one,
265
274
266
275
// 1^y = 1 for any y, even a NaN
267
- ( "powf32" | "powf64 ", [ base, exp] ) if * base == one => {
276
+ ( "pow " , [ base, exp] ) if * base == one => {
268
277
let rng = this. machine . rng . get_mut ( ) ;
269
278
// SNaN exponents get special treatment: they might return 1, or a NaN.
270
279
let return_nan = exp. is_signaling ( ) && this. machine . float_nondet && rng. random ( ) ;
@@ -273,7 +282,7 @@ where
273
282
}
274
283
275
284
// x^(±0) = 1 for any x, even a NaN
276
- ( "powf32" | "powf64 ", [ base, exp] ) if exp. is_zero ( ) => {
285
+ ( "pow " , [ base, exp] ) if exp. is_zero ( ) => {
277
286
let rng = this. machine . rng . get_mut ( ) ;
278
287
// SNaN bases get special treatment: they might return 1, or a NaN.
279
288
let return_nan = base. is_signaling ( ) && this. machine . float_nondet && rng. random ( ) ;
0 commit comments