Skip to content

Commit bd6f053

Browse files
committed
Auto merge of #149682 - matthiaskrgr:rollup-serlk7i, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang/rust#148662 (alloc: Document panics when allocations will exceed max) - rust-lang/rust#148811 (core docs: rewrite `panic::Location::caller` with visual line/column numbers) - rust-lang/rust#149101 (Improve mutable-binding suggestion to include name) - rust-lang/rust#149477 (float::maximum/minimum: make docs more streamlined) - rust-lang/rust#149547 (library: Rename `IterRange*` to `Range*Iter`) - rust-lang/rust#149548 (Generate delegation error body when delegation is not resolved) - rust-lang/rust#149630 (Check identifiers defined in macros when suggesting identifiers hidden by hygiene) - rust-lang/rust#149647 (Add regression test for 141845) - rust-lang/rust#149661 (Fix for LLVM22 making lowering decisions dependent on RuntimeLibraryInfo.) - rust-lang/rust#149666 (Add perma-unstable `--print=backend-has-zstd` for use by compiletest) - rust-lang/rust#149671 (interpret: test SNaN handling of float min/max and update comments) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 589dedf + b3c3832 commit bd6f053

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

tests/pass/float.rs

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,15 @@ macro_rules! assert_approx_eq {
4848
};
4949
}
5050

51-
/// From IEEE 754 a Signaling NaN for single precision has the following representation:
52-
/// ```
53-
/// s | 1111 1111 | 0x..x
54-
/// ````
55-
/// Were at least one `x` is a 1.
56-
///
57-
/// This sNaN has the following representation and is used for testing purposes.:
58-
/// ```
59-
/// 0 | 1111111 | 01..0
60-
/// ```
61-
const SNAN_F32: f32 = f32::from_bits(0x7fa00000);
62-
63-
/// From IEEE 754 a Signaling NaN for double precision has the following representation:
64-
/// ```
65-
/// s | 1111 1111 111 | 0x..x
66-
/// ````
67-
/// Were at least one `x` is a 1.
68-
///
69-
/// This sNaN has the following representation and is used for testing purposes.:
70-
/// ```
71-
/// 0 | 1111 1111 111 | 01..0
72-
/// ```
73-
const SNAN_F64: f64 = f64::from_bits(0x7ff4000000000000);
51+
/// We turn the quiet NaN f*::NAN into a signaling one by flipping the first (most significant)
52+
/// two bits of the mantissa. For this we have to shift by `MANTISSA_DIGITS-3` because:
53+
/// we subtract 1 as the actual mantissa is 1 bit smaller, and 2 more as that's the width
54+
/// if the value we are shifting.
55+
const F16_SNAN: f16 = f16::from_bits(f16::NAN.to_bits() ^ (0b11 << (f16::MANTISSA_DIGITS - 3)));
56+
const F32_SNAN: f32 = f32::from_bits(f32::NAN.to_bits() ^ (0b11 << (f32::MANTISSA_DIGITS - 3)));
57+
const F64_SNAN: f64 = f64::from_bits(f64::NAN.to_bits() ^ (0b11 << (f64::MANTISSA_DIGITS - 3)));
58+
const F128_SNAN: f128 =
59+
f128::from_bits(f128::NAN.to_bits() ^ (0b11 << (f128::MANTISSA_DIGITS - 3)));
7460

7561
fn main() {
7662
basic();
@@ -757,6 +743,8 @@ fn ops() {
757743
assert_eq(f16::NAN.max(-9.0), -9.0);
758744
assert_eq((9.0_f16).min(f16::NAN), 9.0);
759745
assert_eq((-9.0_f16).max(f16::NAN), -9.0);
746+
assert_eq(F16_SNAN.min(9.0), 9.0);
747+
assert_eq((-9.0_f16).max(F16_SNAN), -9.0);
760748

761749
// f32 min/max
762750
assert_eq((1.0 as f32).max(-1.0), 1.0);
@@ -765,6 +753,8 @@ fn ops() {
765753
assert_eq(f32::NAN.max(-9.0), -9.0);
766754
assert_eq((9.0 as f32).min(f32::NAN), 9.0);
767755
assert_eq((-9.0 as f32).max(f32::NAN), -9.0);
756+
assert_eq(F32_SNAN.min(9.0), 9.0);
757+
assert_eq((-9.0_f32).max(F32_SNAN), -9.0);
768758

769759
// f64 min/max
770760
assert_eq((1.0 as f64).max(-1.0), 1.0);
@@ -773,6 +763,8 @@ fn ops() {
773763
assert_eq(f64::NAN.max(-9.0), -9.0);
774764
assert_eq((9.0 as f64).min(f64::NAN), 9.0);
775765
assert_eq((-9.0 as f64).max(f64::NAN), -9.0);
766+
assert_eq(F64_SNAN.min(9.0), 9.0);
767+
assert_eq((-9.0_f64).max(F64_SNAN), -9.0);
776768

777769
// f128 min/max
778770
assert_eq((1.0_f128).max(-1.0), 1.0);
@@ -781,6 +773,8 @@ fn ops() {
781773
assert_eq(f128::NAN.max(-9.0), -9.0);
782774
assert_eq((9.0_f128).min(f128::NAN), 9.0);
783775
assert_eq((-9.0_f128).max(f128::NAN), -9.0);
776+
assert_eq(F128_SNAN.min(9.0), 9.0);
777+
assert_eq((-9.0_f128).max(F128_SNAN), -9.0);
784778

785779
// f16 copysign
786780
assert_eq(3.5_f16.copysign(0.42), 3.5_f16);
@@ -1548,15 +1542,15 @@ fn test_non_determinism() {
15481542
test_operations_f128(25., 18.);
15491543

15501544
// SNaN^0 = (1 | NaN)
1551-
check_nondet(|| f32::powf(SNAN_F32, 0.0).is_nan());
1552-
check_nondet(|| f64::powf(SNAN_F64, 0.0).is_nan());
1545+
check_nondet(|| f32::powf(F32_SNAN, 0.0).is_nan());
1546+
check_nondet(|| f64::powf(F64_SNAN, 0.0).is_nan());
15531547

15541548
// 1^SNaN = (1 | NaN)
1555-
check_nondet(|| f32::powf(1.0, SNAN_F32).is_nan());
1556-
check_nondet(|| f64::powf(1.0, SNAN_F64).is_nan());
1549+
check_nondet(|| f32::powf(1.0, F32_SNAN).is_nan());
1550+
check_nondet(|| f64::powf(1.0, F64_SNAN).is_nan());
15571551

15581552
// same as powf (keep it consistent):
15591553
// x^SNaN = (1 | NaN)
1560-
check_nondet(|| f32::powi(SNAN_F32, 0).is_nan());
1561-
check_nondet(|| f64::powi(SNAN_F64, 0).is_nan());
1554+
check_nondet(|| f32::powi(F32_SNAN, 0).is_nan());
1555+
check_nondet(|| f64::powi(F64_SNAN, 0).is_nan());
15621556
}

0 commit comments

Comments
 (0)