Skip to content

Commit

Permalink
Auto merge of #68325 - faern:move-numeric-consts-to-associated-consts…
Browse files Browse the repository at this point in the history
…-step1, r=LukasKalbertodt

Move numeric consts to associated consts step1

A subset of #67913. Implements the first step of RFC rust-lang/rfcs#2700

This PR adds the new constants as unstable constants and defines the old ones in terms of the new ones. Then fix a tiny bit of code that started having naming collisions because of the new assoc consts.

Removed a test that did not seem relevant any longer. Since doing just `u8::MIN` should now indeed be valid.
  • Loading branch information
bors committed Jan 30, 2020
2 parents 3024c4e + 61fecfb commit c4071d0
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 77 deletions.
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
#![feature(const_type_id)]
#![feature(const_caller_location)]
#![cfg_attr(bootstrap, feature(slice_patterns))]
#![feature(assoc_int_consts)]

#[prelude_import]
#[allow(unused)]
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/num/dec2flt/rawfp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ macro_rules! other_constants {
($type: ident) => {
const EXPLICIT_SIG_BITS: u8 = Self::SIG_BITS - 1;
const MAX_EXP: i16 = (1 << (Self::EXP_BITS - 1)) - 1;
const MIN_EXP: i16 = -Self::MAX_EXP + 1;
const MAX_EXP_INT: i16 = Self::MAX_EXP - (Self::SIG_BITS as i16 - 1);
const MIN_EXP: i16 = -<Self as RawFloat>::MAX_EXP + 1;
const MAX_EXP_INT: i16 = <Self as RawFloat>::MAX_EXP - (Self::SIG_BITS as i16 - 1);
const MAX_ENCODED_EXP: i16 = (1 << Self::EXP_BITS) - 1;
const MIN_EXP_INT: i16 = Self::MIN_EXP - (Self::SIG_BITS as i16 - 1);
const MIN_EXP_INT: i16 = <Self as RawFloat>::MIN_EXP - (Self::SIG_BITS as i16 - 1);
const MAX_SIG: u64 = (1 << Self::SIG_BITS) - 1;
const MIN_SIG: u64 = 1 << (Self::SIG_BITS - 1);

const INFINITY: Self = $crate::$type::INFINITY;
const NAN: Self = $crate::$type::NAN;
const INFINITY: Self = $type::INFINITY;
const NAN: Self = $type::NAN;
const ZERO: Self = 0.0;
};
}
Expand Down
82 changes: 68 additions & 14 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,56 @@ use crate::num::FpCategory;

/// The radix or base of the internal representation of `f32`.
#[stable(feature = "rust1", since = "1.0.0")]
pub const RADIX: u32 = 2;
pub const RADIX: u32 = f32::RADIX;

/// Number of significant digits in base 2.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MANTISSA_DIGITS: u32 = 24;
pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS;
/// Approximate number of significant digits in base 10.
#[stable(feature = "rust1", since = "1.0.0")]
pub const DIGITS: u32 = 6;
pub const DIGITS: u32 = f32::DIGITS;

/// [Machine epsilon] value for `f32`.
///
/// This is the difference between `1.0` and the next larger representable number.
///
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
#[stable(feature = "rust1", since = "1.0.0")]
pub const EPSILON: f32 = 1.1920929e-7_f32;
pub const EPSILON: f32 = f32::EPSILON;

/// Smallest finite `f32` value.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN: f32 = -3.40282347e+38_f32;
pub const MIN: f32 = f32::MIN;
/// Smallest positive normal `f32` value.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32;
pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE;
/// Largest finite `f32` value.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX: f32 = 3.40282347e+38_f32;
pub const MAX: f32 = f32::MAX;

/// One greater than the minimum possible normal power of 2 exponent.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_EXP: i32 = -125;
pub const MIN_EXP: i32 = f32::MIN_EXP;
/// Maximum possible power of 2 exponent.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX_EXP: i32 = 128;
pub const MAX_EXP: i32 = f32::MAX_EXP;

/// Minimum possible normal power of 10 exponent.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_10_EXP: i32 = -37;
pub const MIN_10_EXP: i32 = f32::MIN_10_EXP;
/// Maximum possible power of 10 exponent.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX_10_EXP: i32 = 38;
pub const MAX_10_EXP: i32 = f32::MAX_10_EXP;

/// Not a Number (NaN).
#[stable(feature = "rust1", since = "1.0.0")]
pub const NAN: f32 = 0.0_f32 / 0.0_f32;
pub const NAN: f32 = f32::NAN;
/// Infinity (∞).
#[stable(feature = "rust1", since = "1.0.0")]
pub const INFINITY: f32 = 1.0_f32 / 0.0_f32;
pub const INFINITY: f32 = f32::INFINITY;
/// Negative infinity (−∞).
#[stable(feature = "rust1", since = "1.0.0")]
pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32;
pub const NEG_INFINITY: f32 = f32::NEG_INFINITY;

