Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions library/compiler-builtins/compiler-builtins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#![feature(repr_simd)]
#![feature(macro_metavar_expr_concat)]
#![feature(rustc_attrs)]
#![feature(float_bits_const)]
#![cfg_attr(f16_enabled, feature(f16))]
#![cfg_attr(f128_enabled, feature(f128))]
#![no_builtins]
Expand Down
5 changes: 5 additions & 0 deletions library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ impl f128 {
#[unstable(feature = "f128", issue = "116909")]
pub const RADIX: u32 = 2;

/// The size of this float type in bits.
// #[unstable(feature = "f128", issue = "116909")]
#[unstable(feature = "float_bits_const", issue = "151073")]
pub const BITS: u32 = 128;

/// Number of significant digits in base 2.
///
/// Note that the size of the mantissa in the bitwise representation is one
Expand Down
5 changes: 5 additions & 0 deletions library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ impl f16 {
#[unstable(feature = "f16", issue = "116909")]
pub const RADIX: u32 = 2;

/// The size of this float type in bits.
// #[unstable(feature = "f16", issue = "116909")]
#[unstable(feature = "float_bits_const", issue = "151073")]
pub const BITS: u32 = 16;

/// Number of significant digits in base 2.
///
/// Note that the size of the mantissa in the bitwise representation is one
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ impl f32 {
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
pub const RADIX: u32 = 2;

/// The size of this float type in bits.
#[unstable(feature = "float_bits_const", issue = "151073")]
pub const BITS: u32 = 32;

/// Number of significant digits in base 2.
///
/// Note that the size of the mantissa in the bitwise representation is one
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ impl f64 {
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
pub const RADIX: u32 = 2;

/// The size of this float type in bits.
#[unstable(feature = "float_bits_const", issue = "151073")]
pub const BITS: u32 = 64;

/// Number of significant digits in base 2.
///
/// Note that the size of the mantissa in the bitwise representation is one
Expand Down
6 changes: 3 additions & 3 deletions src/tools/miri/tests/pass/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ macro_rules! test_ftoi_itof {
assert_itof(i, f, msg);
}

let fbits = <$fty>::BITS;
let fbits = <$fty as Float>::BITS;
let fsig_bits = <$fty>::SIGNIFICAND_BITS;
let ibits = <$ity>::BITS;
let imax: $ity = <$ity>::MAX;
Expand Down Expand Up @@ -528,9 +528,9 @@ macro_rules! test_ftof {
assert!((<$f1>::NAN as $f2).is_nan(), "{} -> {} nan", stringify!($f1), stringify!($f2));

let min_sub_casted = <$f1>::from_bits(0x1) as $f2;
let min_neg_sub_casted = <$f1>::from_bits(0x1 | 1 << (<$f1>::BITS - 1)) as $f2;
let min_neg_sub_casted = <$f1>::from_bits(0x1 | 1 << (<$f1 as Float>::BITS - 1)) as $f2;

if <$f1>::BITS > <$f2>::BITS {
if <$f1 as Float>::BITS > <$f2 as Float>::BITS {
assert_feq(<$f1>::MAX as $f2, <$f2>::INFINITY, "max -> inf");
assert_feq(<$f1>::MIN as $f2, <$f2>::NEG_INFINITY, "max -> inf");
assert_biteq(min_sub_casted, f2zero, "min subnormal -> 0.0");
Expand Down
2 changes: 1 addition & 1 deletion src/tools/test-float-parse/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ macro_rules! impl_float {
const BITS: u32 = <$ity>::BITS;
const MAN_BITS: u32 = Self::MANTISSA_DIGITS - 1;
const MAN_MASK: Self::Int = (Self::Int::ONE << Self::MAN_BITS) - Self::Int::ONE;
const SIGN_MASK: Self::Int = Self::Int::ONE << (Self::BITS-1);
const SIGN_MASK: Self::Int = Self::Int::ONE << (<Self as Float>::BITS-1);
fn from_bits(i: Self::Int) -> Self { Self::from_bits(i) }
fn to_bits(self) -> Self::Int { self.to_bits() }
fn constants() -> &'static Constants {
Expand Down
Loading