@@ -383,21 +383,26 @@ macro_rules! float_tests {
383
383
#[ test]
384
384
#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test) ]
385
385
fn to_int_unchecked( ) {
386
+ // The maximum integer that can be represented by the equivalently sized float has
387
+ // all of the mantissa digits set to 1, pushed up to the MSB.
388
+ const ALL_MANTISSA_BITS : $int_scalar = ( ( 1 << <$scalar>:: MANTISSA_DIGITS ) - 1 ) ;
389
+ const MAX_REPRESENTABLE_VALUE : $int_scalar =
390
+ ALL_MANTISSA_BITS << ( core:: mem:: size_of:: <$scalar>( ) * 8 as usize - <$scalar>:: MANTISSA_DIGITS as usize ) ;
386
391
const VALUES : [ $scalar; 16 ] = [
387
392
-0.0 ,
388
393
0.0 ,
389
394
-1.0 ,
390
395
1.0 ,
391
- <$int_scalar>:: MAX as $scalar,
392
- <$int_scalar>:: MIN as $scalar,
396
+ ALL_MANTISSA_BITS as $scalar,
397
+ -ALL_MANTISSA_BITS as $scalar,
398
+ MAX_REPRESENTABLE_VALUE as $scalar,
399
+ -MAX_REPRESENTABLE_VALUE as $scalar,
400
+ ( MAX_REPRESENTABLE_VALUE / 2 ) as $scalar,
401
+ ( -MAX_REPRESENTABLE_VALUE / 2 ) as $scalar,
393
402
<$scalar>:: MIN_POSITIVE ,
394
403
-<$scalar>:: MIN_POSITIVE ,
395
404
<$scalar>:: EPSILON ,
396
405
-<$scalar>:: EPSILON ,
397
- core:: $scalar:: consts:: PI ,
398
- -core:: $scalar:: consts:: PI ,
399
- core:: $scalar:: consts:: TAU ,
400
- -core:: $scalar:: consts:: TAU ,
401
406
100.0 / 3.0 ,
402
407
-100.0 / 3.0 ,
403
408
] ;
0 commit comments