@@ -15,13 +15,204 @@ use crate::mem;
1515
1616/// Basic mathematical constants.
1717#[ unstable( feature = "f128" , issue = "116909" ) ]
18- pub mod consts { }
18+ pub mod consts {
19+ // FIXME: replace with mathematical constants from cmath.
20+
21+ /// Archimedes' constant (π)
22+ #[ unstable( feature = "f128" , issue = "116909" ) ]
23+ pub const PI : f128 = 3.14159265358979323846264338327950288419716939937510582097494_f128 ;
24+
25+ /// The full circle constant (τ)
26+ ///
27+ /// Equal to 2π.
28+ #[ unstable( feature = "f128" , issue = "116909" ) ]
29+ pub const TAU : f128 = 6.28318530717958647692528676655900576839433879875021164194989_f128 ;
30+
31+ /// The golden ratio (φ)
32+ #[ unstable( feature = "f128" , issue = "116909" ) ]
33+ // Also, #[unstable(feature = "more_float_constants", issue = "103883")]
34+ pub const PHI : f128 = 1.61803398874989484820458683436563811772030917980576286213545_f128 ;
35+
36+ /// The Euler-Mascheroni constant (γ)
37+ #[ unstable( feature = "f128" , issue = "116909" ) ]
38+ // Also, #[unstable(feature = "more_float_constants", issue = "103883")]
39+ pub const EGAMMA : f128 = 0.577215664901532860606512090082402431042159335939923598805767_f128 ;
40+
41+ /// π/2
42+ #[ unstable( feature = "f128" , issue = "116909" ) ]
43+ pub const FRAC_PI_2 : f128 = 1.57079632679489661923132169163975144209858469968755291048747_f128 ;
44+
45+ /// π/3
46+ #[ unstable( feature = "f128" , issue = "116909" ) ]
47+ pub const FRAC_PI_3 : f128 = 1.04719755119659774615421446109316762806572313312503527365831_f128 ;
48+
49+ /// π/4
50+ #[ unstable( feature = "f128" , issue = "116909" ) ]
51+ pub const FRAC_PI_4 : f128 = 0.785398163397448309615660845819875721049292349843776455243736_f128 ;
52+
53+ /// π/6
54+ #[ unstable( feature = "f128" , issue = "116909" ) ]
55+ pub const FRAC_PI_6 : f128 = 0.523598775598298873077107230546583814032861566562517636829157_f128 ;
56+
57+ /// π/8
58+ #[ unstable( feature = "f128" , issue = "116909" ) ]
59+ pub const FRAC_PI_8 : f128 = 0.392699081698724154807830422909937860524646174921888227621868_f128 ;
60+
61+ /// 1/π
62+ #[ unstable( feature = "f128" , issue = "116909" ) ]
63+ pub const FRAC_1_PI : f128 = 0.318309886183790671537767526745028724068919291480912897495335_f128 ;
64+
65+ /// 1/sqrt(π)
66+ #[ unstable( feature = "f128" , issue = "116909" ) ]
67+ // Also, #[unstable(feature = "more_float_constants", issue = "103883")]
68+ pub const FRAC_1_SQRT_PI : f128 =
69+ 0.564189583547756286948079451560772585844050629328998856844086_f128 ;
70+
71+ /// 2/π
72+ #[ unstable( feature = "f128" , issue = "116909" ) ]
73+ pub const FRAC_2_PI : f128 = 0.636619772367581343075535053490057448137838582961825794990669_f128 ;
74+
75+ /// 2/sqrt(π)
76+ #[ unstable( feature = "f128" , issue = "116909" ) ]
77+ pub const FRAC_2_SQRT_PI : f128 =
78+ 1.12837916709551257389615890312154517168810125865799771368817_f128 ;
79+
80+ /// sqrt(2)
81+ #[ unstable( feature = "f128" , issue = "116909" ) ]
82+ pub const SQRT_2 : f128 = 1.41421356237309504880168872420969807856967187537694807317668_f128 ;
83+
84+ /// 1/sqrt(2)
85+ #[ unstable( feature = "f128" , issue = "116909" ) ]
86+ pub const FRAC_1_SQRT_2 : f128 =
87+ 0.707106781186547524400844362104849039284835937688474036588340_f128 ;
88+
89+ /// sqrt(3)
90+ #[ unstable( feature = "f128" , issue = "116909" ) ]
91+ // Also, #[unstable(feature = "more_float_constants", issue = "103883")]
92+ pub const SQRT_3 : f128 = 1.73205080756887729352744634150587236694280525381038062805581_f128 ;
93+
94+ /// 1/sqrt(3)
95+ #[ unstable( feature = "f128" , issue = "116909" ) ]
96+ // Also, #[unstable(feature = "more_float_constants", issue = "103883")]
97+ pub const FRAC_1_SQRT_3 : f128 =
98+ 0.577350269189625764509148780501957455647601751270126876018602_f128 ;
99+
100+ /// Euler's number (e)
101+ #[ unstable( feature = "f128" , issue = "116909" ) ]
102+ pub const E : f128 = 2.71828182845904523536028747135266249775724709369995957496697_f128 ;
103+
104+ /// log<sub>2</sub>(10)
105+ #[ unstable( feature = "f128" , issue = "116909" ) ]
106+ pub const LOG2_10 : f128 = 3.32192809488736234787031942948939017586483139302458061205476_f128 ;
107+
108+ /// log<sub>2</sub>(e)
109+ #[ unstable( feature = "f128" , issue = "116909" ) ]
110+ pub const LOG2_E : f128 = 1.44269504088896340735992468100189213742664595415298593413545_f128 ;
111+
112+ /// log<sub>10</sub>(2)
113+ #[ unstable( feature = "f128" , issue = "116909" ) ]
114+ pub const LOG10_2 : f128 = 0.301029995663981195213738894724493026768189881462108541310427_f128 ;
115+
116+ /// log<sub>10</sub>(e)
117+ #[ unstable( feature = "f128" , issue = "116909" ) ]
118+ pub const LOG10_E : f128 = 0.434294481903251827651128918916605082294397005803666566114454_f128 ;
119+
120+ /// ln(2)
121+ #[ unstable( feature = "f128" , issue = "116909" ) ]
122+ pub const LN_2 : f128 = 0.693147180559945309417232121458176568075500134360255254120680_f128 ;
123+
124+ /// ln(10)
125+ #[ unstable( feature = "f128" , issue = "116909" ) ]
126+ pub const LN_10 : f128 = 2.30258509299404568401799145468436420760110148862877297603333_f128 ;
127+ }
19128
20129#[ cfg( not( test) ) ]
21130impl f128 {
22- // FIXME(f16_f128): almost everything in this `impl` is missing examples and a const
131+ // FIXME(f16_f128): almost all methods in this `impl` are missing examples and a const
23132 // implementation. Add these once we can run code on all platforms and have f16/f128 in CTFE.
24133
134+ /// The radix or base of the internal representation of `f128`.
135+ #[ unstable( feature = "f128" , issue = "116909" ) ]
136+ pub const RADIX : u32 = 2 ;
137+
138+ /// Number of significant digits in base 2.
139+ #[ unstable( feature = "f128" , issue = "116909" ) ]
140+ pub const MANTISSA_DIGITS : u32 = 113 ;
141+
142+ /// Approximate number of significant digits in base 10.
143+ ///
144+ /// This is the maximum <i>x</i> such that any decimal number with <i>x</i>
145+ /// significant digits can be converted to `f128` and back without loss.
146+ ///
147+ /// Equal to floor(log<sub>10</sub> 2<sup>[`MANTISSA_DIGITS`] − 1</sup>).
148+ ///
149+ /// [`MANTISSA_DIGITS`]: f128::MANTISSA_DIGITS
150+ #[ unstable( feature = "f128" , issue = "116909" ) ]
151+ pub const DIGITS : u32 = 33 ;
152+
153+ /// [Machine epsilon] value for `f128`.
154+ ///
155+ /// This is the difference between `1.0` and the next larger representable number.
156+ ///
157+ /// Equal to 2<sup>1 − [`MANTISSA_DIGITS`]</sup>.
158+ ///
159+ /// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
160+ /// [`MANTISSA_DIGITS`]: f128::MANTISSA_DIGITS
161+ #[ unstable( feature = "f128" , issue = "116909" ) ]
162+ pub const EPSILON : f128 = 1.92592994438723585305597794258492731e-34_f128 ;
163+
164+ /// Smallest finite `f128` value.
165+ ///
166+ /// Equal to −[`MAX`].
167+ ///
168+ /// [`MAX`]: f128::MAX
169+ #[ unstable( feature = "f128" , issue = "116909" ) ]
170+ pub const MIN : f128 = -1.18973149535723176508575932662800701e+4932_f128 ;
171+ /// Smallest positive normal `f128` value.
172+ ///
173+ /// Equal to 2<sup>[`MIN_EXP`] − 1</sup>.
174+ ///
175+ /// [`MIN_EXP`]: f128::MIN_EXP
176+ #[ unstable( feature = "f128" , issue = "116909" ) ]
177+ pub const MIN_POSITIVE : f128 = 3.36210314311209350626267781732175260e-4932_f128 ;
178+ /// Largest finite `f128` value.
179+ ///
180+ /// Equal to
181+ /// (1 − 2<sup>−[`MANTISSA_DIGITS`]</sup>) 2<sup>[`MAX_EXP`]</sup>.
182+ ///
183+ /// [`MANTISSA_DIGITS`]: f128::MANTISSA_DIGITS
184+ /// [`MAX_EXP`]: f128::MAX_EXP
185+ #[ unstable( feature = "f128" , issue = "116909" ) ]
186+ pub const MAX : f128 = 1.18973149535723176508575932662800701e+4932_f128 ;
187+
188+ /// One greater than the minimum possible normal power of 2 exponent.
189+ ///
190+ /// If <i>x</i> = `MIN_EXP`, then normal numbers
191+ /// ≥ 0.5 × 2<sup><i>x</i></sup>.
192+ #[ unstable( feature = "f128" , issue = "116909" ) ]
193+ pub const MIN_EXP : i32 = -16_381 ;
194+ /// Maximum possible power of 2 exponent.
195+ ///
196+ /// If <i>x</i> = `MAX_EXP`, then normal numbers
197+ /// < 1 × 2<sup><i>x</i></sup>.
198+ #[ unstable( feature = "f128" , issue = "116909" ) ]
199+ pub const MAX_EXP : i32 = 16_384 ;
200+
201+ /// Minimum <i>x</i> for which 10<sup><i>x</i></sup> is normal.
202+ ///
203+ /// Equal to ceil(log<sub>10</sub> [`MIN_POSITIVE`]).
204+ ///
205+ /// [`MIN_POSITIVE`]: f128::MIN_POSITIVE
206+ #[ unstable( feature = "f128" , issue = "116909" ) ]
207+ pub const MIN_10_EXP : i32 = -4_931 ;
208+ /// Maximum <i>x</i> for which 10<sup><i>x</i></sup> is normal.
209+ ///
210+ /// Equal to floor(log<sub>10</sub> [`MAX`]).
211+ ///
212+ /// [`MAX`]: f128::MAX
213+ #[ unstable( feature = "f128" , issue = "116909" ) ]
214+ pub const MAX_10_EXP : i32 = 4_932 ;
215+
25216 /// Returns `true` if this value is NaN.
26217 #[ inline]
27218 #[ must_use]
0 commit comments