@@ -276,7 +276,7 @@ macro_rules! apfloat_fallback {
276
276
// The expression to run. This expression may use `FloatTy` for its signature.
277
277
// Optionally, the final conversion back to a float can be suppressed using
278
278
// `=> no_convert` (for e.g. operations that return a bool).
279
- $op: expr $( => $convert: ident) ?,
279
+ $op: expr $( => $convert: ident) ? $ ( ; $apfloat_op : expr ) ? ,
280
280
// Arguments that get passed to `$op` after converting to a float
281
281
$( $arg: expr) ,+
282
282
$( , ) ?
@@ -292,26 +292,40 @@ macro_rules! apfloat_fallback {
292
292
use rustc_apfloat:: Float ;
293
293
type FloatTy = rustc_apfloat:: ieee:: $apfloat_ty;
294
294
295
- let op_res = $op( $( FloatTy :: from_bits( $arg. to_bits( ) . into( ) ) ) ,+ ) ;
296
-
297
- apfloat_fallback!( @convert $float_ty, op_res $( , $convert) ?)
295
+ apfloat_fallback!( @inner
296
+ fty: $float_ty,
297
+ // Apply a conversion to `FloatTy` to each arg, then pass all args to `$op`
298
+ op_res: $op( $( FloatTy :: from_bits( $arg. to_bits( ) . into( ) ) ) ,+ ) ,
299
+ $( apfloat_op: $apfloat_op, ) ?
300
+ $( conv_opts: $convert, ) ?
301
+ args: $( $arg) ,+
302
+ )
298
303
} ;
299
304
300
305
ret
301
306
} } ;
302
307
303
308
// Operations that do not need converting back to a float
304
- ( @convert $float_ty: ty, $val: expr, no_convert) => {
309
+ ( @inner fty : $float_ty: ty, op_res : $val: expr, conv_opts : no_convert, args : $ ( $_arg : expr ) ,+ ) => {
305
310
$val
306
311
} ;
307
312
308
313
// Some apfloat operations return a `StatusAnd` that we need to extract the value from. This
309
314
// is the default.
310
- ( @convert $float_ty: ty, $val: expr) => { {
315
+ ( @inner fty : $float_ty: ty, op_res : $val: expr, args : $ ( $_arg : expr ) ,+ ) => { {
311
316
// ignore the status, just get the value
312
317
let unwrapped = $val. value;
313
318
314
319
<$float_ty>:: from_bits( FloatTy :: to_bits( unwrapped) . try_into( ) . unwrap( ) )
315
320
} } ;
316
321
322
+ // This is the case where we can't use the same expression for the default builtin and
323
+ // nonstandard apfloat fallbac (e.g. `as` casts in std are normal functions in apfloat, so
324
+ // two separate expressions must be specified.
325
+ ( @inner
326
+ fty: $float_ty: ty, op_res: $_val: expr,
327
+ apfloat_op: $apfloat_op: expr, args: $( $arg: expr) ,+
328
+ ) => { {
329
+ $apfloat_op( $( $arg) ,+)
330
+ } } ;
317
331
}
0 commit comments