Skip to content

Commit ae47627

Browse files
committed
Merge core::num::Float and std::num::FloatMath.
`FloatMath` no longer exists and all functionality from both traits is available under `Float`. Change from use std::num::{Float, FloatMath}; to use std::num::Float; [breaking-change]
1 parent 1291fc7 commit ae47627

File tree

6 files changed

+443
-36
lines changed

6 files changed

+443
-36
lines changed

src/libstd/num/f32.rs

+125-11
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ use prelude::v1::*;
1919

2020
use intrinsics;
2121
use libc::c_int;
22-
use num::{Float, FloatMath};
22+
use num::{Float, FpCategory};
2323
use num::strconv;
2424
use num::strconv::ExponentFormat::{ExpNone, ExpDec};
2525
use num::strconv::SignificantDigits::{DigAll, DigMax, DigExact};
2626
use num::strconv::SignFormat::SignNeg;
2727

28+
use core::num;
29+
2830
pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE};
2931
pub use core::f32::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP};
3032
pub use core::f32::{MAX_10_EXP, NAN, INFINITY, NEG_INFINITY};
@@ -72,7 +74,119 @@ mod cmath {
7274
}
7375

7476
#[unstable = "trait is unstable"]
75-
impl FloatMath for f32 {
77+
impl Float for f32 {
78+
#[inline]
79+
fn nan() -> f32 { num::Float::nan() }
80+
#[inline]
81+
fn infinity() -> f32 { num::Float::infinity() }
82+
#[inline]
83+
fn neg_infinity() -> f32 { num::Float::neg_infinity() }
84+
#[inline]
85+
fn zero() -> f32 { num::Float::zero() }
86+
#[inline]
87+
fn neg_zero() -> f32 { num::Float::neg_zero() }
88+
#[inline]
89+
fn one() -> f32 { num::Float::one() }
90+
91+
#[allow(deprecated)]
92+
#[inline]
93+
fn mantissa_digits(unused_self: Option<f32>) -> uint {
94+
num::Float::mantissa_digits(unused_self)
95+
}
96+
#[allow(deprecated)]
97+
#[inline]
98+
fn digits(unused_self: Option<f32>) -> uint { num::Float::digits(unused_self) }
99+
#[allow(deprecated)]
100+
#[inline]
101+
fn epsilon() -> f32 { num::Float::epsilon() }
102+
#[allow(deprecated)]
103+
#[inline]
104+
fn min_exp(unused_self: Option<f32>) -> int { num::Float::min_exp(unused_self) }
105+
#[allow(deprecated)]
106+
#[inline]
107+
fn max_exp(unused_self: Option<f32>) -> int { num::Float::max_exp(unused_self) }
108+
#[allow(deprecated)]
109+
#[inline]
110+
fn min_10_exp(unused_self: Option<f32>) -> int { num::Float::min_10_exp(unused_self) }
111+
#[allow(deprecated)]
112+
#[inline]
113+
fn max_10_exp(unused_self: Option<f32>) -> int { num::Float::max_10_exp(unused_self) }
114+
#[allow(deprecated)]
115+
#[inline]
116+
fn min_value() -> f32 { num::Float::min_value() }
117+
#[allow(deprecated)]
118+
#[inline]
119+
fn min_pos_value(unused_self: Option<f32>) -> f32 { num::Float::min_pos_value(unused_self) }
120+
#[allow(deprecated)]
121+
#[inline]
122+
fn max_value() -> f32 { num::Float::max_value() }
123+
124+
#[inline]
125+
fn is_nan(self) -> bool { num::Float::is_nan(self) }
126+
#[inline]
127+
fn is_infinite(self) -> bool { num::Float::is_infinite(self) }
128+
#[inline]
129+
fn is_finite(self) -> bool { num::Float::is_finite(self) }
130+
#[inline]
131+
fn is_normal(self) -> bool { num::Float::is_normal(self) }
132+
#[inline]
133+
fn classify(self) -> FpCategory { num::Float::classify(self) }
134+
135+
#[inline]
136+
fn integer_decode(self) -> (u64, i16, i8) { num::Float::integer_decode(self) }
137+
138+
#[inline]
139+
fn floor(self) -> f32 { num::Float::floor(self) }
140+
#[inline]
141+
fn ceil(self) -> f32 { num::Float::ceil(self) }
142+
#[inline]
143+
fn round(self) -> f32 { num::Float::round(self) }
144+
#[inline]
145+
fn trunc(self) -> f32 { num::Float::trunc(self) }
146+
#[inline]
147+
fn fract(self) -> f32 { num::Float::fract(self) }
148+
149+
#[inline]
150+
fn abs(self) -> f32 { num::Float::abs(self) }
151+
#[inline]
152+
fn signum(self) -> f32 { num::Float::signum(self) }
153+
#[inline]
154+
fn is_positive(self) -> bool { num::Float::is_positive(self) }
155+
#[inline]
156+
fn is_negative(self) -> bool { num::Float::is_negative(self) }
157+
158+
#[inline]
159+
fn mul_add(self, a: f32, b: f32) -> f32 { num::Float::mul_add(self, a, b) }
160+
#[inline]
161+
fn recip(self) -> f32 { num::Float::recip(self) }
162+
163+
#[inline]
164+
fn powi(self, n: i32) -> f32 { num::Float::powi(self, n) }
165+
#[inline]
166+
fn powf(self, n: f32) -> f32 { num::Float::powf(self, n) }
167+
168+
#[inline]
169+
fn sqrt(self) -> f32 { num::Float::sqrt(self) }
170+
#[inline]
171+
fn rsqrt(self) -> f32 { num::Float::rsqrt(self) }
172+
173+
#[inline]
174+
fn exp(self) -> f32 { num::Float::exp(self) }
175+
#[inline]
176+
fn exp2(self) -> f32 { num::Float::exp(self) }
177+
#[inline]
178+
fn ln(self) -> f32 { num::Float::ln(self) }
179+
#[inline]
180+
fn log(self, base: f32) -> f32 { num::Float::log(self, base) }
181+
#[inline]
182+
fn log2(self) -> f32 { num::Float::log2(self) }
183+
#[inline]
184+
fn log10(self) -> f32 { num::Float::log10(self) }
185+
#[inline]
186+
fn to_degrees(self) -> f32 { num::Float::to_degrees(self) }
187+
#[inline]
188+
fn to_radians(self) -> f32 { num::Float::to_radians(self) }
189+
76190
/// Constructs a floating point number by multiplying `x` by 2 raised to the
77191
/// power of `exp`
78192
#[inline]
@@ -639,18 +753,18 @@ mod tests {
639753
// are supported in floating-point literals
640754
let f1: f32 = FromStrRadix::from_str_radix("1p-123", 16).unwrap();
641755
let f2: f32 = FromStrRadix::from_str_radix("1p-111", 16).unwrap();
642-
assert_eq!(FloatMath::ldexp(1f32, -123), f1);
643-
assert_eq!(FloatMath::ldexp(1f32, -111), f2);
756+
assert_eq!(Float::ldexp(1f32, -123), f1);
757+
assert_eq!(Float::ldexp(1f32, -111), f2);
644758

645-
assert_eq!(FloatMath::ldexp(0f32, -123), 0f32);
646-
assert_eq!(FloatMath::ldexp(-0f32, -123), -0f32);
759+
assert_eq!(Float::ldexp(0f32, -123), 0f32);
760+
assert_eq!(Float::ldexp(-0f32, -123), -0f32);
647761

648762
let inf: f32 = Float::infinity();
649763
let neg_inf: f32 = Float::neg_infinity();
650764
let nan: f32 = Float::nan();
651-
assert_eq!(FloatMath::ldexp(inf, -123), inf);
652-
assert_eq!(FloatMath::ldexp(neg_inf, -123), neg_inf);
653-
assert!(FloatMath::ldexp(nan, -123).is_nan());
765+
assert_eq!(Float::ldexp(inf, -123), inf);
766+
assert_eq!(Float::ldexp(neg_inf, -123), neg_inf);
767+
assert!(Float::ldexp(nan, -123).is_nan());
654768
}
655769

656770
#[test]
@@ -663,8 +777,8 @@ mod tests {
663777
let (x2, exp2) = f2.frexp();
664778
assert_eq!((x1, exp1), (0.5f32, -122));
665779
assert_eq!((x2, exp2), (0.5f32, -110));
666-
assert_eq!(FloatMath::ldexp(x1, exp1), f1);
667-
assert_eq!(FloatMath::ldexp(x2, exp2), f2);
780+
assert_eq!(Float::ldexp(x1, exp1), f1);
781+
assert_eq!(Float::ldexp(x2, exp2), f2);
668782

669783
assert_eq!(0f32.frexp(), (0f32, 0));
670784
assert_eq!((-0f32).frexp(), (-0f32, 0));

src/libstd/num/f64.rs

+128-13
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ use prelude::v1::*;
1818

1919
use intrinsics;
2020
use libc::c_int;
21-
use num::{Float, FloatMath};
21+
use num::{Float, FpCategory};
2222
use num::strconv;
2323
use num::strconv::ExponentFormat::{ExpNone, ExpDec};
2424
use num::strconv::SignificantDigits::{DigAll, DigMax, DigExact};
2525
use num::strconv::SignFormat::SignNeg;
2626

27+
use core::num;
28+
2729
pub use core::f64::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE};
2830
pub use core::f64::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP};
2931
pub use core::f64::{MAX_10_EXP, NAN, INFINITY, NEG_INFINITY};
@@ -80,9 +82,122 @@ mod cmath {
8082
}
8183

8284
#[unstable = "trait is unstable"]
83-
impl FloatMath for f64 {
84-
/// Constructs a floating point number by multiplying `x` by 2 raised to the
85-
/// power of `exp`
85+
impl Float for f64 {
86+
// inlined methods from `num::Float`
87+
#[inline]
88+
fn nan() -> f64 { num::Float::nan() }
89+
#[inline]
90+
fn infinity() -> f64 { num::Float::infinity() }
91+
#[inline]
92+
fn neg_infinity() -> f64 { num::Float::neg_infinity() }
93+
#[inline]
94+
fn zero() -> f64 { num::Float::zero() }
95+
#[inline]
96+
fn neg_zero() -> f64 { num::Float::neg_zero() }
97+
#[inline]
98+
fn one() -> f64 { num::Float::one() }
99+
100+
101+
#[allow(deprecated)]
102+
#[inline]
103+
fn mantissa_digits(unused_self: Option<f64>) -> uint {
104+
num::Float::mantissa_digits(unused_self)
105+
}
106+
#[allow(deprecated)]
107+
#[inline]
108+
fn digits(unused_self: Option<f64>) -> uint { num::Float::digits(unused_self) }
109+
#[allow(deprecated)]
110+
#[inline]
111+
fn epsilon() -> f64 { num::Float::epsilon() }
112+
#[allow(deprecated)]
113+
#[inline]
114+
fn min_exp(unused_self: Option<f64>) -> int { num::Float::min_exp(unused_self) }
115+
#[allow(deprecated)]
116+
#[inline]
117+
fn max_exp(unused_self: Option<f64>) -> int { num::Float::max_exp(unused_self) }
118+
#[allow(deprecated)]
119+
#[inline]
120+
fn min_10_exp(unused_self: Option<f64>) -> int { num::Float::min_10_exp(unused_self) }
121+
#[allow(deprecated)]
122+
#[inline]
123+
fn max_10_exp(unused_self: Option<f64>) -> int { num::Float::max_10_exp(unused_self) }
124+
#[allow(deprecated)]
125+
#[inline]
126+
fn min_value() -> f64 { num::Float::min_value() }
127+
#[allow(deprecated)]
128+
#[inline]
129+
fn min_pos_value(unused_self: Option<f64>) -> f64 { num::Float::min_pos_value(unused_self) }
130+
#[allow(deprecated)]
131+
#[inline]
132+
fn max_value() -> f64 { num::Float::max_value() }
133+
134+
#[inline]
135+
fn is_nan(self) -> bool { num::Float::is_nan(self) }
136+
#[inline]
137+
fn is_infinite(self) -> bool { num::Float::is_infinite(self) }
138+
#[inline]
139+
fn is_finite(self) -> bool { num::Float::is_finite(self) }
140+
#[inline]
141+
fn is_normal(self) -> bool { num::Float::is_normal(self) }
142+
#[inline]
143+
fn classify(self) -> FpCategory { num::Float::classify(self) }
144+
145+
#[inline]
146+
fn integer_decode(self) -> (u64, i16, i8) { num::Float::integer_decode(self) }
147+
148+
#[inline]
149+
fn floor(self) -> f64 { num::Float::floor(self) }
150+
#[inline]
151+
fn ceil(self) -> f64 { num::Float::ceil(self) }
152+
#[inline]
153+
fn round(self) -> f64 { num::Float::round(self) }
154+
#[inline]
155+
fn trunc(self) -> f64 { num::Float::trunc(self) }
156+
#[inline]
157+
fn fract(self) -> f64 { num::Float::fract(self) }
158+
159+
#[inline]
160+
fn abs(self) -> f64 { num::Float::abs(self) }
161+
#[inline]
162+
fn signum(self) -> f64 { num::Float::signum(self) }
163+
#[inline]
164+
fn is_positive(self) -> bool { num::Float::is_positive(self) }
165+
#[inline]
166+
fn is_negative(self) -> bool { num::Float::is_negative(self) }
167+
168+
#[inline]
169+
fn mul_add(self, a: f64, b: f64) -> f64 { num::Float::mul_add(self, a, b) }
170+
#[inline]
171+
fn recip(self) -> f64 { num::Float::recip(self) }
172+
173+
#[inline]
174+
fn powi(self, n: i32) -> f64 { num::Float::powi(self, n) }
175+
#[inline]
176+
fn powf(self, n: f64) -> f64 { num::Float::powf(self, n) }
177+
178+
#[inline]
179+
fn sqrt(self) -> f64 { num::Float::sqrt(self) }
180+
#[inline]
181+
fn rsqrt(self) -> f64 { num::Float::rsqrt(self) }
182+
183+
#[inline]
184+
fn exp(self) -> f64 { num::Float::exp(self) }
185+
#[inline]
186+
fn exp2(self) -> f64 { num::Float::exp(self) }
187+
#[inline]
188+
fn ln(self) -> f64 { num::Float::ln(self) }
189+
#[inline]
190+
fn log(self, base: f64) -> f64 { num::Float::log(self, base) }
191+
#[inline]
192+
fn log2(self) -> f64 { num::Float::log2(self) }
193+
#[inline]
194+
fn log10(self) -> f64 { num::Float::log10(self) }
195+
196+
#[inline]
197+
fn to_degrees(self) -> f64 { num::Float::to_degrees(self) }
198+
#[inline]
199+
fn to_radians(self) -> f64 { num::Float::to_radians(self) }
200+
86201
#[inline]
87202
fn ldexp(x: f64, exp: int) -> f64 {
88203
unsafe { cmath::ldexp(x, exp as c_int) }
@@ -640,18 +755,18 @@ mod tests {
640755
// are supported in floating-point literals
641756
let f1: f64 = FromStrRadix::from_str_radix("1p-123", 16).unwrap();
642757
let f2: f64 = FromStrRadix::from_str_radix("1p-111", 16).unwrap();
643-
assert_eq!(FloatMath::ldexp(1f64, -123), f1);
644-
assert_eq!(FloatMath::ldexp(1f64, -111), f2);
758+
assert_eq!(Float::ldexp(1f64, -123), f1);
759+
assert_eq!(Float::ldexp(1f64, -111), f2);
645760

646-
assert_eq!(FloatMath::ldexp(0f64, -123), 0f64);
647-
assert_eq!(FloatMath::ldexp(-0f64, -123), -0f64);
761+
assert_eq!(Float::ldexp(0f64, -123), 0f64);
762+
assert_eq!(Float::ldexp(-0f64, -123), -0f64);
648763

649764
let inf: f64 = Float::infinity();
650765
let neg_inf: f64 = Float::neg_infinity();
651766
let nan: f64 = Float::nan();
652-
assert_eq!(FloatMath::ldexp(inf, -123), inf);
653-
assert_eq!(FloatMath::ldexp(neg_inf, -123), neg_inf);
654-
assert!(FloatMath::ldexp(nan, -123).is_nan());
767+
assert_eq!(Float::ldexp(inf, -123), inf);
768+
assert_eq!(Float::ldexp(neg_inf, -123), neg_inf);
769+
assert!(Float::ldexp(nan, -123).is_nan());
655770
}
656771

657772
#[test]
@@ -664,8 +779,8 @@ mod tests {
664779
let (x2, exp2) = f2.frexp();
665780
assert_eq!((x1, exp1), (0.5f64, -122));
666781
assert_eq!((x2, exp2), (0.5f64, -110));
667-
assert_eq!(FloatMath::ldexp(x1, exp1), f1);
668-
assert_eq!(FloatMath::ldexp(x2, exp2), f2);
782+
assert_eq!(Float::ldexp(x1, exp1), f1);
783+
assert_eq!(Float::ldexp(x2, exp2), f2);
669784

670785
assert_eq!(0f64.frexp(), (0f64, 0));
671786
assert_eq!((-0f64).frexp(), (-0f64, 0));

0 commit comments

Comments
 (0)