Skip to content

Commit 96f6b0b

Browse files
committed
add f128 associated constants
NaN and infinity are not included as they require arithmetic.
1 parent f679a9e commit 96f6b0b

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

library/core/src/num/f128.rs

+83-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,91 @@ pub mod consts {}
1919

2020
#[cfg(not(test))]
2121
impl f128 {
22-
// FIXME(f16_f128): almost everything in this `impl` is missing examples and a const
22+
// FIXME(f16_f128): almost all methods in this `impl` are missing examples and a const
2323
// implementation. Add these once we can run code on all platforms and have f16/f128 in CTFE.
2424

25+
/// The radix or base of the internal representation of `f128`.
26+
#[unstable(feature = "f128", issue = "116909")]
27+
pub const RADIX: u32 = 2;
28+
29+
/// Number of significant digits in base 2.
30+
#[unstable(feature = "f128", issue = "116909")]
31+
pub const MANTISSA_DIGITS: u32 = 113;
32+
33+
/// Approximate number of significant digits in base 10.
34+
///
35+
/// This is the maximum <i>x</i> such that any decimal number with <i>x</i>
36+
/// significant digits can be converted to `f128` and back without loss.
37+
///
38+
/// Equal to floor(log<sub>10</sub>&nbsp;2<sup>[`MANTISSA_DIGITS`]&nbsp;&minus;&nbsp;1</sup>).
39+
///
40+
/// [`MANTISSA_DIGITS`]: f128::MANTISSA_DIGITS
41+
#[unstable(feature = "f128", issue = "116909")]
42+
pub const DIGITS: u32 = 33;
43+
44+
/// [Machine epsilon] value for `f128`.
45+
///
46+
/// This is the difference between `1.0` and the next larger representable number.
47+
///
48+
/// Equal to 2<sup>1&nbsp;&minus;&nbsp;[`MANTISSA_DIGITS`]</sup>.
49+
///
50+
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
51+
/// [`MANTISSA_DIGITS`]: f128::MANTISSA_DIGITS
52+
#[unstable(feature = "f128", issue = "116909")]
53+
pub const EPSILON: f128 = 1.92592994438723585305597794258492731e-34_f128;
54+
55+
/// Smallest finite `f128` value.
56+
///
57+
/// Equal to &minus;[`MAX`].
58+
///
59+
/// [`MAX`]: f128::MAX
60+
#[unstable(feature = "f128", issue = "116909")]
61+
pub const MIN: f128 = -1.18973149535723176508575932662800701e+4932_f128;
62+
/// Smallest positive normal `f128` value.
63+
///
64+
/// Equal to 2<sup>[`MIN_EXP`]&nbsp;&minus;&nbsp;1</sup>.
65+
///
66+
/// [`MIN_EXP`]: f128::MIN_EXP
67+
#[unstable(feature = "f128", issue = "116909")]
68+
pub const MIN_POSITIVE: f128 = 3.36210314311209350626267781732175260e-4932_f128;
69+
/// Largest finite `f128` value.
70+
///
71+
/// Equal to
72+
/// (1&nbsp;&minus;&nbsp;2<sup>&minus;[`MANTISSA_DIGITS`]</sup>)&nbsp;2<sup>[`MAX_EXP`]</sup>.
73+
///
74+
/// [`MANTISSA_DIGITS`]: f128::MANTISSA_DIGITS
75+
/// [`MAX_EXP`]: f128::MAX_EXP
76+
#[unstable(feature = "f128", issue = "116909")]
77+
pub const MAX: f128 = 1.18973149535723176508575932662800701e+4932_f128;
78+
79+
/// One greater than the minimum possible normal power of 2 exponent.
80+
///
81+
/// If <i>x</i>&nbsp;=&nbsp;`MIN_EXP`, then normal numbers
82+
/// ≥&nbsp;0.5&nbsp;×&nbsp;2<sup><i>x</i></sup>.
83+
#[unstable(feature = "f128", issue = "116909")]
84+
pub const MIN_EXP: i32 = -16_381;
85+
/// Maximum possible power of 2 exponent.
86+
///
87+
/// If <i>x</i>&nbsp;=&nbsp;`MAX_EXP`, then normal numbers
88+
/// &lt;&nbsp;1&nbsp;×&nbsp;2<sup><i>x</i></sup>.
89+
#[unstable(feature = "f128", issue = "116909")]
90+
pub const MAX_EXP: i32 = 16_384;
91+
92+
/// Minimum <i>x</i> for which 10<sup><i>x</i></sup> is normal.
93+
///
94+
/// Equal to ceil(log<sub>10</sub>&nbsp;[`MIN_POSITIVE`]).
95+
///
96+
/// [`MIN_POSITIVE`]: f128::MIN_POSITIVE
97+
#[unstable(feature = "f128", issue = "116909")]
98+
pub const MIN_10_EXP: i32 = -4_931;
99+
/// Maximum <i>x</i> for which 10<sup><i>x</i></sup> is normal.
100+
///
101+
/// Equal to floor(log<sub>10</sub>&nbsp;[`MAX`]).
102+
///
103+
/// [`MAX`]: f128::MAX
104+
#[unstable(feature = "f128", issue = "116909")]
105+
pub const MAX_10_EXP: i32 = 4_932;
106+
25107
/// Returns `true` if this value is NaN.
26108
#[inline]
27109
#[must_use]

0 commit comments

Comments
 (0)