Skip to content

Commit beb75d8

Browse files
committed
The core::num methods are now inherent methods of f32
See rust-lang/rust#49896
1 parent 6d546c1 commit beb75d8

File tree

1 file changed

+1
-189
lines changed

1 file changed

+1
-189
lines changed

src/float_impls.rs

Lines changed: 1 addition & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
use core::{num, intrinsics};
1+
use core::intrinsics;
22
use core::f32::{NAN, NEG_INFINITY};
33

44
pub trait FloatImpls {
5-
fn is_nan(self) -> bool;
6-
fn is_infinite(self) -> bool;
7-
fn is_finite(self) -> bool;
8-
fn is_normal(self) -> bool;
95
fn floor(self) -> f32;
106
fn ceil(self) -> f32;
117
fn round(self) -> f32;
128
fn trunc(self) -> f32;
139
fn fract(self) -> f32;
14-
fn signum(self) -> f32;
15-
fn is_sign_positive(self) -> bool;
16-
fn is_sign_negative(self) -> bool;
1710
fn mul_add(self, a: f32, b: f32) -> f32;
18-
fn powi(self, n: i32) -> f32;
1911
fn powf(self, n: f32) -> f32;
2012
fn sqrt(self) -> f32;
2113
fn exp(self) -> f32;
@@ -24,99 +16,13 @@ pub trait FloatImpls {
2416
fn log(self, base: f32) -> f32;
2517
fn log2(self) -> f32;
2618
fn log10(self) -> f32;
27-
fn to_degrees(self) -> f32;
2819
fn max(self, other: f32) -> f32;
2920
fn min(self, other: f32) -> f32;
3021
fn asinh(self) -> f32;
3122
fn acosh(self) -> f32;
3223
}
3324

3425
impl FloatImpls for f32 {
35-
/// Returns `true` if this value is `NaN` and false otherwise.
36-
///
37-
/// ```
38-
/// use std::f32;
39-
///
40-
/// let nan = f32::NAN;
41-
/// let f = 7.0_f32;
42-
///
43-
/// assert!(nan.is_nan());
44-
/// assert!(!f.is_nan());
45-
/// ```
46-
#[inline]
47-
fn is_nan(self) -> bool {
48-
num::Float::is_nan(self)
49-
}
50-
51-
/// Returns `true` if this value is positive infinity or negative infinity and
52-
/// false otherwise.
53-
///
54-
/// ```
55-
/// use std::f32;
56-
///
57-
/// let f = 7.0f32;
58-
/// let inf = f32::INFINITY;
59-
/// let neg_inf = f32::NEG_INFINITY;
60-
/// let nan = f32::NAN;
61-
///
62-
/// assert!(!f.is_infinite());
63-
/// assert!(!nan.is_infinite());
64-
///
65-
/// assert!(inf.is_infinite());
66-
/// assert!(neg_inf.is_infinite());
67-
/// ```
68-
#[inline]
69-
fn is_infinite(self) -> bool {
70-
num::Float::is_infinite(self)
71-
}
72-
73-
/// Returns `true` if this number is neither infinite nor `NaN`.
74-
///
75-
/// ```
76-
/// use std::f32;
77-
///
78-
/// let f = 7.0f32;
79-
/// let inf = f32::INFINITY;
80-
/// let neg_inf = f32::NEG_INFINITY;
81-
/// let nan = f32::NAN;
82-
///
83-
/// assert!(f.is_finite());
84-
///
85-
/// assert!(!nan.is_finite());
86-
/// assert!(!inf.is_finite());
87-
/// assert!(!neg_inf.is_finite());
88-
/// ```
89-
#[inline]
90-
fn is_finite(self) -> bool {
91-
num::Float::is_finite(self)
92-
}
93-
94-
/// Returns `true` if the number is neither zero, infinite,
95-
/// [subnormal][subnormal], or `NaN`.
96-
///
97-
/// ```
98-
/// use std::f32;
99-
///
100-
/// let min = f32::MIN_POSITIVE; // 1.17549435e-38f32
101-
/// let max = f32::MAX;
102-
/// let lower_than_min = 1.0e-40_f32;
103-
/// let zero = 0.0_f32;
104-
///
105-
/// assert!(min.is_normal());
106-
/// assert!(max.is_normal());
107-
///
108-
/// assert!(!zero.is_normal());
109-
/// assert!(!f32::NAN.is_normal());
110-
/// assert!(!f32::INFINITY.is_normal());
111-
/// // Values between `0` and `min` are Subnormal.
112-
/// assert!(!lower_than_min.is_normal());
113-
/// ```
114-
/// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
115-
#[inline]
116-
fn is_normal(self) -> bool {
117-
num::Float::is_normal(self)
118-
}
119-
12026
/// Returns the largest integer less than or equal to a number.
12127
///
12228
/// ```
@@ -215,67 +121,6 @@ impl FloatImpls for f32 {
215121
self - self.trunc()
216122
}
217123

218-
/// Returns a number that represents the sign of `self`.
219-
///
220-
/// - `1.0` if the number is positive, `+0.0` or `INFINITY`
221-
/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
222-
/// - `NAN` if the number is `NAN`
223-
///
224-
/// ```
225-
/// use std::f32;
226-
///
227-
/// let f = 3.5_f32;
228-
///
229-
/// assert_eq!(f.signum(), 1.0);
230-
/// assert_eq!(f32::NEG_INFINITY.signum(), -1.0);
231-
///
232-
/// assert!(f32::NAN.signum().is_nan());
233-
/// ```
234-
#[inline]
235-
fn signum(self) -> f32 {
236-
num::Float::signum(self)
237-
}
238-
239-
/// Returns `true` if `self`'s sign bit is positive, including
240-
/// `+0.0` and `INFINITY`.
241-
///
242-
/// ```
243-
/// use std::f32;
244-
///
245-
/// let nan = f32::NAN;
246-
/// let f = 7.0_f32;
247-
/// let g = -7.0_f32;
248-
///
249-
/// assert!(f.is_sign_positive());
250-
/// assert!(!g.is_sign_positive());
251-
/// // Requires both tests to determine if is `NaN`
252-
/// assert!(!nan.is_sign_positive() && !nan.is_sign_negative());
253-
/// ```
254-
#[inline]
255-
fn is_sign_positive(self) -> bool {
256-
num::Float::is_sign_positive(self)
257-
}
258-
259-
/// Returns `true` if `self`'s sign is negative, including `-0.0`
260-
/// and `NEG_INFINITY`.
261-
///
262-
/// ```
263-
/// use std::f32;
264-
///
265-
/// let nan = f32::NAN;
266-
/// let f = 7.0f32;
267-
/// let g = -7.0f32;
268-
///
269-
/// assert!(!f.is_sign_negative());
270-
/// assert!(g.is_sign_negative());
271-
/// // Requires both tests to determine if is `NaN`.
272-
/// assert!(!nan.is_sign_positive() && !nan.is_sign_negative());
273-
/// ```
274-
#[inline]
275-
fn is_sign_negative(self) -> bool {
276-
num::Float::is_sign_negative(self)
277-
}
278-
279124
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
280125
/// error. This produces a more accurate result with better performance than
281126
/// a separate multiplication operation followed by an add.
@@ -297,23 +142,6 @@ impl FloatImpls for f32 {
297142
unsafe { intrinsics::fmaf32(self, a, b) }
298143
}
299144

300-
/// Raises a number to an integer power.
301-
///
302-
/// Using this function is generally faster than using `powf`
303-
///
304-
/// ```
305-
/// use std::f32;
306-
///
307-
/// let x = 2.0_f32;
308-
/// let abs_difference = (x.powi(2) - x*x).abs();
309-
///
310-
/// assert!(abs_difference <= f32::EPSILON);
311-
/// ```
312-
#[inline]
313-
fn powi(self, n: i32) -> f32 {
314-
num::Float::powi(self, n)
315-
}
316-
317145
/// Raises a number to a floating point power.
318146
///
319147
/// ```
@@ -483,22 +311,6 @@ impl FloatImpls for f32 {
483311
return unsafe { intrinsics::log10f32(self) };
484312
}
485313

486-
/// Converts radians to degrees.
487-
///
488-
/// ```
489-
/// use std::f32::{self, consts};
490-
///
491-
/// let angle = consts::PI;
492-
///
493-
/// let abs_difference = (angle.to_degrees() - 180.0).abs();
494-
///
495-
/// assert!(abs_difference <= f32::EPSILON);
496-
/// ```
497-
#[inline]
498-
fn to_degrees(self) -> f32 {
499-
num::Float::to_degrees(self)
500-
}
501-
502314
/// Returns the maximum of the two numbers.
503315
///
504316
/// ```

0 commit comments

Comments
 (0)