/// Basic mathematical constants.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -153,6 +153,60 @@ pub mod consts {
#[lang = "f32"]
#[cfg(not(test))]
impl f32 {
/// The radix or base of the internal representation of `f32`.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const RADIX: u32 = 2;

/// Number of significant digits in base 2.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MANTISSA_DIGITS: u32 = 24;

/// Approximate number of significant digits in base 10.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const DIGITS: u32 = 6;

/// [Machine epsilon] value for `f32`.
///
/// This is the difference between `1.0` and the next larger representable number.
///
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const EPSILON: f32 = 1.19209290e-07_f32;

/// Smallest finite `f32` value.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MIN: f32 = -3.40282347e+38_f32;
/// Smallest positive normal `f32` value.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MIN_POSITIVE: f32 = 1.17549435e-38_f32;
/// Largest finite `f32` value.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MAX: f32 = 3.40282347e+38_f32;

/// One greater than the minimum possible normal power of 2 exponent.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MIN_EXP: i32 = -125;
/// Maximum possible power of 2 exponent.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MAX_EXP: i32 = 128;

/// Minimum possible normal power of 10 exponent.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MIN_10_EXP: i32 = -37;
/// Maximum possible power of 10 exponent.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MAX_10_EXP: i32 = 38;

/// Not a Number (NaN).
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const NAN: f32 = 0.0_f32 / 0.0_f32;
/// Infinity (∞).
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const INFINITY: f32 = 1.0_f32 / 0.0_f32;
/// Negative infinity (-∞).
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const NEG_INFINITY: f32 = -1.0_f32 / 0.0_f32;

/// Returns `true` if this value is `NaN`.
///
/// ```
Expand Down
81 changes: 67 additions & 14 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,56 @@ use crate::num::FpCategory;

/// The radix or base of the internal representation of `f64`.
#[stable(feature = "rust1", since = "1.0.0")]
pub const RADIX: u32 = 2;
pub const RADIX: u32 = f64::RADIX;

/// Number of significant digits in base 2.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MANTISSA_DIGITS: u32 = 53;
pub const MANTISSA_DIGITS: u32 = f64::MANTISSA_DIGITS;
/// Approximate number of significant digits in base 10.
#[stable(feature = "rust1", since = "1.0.0")]
pub const DIGITS: u32 = 15;
pub const DIGITS: u32 = f64::DIGITS;

/// [Machine epsilon] value for `f64`.
///
/// This is the difference between `1.0` and the next larger representable number.
///
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
#[stable(feature = "rust1", since = "1.0.0")]
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
pub const EPSILON: f64 = f64::EPSILON;

/// Smallest finite `f64` value.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN: f64 = -1.7976931348623157e+308_f64;
pub const MIN: f64 = f64::MIN;
/// Smallest positive normal `f64` value.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64;
pub const MIN_POSITIVE: f64 = f64::MIN_POSITIVE;
/// Largest finite `f64` value.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX: f64 = 1.7976931348623157e+308_f64;
pub const MAX: f64 = f64::MAX;

/// One greater than the minimum possible normal power of 2 exponent.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_EXP: i32 = -1021;
pub const MIN_EXP: i32 = f64::MIN_EXP;
/// Maximum possible power of 2 exponent.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX_EXP: i32 = 1024;
pub const MAX_EXP: i32 = f64::MAX_EXP;

/// Minimum possible normal power of 10 exponent.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MIN_10_EXP: i32 = -307;
pub const MIN_10_EXP: i32 = f64::MIN_10_EXP;
/// Maximum possible power of 10 exponent.
#[stable(feature = "rust1", since = "1.0.0")]
pub const MAX_10_EXP: i32 = 308;
pub const MAX_10_EXP: i32 = f64::MAX_10_EXP;

/// Not a Number (NaN).
#[stable(feature = "rust1", since = "1.0.0")]
pub const NAN: f64 = 0.0_f64 / 0.0_f64;
pub const NAN: f64 = f64::NAN;
/// Infinity (∞).
#[stable(feature = "rust1", since = "1.0.0")]
pub const INFINITY: f64 = 1.0_f64 / 0.0_f64;
pub const INFINITY: f64 = f64::INFINITY;
/// Negative infinity (−∞).
#[stable(feature = "rust1", since = "1.0.0")]
pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64;
pub const NEG_INFINITY: f64 = f64::NEG_INFINITY;

/// Basic mathematical constants.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -153,6 +153,59 @@ pub mod consts {
#[lang = "f64"]
#[cfg(not(test))]
impl f64 {
/// The radix or base of the internal representation of `f64`.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const RADIX: u32 = 2;

/// Number of significant digits in base 2.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MANTISSA_DIGITS: u32 = 53;
/// Approximate number of significant digits in base 10.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const DIGITS: u32 = 15;

/// [Machine epsilon] value for `f64`.
///
/// This is the difference between `1.0` and the next larger representable number.
///
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;

/// Smallest finite `f64` value.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MIN: f64 = -1.7976931348623157e+308_f64;
/// Smallest positive normal `f64` value.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MIN_POSITIVE: f64 = 2.2250738585072014e-308_f64;
/// Largest finite `f64` value.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MAX: f64 = 1.7976931348623157e+308_f64;

/// One greater than the minimum possible normal power of 2 exponent.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MIN_EXP: i32 = -1021;
/// Maximum possible power of 2 exponent.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MAX_EXP: i32 = 1024;

/// Minimum possible normal power of 10 exponent.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MIN_10_EXP: i32 = -307;
/// Maximum possible power of 10 exponent.
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const MAX_10_EXP: i32 = 308;

/// Not a Number (NaN).
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const NAN: f64 = 0.0_f64 / 0.0_f64;
/// Infinity (∞).
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const INFINITY: f64 = 1.0_f64 / 0.0_f64;
/// Negative infinity (-∞).
#[unstable(feature = "assoc_int_consts", reason = "recently added", issue = "68490")]
pub const NEG_INFINITY: f64 = -1.0_f64 / 0.0_f64;

/// Returns `true` if this value is `NaN`.
///
/// ```
Expand Down
Loading

0 comments on commit c4071d0

Please sign in to comment.