Skip to content
Closed
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
68fb25e
Make use of raw strings in `core::fmt::builders`
tgross35 Jul 19, 2024
827970e
Implement `debug_more_non_exhaustive`
tgross35 Jul 19, 2024
803cbaf
Add f16 and f128 to tests/ui/consts/const-float-bits-conv.rs
rezwanahmedsami Aug 17, 2024
1687c55
bootstrap: fix clean's `remove_dir_all` implementation
jieyouxu Aug 17, 2024
9f39427
Added #[cfg(target_arch = x86_64)] to f16 and f128
rezwanahmedsami Aug 18, 2024
c7832b8
move `Build::update_submodule` to `Config::update_submodule`
onur-ozkan Aug 18, 2024
3d0f3b2
bypass `dry_run` if the command is `run_always`
onur-ozkan Aug 18, 2024
1ca2708
sync llvm submodule during config parse
onur-ozkan Aug 18, 2024
35752cf
Update `library/Cargo.toml` in weekly job
tgross35 Aug 19, 2024
d2d8fa4
fix broken bootstrap documentation
onur-ozkan Aug 19, 2024
75ed089
compiletest: use `std::fs::remove_dir_all` now that it is available
jieyouxu Aug 20, 2024
f5bae72
Point at explicit `'static` obligations on a trait
estebank Aug 12, 2024
40f1d9d
Add missing module flags for CFI and KCFI sanitizers
samitolvanen Aug 16, 2024
5d7ed27
Rollup merge of #127945 - tgross35:debug-more-non-exhaustive, r=Norat…
jieyouxu Aug 22, 2024
94a38fd
Rollup merge of #129070 - estebank:static-trait, r=davidtwco
jieyouxu Aug 22, 2024
0e92667
Rollup merge of #129187 - jieyouxu:squeaky-clean-windows-symlinks, r=…
jieyouxu Aug 22, 2024
b79cc36
Rollup merge of #129190 - rezwanahmedsami:master, r=tgross35
jieyouxu Aug 22, 2024
44cdda4
Rollup merge of #129231 - onur-ozkan:improve-submodule-updates, r=Mar…
jieyouxu Aug 22, 2024
360e826
Rollup merge of #129264 - tgross35:dependencies-ci-library, r=Kobzol
jieyouxu Aug 22, 2024
114d6b0
Rollup merge of #129302 - jieyouxu:compiletest-RAGEY, r=compiler-errors
jieyouxu Aug 22, 2024
a0428cb
Rollup merge of #129373 - samitolvanen:cfi-module-flags, r=compiler-e…
jieyouxu Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion tests/ui/consts/const-float-bits-conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#![feature(const_float_bits_conv)]
#![feature(const_float_classify)]
#![feature(f16)]
#![feature(f128)]
#![allow(unused_macro_rules)]

// Don't promote
const fn nop<T>(x: T) -> T { x }

Expand All @@ -28,6 +29,37 @@ fn has_broken_floats() -> bool {
std::env::var("TARGET").is_ok_and(|v| v.contains("i586"))
}

