Skip to content

Commit

Permalink
Add relevant associated constants to the float types
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Jan 23, 2020
1 parent b5ff806 commit 22dcfa1
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 28 deletions.
82 changes: 68 additions & 14 deletions src/libcore/num/f32.rs
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
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

0 comments on commit 22dcfa1

Please sign in to comment.