Skip to content

Commit c27c761

Browse files
committed
Fix UB in test (really this time)
1 parent 6e07982 commit c27c761

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

crates/core_simd/tests/ops_impl/float_macros.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,21 +383,26 @@ macro_rules! float_tests {
383383
#[test]
384384
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
385385
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);
386391
const VALUES: [$scalar; 16] = [
387392
-0.0,
388393
0.0,
389394
-1.0,
390395
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,
393402
<$scalar>::MIN_POSITIVE,
394403
-<$scalar>::MIN_POSITIVE,
395404
<$scalar>::EPSILON,
396405
-<$scalar>::EPSILON,
397-
core::$scalar::consts::PI,
398-
-core::$scalar::consts::PI,
399-
core::$scalar::consts::TAU,
400-
-core::$scalar::consts::TAU,
401406
100.0 / 3.0,
402407
-100.0 / 3.0,
403408
];

0 commit comments

Comments
 (0)