#[cfg(target_arch = "x86_64")]
fn f16(){
const_assert!((1f16).to_bits(), 0x3c00);
const_assert!(u16::from_be_bytes(1f16.to_be_bytes()), 0x3c00);
const_assert!((12.5f16).to_bits(), 0x4a40);
const_assert!(u16::from_le_bytes(12.5f16.to_le_bytes()), 0x4a40);
const_assert!((1337f16).to_bits(), 0x6539);
const_assert!(u16::from_ne_bytes(1337f16.to_ne_bytes()), 0x6539);
const_assert!((-14.25f16).to_bits(), 0xcb20);
const_assert!(f16::from_bits(0x3c00), 1.0);
const_assert!(f16::from_be_bytes(0x3c00u16.to_be_bytes()), 1.0);
const_assert!(f16::from_bits(0x4a40), 12.5);
const_assert!(f16::from_le_bytes(0x4a40u16.to_le_bytes()), 12.5);
const_assert!(f16::from_bits(0x5be0), 252.0);
const_assert!(f16::from_ne_bytes(0x5be0u16.to_ne_bytes()), 252.0);
const_assert!(f16::from_bits(0xcb20), -14.25);

// Check that NaNs roundtrip their bits regardless of signalingness
// 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
// NOTE: These names assume `f{BITS}::NAN` is a quiet NAN and IEEE754-2008's NaN rules apply!
const QUIET_NAN: u16 = f16::NAN.to_bits() ^ 0x0155;
const SIGNALING_NAN: u16 = f16::NAN.to_bits() ^ 0x02AA;

const_assert!(f16::from_bits(QUIET_NAN).is_nan());
const_assert!(f16::from_bits(SIGNALING_NAN).is_nan());
const_assert!(f16::from_bits(QUIET_NAN).to_bits(), QUIET_NAN);
if !has_broken_floats() {
const_assert!(f16::from_bits(SIGNALING_NAN).to_bits(), SIGNALING_NAN);
}
}

fn f32() {
const_assert!((1f32).to_bits(), 0x3f800000);
const_assert!(u32::from_be_bytes(1f32.to_be_bytes()), 0x3f800000);
Expand Down Expand Up @@ -88,7 +120,43 @@ fn f64() {
}
}

#[cfg(target_arch = "x86_64")]
fn f128() {
const_assert!((1f128).to_bits(), 0x3fff0000000000000000000000000000);
const_assert!(u128::from_be_bytes(1f128.to_be_bytes()), 0x3fff0000000000000000000000000000);
const_assert!((12.5f128).to_bits(), 0x40029000000000000000000000000000);
const_assert!(u128::from_le_bytes(12.5f128.to_le_bytes()), 0x40029000000000000000000000000000);
const_assert!((1337f128).to_bits(), 0x40094e40000000000000000000000000);
const_assert!(u128::from_ne_bytes(1337f128.to_ne_bytes()), 0x40094e40000000000000000000000000);
const_assert!((-14.25f128).to_bits(), 0xc002c800000000000000000000000000);
const_assert!(f128::from_bits(0x3fff0000000000000000000000000000), 1.0);
const_assert!(f128::from_be_bytes(0x3fff0000000000000000000000000000u128.to_be_bytes()), 1.0);
const_assert!(f128::from_bits(0x40029000000000000000000000000000), 12.5);
const_assert!(f128::from_le_bytes(0x40029000000000000000000000000000u128.to_le_bytes()), 12.5);
const_assert!(f128::from_bits(0x40094e40000000000000000000000000), 1337.0);
assert_eq!(f128::from_ne_bytes(0x40094e40000000000000000000000000u128.to_ne_bytes()), 1337.0);
const_assert!(f128::from_bits(0xc002c800000000000000000000000000), -14.25);

// Check that NaNs roundtrip their bits regardless of signalingness
// 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
// NOTE: These names assume `f{BITS}::NAN` is a quiet NAN and IEEE754-2008's NaN rules apply!
const QUIET_NAN: u128 = f128::NAN.to_bits() | 0x0000_AAAA_AAAA_AAAA_AAAA_AAAA_AAAA_AAAA;
const SIGNALING_NAN: u128 = f128::NAN.to_bits() ^ 0x0000_5555_5555_5555_5555_5555_5555_5555;

const_assert!(f128::from_bits(QUIET_NAN).is_nan());
const_assert!(f128::from_bits(SIGNALING_NAN).is_nan());
const_assert!(f128::from_bits(QUIET_NAN).to_bits(), QUIET_NAN);
if !has_broken_floats() {
const_assert!(f128::from_bits(SIGNALING_NAN).to_bits(), SIGNALING_NAN);
}
}

fn main() {
#[cfg(target_arch = "x86_64")]
{
f16();
f128();
}
f32();
f64();
}