|
| 1 | +//! Constants for the `f128` quadruple-precision floating point type. |
| 2 | +//! |
| 3 | +//! *[See also the `f128` primitive type][f128].* |
| 4 | +//! |
| 5 | +//! Mathematically significant numbers are provided in the `consts` sub-module. |
| 6 | +//! |
| 7 | +//! For the constants defined directly in this module |
| 8 | +//! (as distinct from those defined in the `consts` sub-module), |
| 9 | +//! new code should instead use the associated constants |
| 10 | +//! defined directly on the `f128` type. |
| 11 | +
|
| 12 | +#![unstable(feature = "f128", issue = "116909")] |
| 13 | + |
| 14 | +/// Basic mathematical constants. |
| 15 | +#[unstable(feature = "f128", issue = "116909")] |
| 16 | +pub mod consts { |
| 17 | + /// Archimedes' constant (π) |
| 18 | + #[unstable(feature = "f128", issue = "116909")] |
| 19 | + pub const PI: f128 = 3.14159265358979323846264338327950288419716939937510582097494_f128; |
| 20 | + |
| 21 | + /// The full circle constant (τ) |
| 22 | + /// |
| 23 | + /// Equal to 2π. |
| 24 | + #[unstable(feature = "f128", issue = "116909")] |
| 25 | + pub const TAU: f128 = 6.28318530717958647692528676655900576839433879875021164194989_f128; |
| 26 | + |
| 27 | + /// The golden ratio (φ) |
| 28 | + #[unstable(feature = "more_float_constants", issue = "103883")] |
| 29 | + pub const PHI: f128 = 1.61803398874989484820458683436563811772030917980576286213545_f128; |
| 30 | + |
| 31 | + /// The Euler-Mascheroni constant (γ) |
| 32 | + #[unstable(feature = "more_float_constants", issue = "103883")] |
| 33 | + pub const EGAMMA: f128 = 0.577215664901532860606512090082402431042159335939923598805767_f128; |
| 34 | + |
| 35 | + /// π/2 |
| 36 | + #[unstable(feature = "f128", issue = "116909")] |
| 37 | + pub const FRAC_PI_2: f128 = 1.57079632679489661923132169163975144209858469968755291048747_f128; |
| 38 | + |
| 39 | + /// π/3 |
| 40 | + #[unstable(feature = "f128", issue = "116909")] |
| 41 | + pub const FRAC_PI_3: f128 = 1.04719755119659774615421446109316762806572313312503527365831_f128; |
| 42 | + |
| 43 | + /// π/4 |
| 44 | + #[unstable(feature = "f128", issue = "116909")] |
| 45 | + pub const FRAC_PI_4: f128 = 0.785398163397448309615660845819875721049292349843776455243736_f128; |
| 46 | + |
| 47 | + /// π/6 |
| 48 | + #[unstable(feature = "f128", issue = "116909")] |
| 49 | + pub const FRAC_PI_6: f128 = 0.523598775598298873077107230546583814032861566562517636829157_f128; |
| 50 | + |
| 51 | + /// π/8 |
| 52 | + #[unstable(feature = "f128", issue = "116909")] |
| 53 | + pub const FRAC_PI_8: f128 = 0.392699081698724154807830422909937860524646174921888227621868_f128; |
| 54 | + |
| 55 | + /// 1/π |
| 56 | + #[unstable(feature = "f128", issue = "116909")] |
| 57 | + pub const FRAC_1_PI: f128 = 0.318309886183790671537767526745028724068919291480912897495335_f128; |
| 58 | + |
| 59 | + /// 1/sqrt(π) |
| 60 | + #[unstable(feature = "more_float_constants", issue = "103883")] |
| 61 | + pub const FRAC_1_SQRT_PI: f128 = |
| 62 | + 0.564189583547756286948079451560772585844050629328998856844085_f128; |
| 63 | + |
| 64 | + /// 2/π |
| 65 | + #[unstable(feature = "f128", issue = "116909")] |
| 66 | + pub const FRAC_2_PI: f128 = 0.636619772367581343075535053490057448137838582961825794990669_f128; |
| 67 | + |
| 68 | + /// 2/sqrt(π) |
| 69 | + #[unstable(feature = "f128", issue = "116909")] |
| 70 | + pub const FRAC_2_SQRT_PI: f128 = |
| 71 | + 1.12837916709551257389615890312154517168810125865799771368817_f128; |
| 72 | + |
| 73 | + /// sqrt(2) |
| 74 | + #[unstable(feature = "f128", issue = "116909")] |
| 75 | + pub const SQRT_2: f128 = 1.41421356237309504880168872420969807856967187537694807317668_f128; |
| 76 | + |
| 77 | + /// 1/sqrt(2) |
| 78 | + #[unstable(feature = "f128", issue = "116909")] |
| 79 | + pub const FRAC_1_SQRT_2: f128 = |
| 80 | + 0.70710678118654752440084436210484903928483593768847403658834_f128; |
| 81 | + |
| 82 | + /// sqrt(3) |
| 83 | + #[unstable(feature = "more_float_constants", issue = "103883")] |
| 84 | + pub const SQRT_3: f128 = 1.732050807568877293527446341505872366942805253810380628055807_f128; |
| 85 | + /// 1/sqrt(3) |
| 86 | + #[unstable(feature = "more_float_constants", issue = "103883")] |
| 87 | + pub const FRAC_1_SQRT_3: f128 = |
| 88 | + 0.577350269189625764509148780501957455647601751270126876018602_f128; |
| 89 | + |
| 90 | + /// Euler's number (e) |
| 91 | + #[unstable(feature = "f128", issue = "116909")] |
| 92 | + pub const E: f128 = 2.71828182845904523536028747135266249775724709369995957496697_f128; |
| 93 | + |
| 94 | + /// log<sub>2</sub>(10) |
| 95 | + #[unstable(feature = "f128", issue = "116909")] |
| 96 | + pub const LOG2_10: f128 = 3.32192809488736234787031942948939017586483139302458061205476_f128; |
| 97 | + |
| 98 | + /// log<sub>2</sub>(e) |
| 99 | + #[unstable(feature = "f128", issue = "116909")] |
| 100 | + pub const LOG2_E: f128 = 1.44269504088896340735992468100189213742664595415298593413545_f128; |
| 101 | + |
| 102 | + /// log<sub>10</sub>(2) |
| 103 | + #[unstable(feature = "f128", issue = "116909")] |
| 104 | + pub const LOG10_2: f128 = 0.301029995663981195213738894724493026768189881462108541310427_f128; |
| 105 | + |
| 106 | + /// log<sub>10</sub>(e) |
| 107 | + #[unstable(feature = "f128", issue = "116909")] |
| 108 | + pub const LOG10_E: f128 = 0.434294481903251827651128918916605082294397005803666566114454_f128; |
| 109 | + |
| 110 | + /// ln(2) |
| 111 | + #[unstable(feature = "f128", issue = "116909")] |
| 112 | + pub const LN_2: f128 = 0.69314718055994530941723212145817656807550013436025525412068_f128; |
| 113 | + |
| 114 | + /// ln(10) |
| 115 | + #[unstable(feature = "f128", issue = "116909")] |
| 116 | + pub const LN_10: f128 = 2.30258509299404568401799145468436420760110148862877297603333_f128; |
| 117 | +} |
| 118 | + |
| 119 | +#[cfg(not(test))] |
| 120 | +impl f128 { |
| 121 | + /// The radix or base of the internal representation of `f128`. |
| 122 | + #[unstable(feature = "f128", issue = "116909")] |
| 123 | + pub const RADIX: u32 = 128; |
| 124 | + |
| 125 | + /// Number of significant digits in base 2. |
| 126 | + #[unstable(feature = "f128", issue = "116909")] |
| 127 | + pub const MANTISSA_DIGITS: u32 = 112; |
| 128 | + |
| 129 | + /// Approximate number of significant digits in base 10. |
| 130 | + /// |
| 131 | + /// This is the maximum _x_ such that any decimal number with _x_ |
| 132 | + /// significant digits can be converted to `f32` and back without loss. |
| 133 | + /// |
| 134 | + /// Equal to floor(log<sub>10</sub> 2<sup>[`MANTISSA_DIGITS`] − 1</sup>). |
| 135 | + #[unstable(feature = "f128", issue = "116909")] |
| 136 | + pub const DIGITS: u32 = 33; |
| 137 | + |
| 138 | + /// [Machine epsilon] value for `f128`. |
| 139 | + /// |
| 140 | + /// This is the difference between `1.0` and the next larger representable number. |
| 141 | + /// |
| 142 | + /// Equal to 2<sup>1 − [`MANTISSA_DIGITS`]</sup>. |
| 143 | + /// |
| 144 | + /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon |
| 145 | + #[unstable(feature = "f128", issue = "116909")] |
| 146 | + pub const EPSILON: f128 = 1.92592994438723585305597794258492732e-34_f128; |
| 147 | + |
| 148 | + /// Smallest finite `f128` value. |
| 149 | + /// |
| 150 | + /// Equal to −[`MAX`]. |
| 151 | + #[cfg(not(bootstrap))] |
| 152 | + #[unstable(feature = "f128", issue = "116909")] |
| 153 | + pub const MIN: f128 = -1.1897314953572317650857593266280070162e+4932_f128; |
| 154 | + |
| 155 | + /// Smallest positive normal `f128` value. |
| 156 | + /// |
| 157 | + /// Equal to 2<sup>[`MIN_EXP`] − 1</sup>. |
| 158 | + #[unstable(feature = "f128", issue = "116909")] |
| 159 | + pub const MIN_POSITIVE: f128 = 3.3621031431120935062626778173217526E-4932_f128; |
| 160 | + |
| 161 | + /// Largest finite `f128` value. |
| 162 | + /// |
| 163 | + /// Equal to |
| 164 | + /// (1 − 2<sup>−[`MANTISSA_DIGITS`]</sup>) 2<sup>[`MAX_EXP`]</sup>. |
| 165 | + #[unstable(feature = "f128", issue = "116909")] |
| 166 | + pub const MAX: f128 = 1.1897314953572317650857593266280070162e+4932_f128; |
| 167 | + |
| 168 | + /// One greater than the minimum possible normal power of 2 exponent. |
| 169 | + /// |
| 170 | + /// If <i>x</i> = `MIN_EXP`, then normal numbers |
| 171 | + /// ≥ 0.5 × 2<sup><i>x</i></sup>. |
| 172 | + #[unstable(feature = "f128", issue = "116909")] |
| 173 | + pub const MIN_EXP: i32 = -16381; |
| 174 | + |
| 175 | + /// Maximum possible power of 2 exponent. |
| 176 | + /// |
| 177 | + /// If <i>x</i> = `MAX_EXP`, then normal numbers |
| 178 | + /// < 1 × 2<sup><i>x</i></sup>. |
| 179 | + #[unstable(feature = "f128", issue = "116909")] |
| 180 | + pub const MAX_EXP: i32 = 16384; |
| 181 | + |
| 182 | + /// Minimum possible normal power of 10 exponent. |
| 183 | + /// |
| 184 | + /// Equal to ceil(log<sub>10</sub> [`MIN_POSITIVE`]). |
| 185 | + #[unstable(feature = "f128", issue = "116909")] |
| 186 | + pub const MIN_10_EXP: i32 = -4931; |
| 187 | + |
| 188 | + /// Maximum possible power of 10 exponent. |
| 189 | + /// |
| 190 | + /// Equal to floor(log<sub>10</sub> [`MAX`]). |
| 191 | + #[unstable(feature = "f128", issue = "116909")] |
| 192 | + pub const MAX_10_EXP: i32 = 4932; |
| 193 | + |
| 194 | + /// Not a Number (NaN). |
| 195 | + /// |
| 196 | + /// Note that IEEE 754 doesn't define just a single NaN value; |
| 197 | + /// a plethora of bit patterns are considered to be NaN. |
| 198 | + /// Furthermore, the standard makes a difference |
| 199 | + /// between a "signaling" and a "quiet" NaN, |
| 200 | + /// and allows inspecting its "payload" (the unspecified bits in the bit pattern). |
| 201 | + /// This constant isn't guaranteed to equal to any specific NaN bitpattern, |
| 202 | + /// and the stability of its representation over Rust versions |
| 203 | + /// and target platforms isn't guaranteed. |
| 204 | + #[cfg(not(bootstrap))] |
| 205 | + #[rustc_diagnostic_item = "f128_nan"] |
| 206 | + #[unstable(feature = "f128", issue = "116909")] |
| 207 | + pub const NAN: f128 = 0.0_f128 / 0.0_f128; |
| 208 | + |
| 209 | + /// Infinity (∞). |
| 210 | + #[cfg(not(bootstrap))] |
| 211 | + #[unstable(feature = "f128", issue = "116909")] |
| 212 | + pub const INFINITY: f128 = 1.0_f128 / 0.0_f128; |
| 213 | + |
| 214 | + /// Negative infinity (−∞). |
| 215 | + #[cfg(not(bootstrap))] |
| 216 | + #[unstable(feature = "f128", issue = "116909")] |
| 217 | + pub const NEG_INFINITY: f128 = -1.0_f128 / 0.0_f128; |
| 218 | +} |
0 commit comments