Skip to content

Commit a7da925

Browse files
committed
auto merge of #12700 : thestinger/rust/float, r=cmr
2 parents ea71a08 + 28d4f80 commit a7da925

File tree

5 files changed

+43
-90
lines changed

5 files changed

+43
-90
lines changed

src/libstd/num/cmath.rs

-57
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,15 @@ pub mod c_double {
2828
pub fn atan(n: c_double) -> c_double;
2929
pub fn atan2(a: c_double, b: c_double) -> c_double;
3030
pub fn cbrt(n: c_double) -> c_double;
31-
pub fn ceil(n: c_double) -> c_double;
32-
pub fn copysign(x: c_double, y: c_double) -> c_double;
33-
pub fn cos(n: c_double) -> c_double;
3431
pub fn cosh(n: c_double) -> c_double;
3532
pub fn erf(n: c_double) -> c_double;
3633
pub fn erfc(n: c_double) -> c_double;
37-
pub fn exp(n: c_double) -> c_double;
3834
// rename: for consistency with underscore usage elsewhere
3935
#[link_name="expm1"]
4036
pub fn exp_m1(n: c_double) -> c_double;
41-
pub fn exp2(n: c_double) -> c_double;
42-
#[link_name="fabs"]
43-
pub fn abs(n: c_double) -> c_double;
4437
// rename: for clarity and consistency with add/sub/mul/div
4538
#[link_name="fdim"]
4639
pub fn abs_sub(a: c_double, b: c_double) -> c_double;
47-
pub fn floor(n: c_double) -> c_double;
48-
// rename: for clarity and consistency with add/sub/mul/div
49-
#[link_name="fma"]
50-
pub fn mul_add(a: c_double, b: c_double, c: c_double) -> c_double;
5140
#[link_name="fmax"]
5241
pub fn fmax(a: c_double, b: c_double) -> c_double;
5342
#[link_name="fmin"]
@@ -63,34 +52,22 @@ pub mod c_double {
6352
#[cfg(windows)]
6453
#[link_name="__lgamma_r"]
6554
pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
66-
// renamed: ln seems more natural
67-
#[link_name="log"]
68-
pub fn ln(n: c_double) -> c_double;
6955
// renamed: "logb" /often/ is confused for log2 by beginners
7056
#[link_name="logb"]
7157
pub fn log_radix(n: c_double) -> c_double;
7258
// renamed: to be consitent with log as ln
7359
#[link_name="log1p"]
7460
pub fn ln_1p(n: c_double) -> c_double;
75-
pub fn log10(n: c_double) -> c_double;
76-
pub fn log2(n: c_double) -> c_double;
7761
#[link_name="ilogb"]
7862
pub fn ilog_radix(n: c_double) -> c_int;
7963
pub fn modf(n: c_double, iptr: &mut c_double) -> c_double;
80-
pub fn pow(n: c_double, e: c_double) -> c_double;
81-
// FIXME (#1379): enable when rounding modes become available
82-
// fn rint(n: c_double) -> c_double;
83-
pub fn round(n: c_double) -> c_double;
8464
// rename: for consistency with logradix
8565
#[link_name="scalbn"]
8666
pub fn ldexp_radix(n: c_double, i: c_int) -> c_double;
87-
pub fn sin(n: c_double) -> c_double;
8867
pub fn sinh(n: c_double) -> c_double;
89-
pub fn sqrt(n: c_double) -> c_double;
9068
pub fn tan(n: c_double) -> c_double;
9169
pub fn tanh(n: c_double) -> c_double;
9270
pub fn tgamma(n: c_double) -> c_double;
93-
pub fn trunc(n: c_double) -> c_double;
9471

9572
// These are commonly only available for doubles
9673

@@ -121,34 +98,18 @@ pub mod c_float {
12198
pub fn atan2(a: c_float, b: c_float) -> c_float;
12299
#[link_name="cbrtf"]
123100
pub fn cbrt(n: c_float) -> c_float;
124-
#[link_name="ceilf"]
125-
pub fn ceil(n: c_float) -> c_float;
126-
#[link_name="copysignf"]
127-
pub fn copysign(x: c_float, y: c_float) -> c_float;
128-
#[link_name="cosf"]
129-
pub fn cos(n: c_float) -> c_float;
130101
#[link_name="coshf"]
131102
pub fn cosh(n: c_float) -> c_float;
132103
#[link_name="erff"]
133104
pub fn erf(n: c_float) -> c_float;
134105
#[link_name="erfcf"]
135106
pub fn erfc(n: c_float) -> c_float;
136-
#[link_name="expf"]
137-
pub fn exp(n: c_float) -> c_float;
138107
#[link_name="expm1f"]
139108
pub fn exp_m1(n: c_float) -> c_float;
140-
#[link_name="exp2f"]
141-
pub fn exp2(n: c_float) -> c_float;
142-
#[link_name="fabsf"]
143-
pub fn abs(n: c_float) -> c_float;
144109
#[link_name="fdimf"]
145110
pub fn abs_sub(a: c_float, b: c_float) -> c_float;
146-
#[link_name="floorf"]
147-
pub fn floor(n: c_float) -> c_float;
148111
#[link_name="frexpf"]
149112
pub fn frexp(n: c_float, value: &mut c_int) -> c_float;
150-
#[link_name="fmaf"]
151-
pub fn mul_add(a: c_float, b: c_float, c: c_float) -> c_float;
152113
#[link_name="fmaxf"]
153114
pub fn fmax(a: c_float, b: c_float) -> c_float;
154115
#[link_name="fminf"]
@@ -168,41 +129,23 @@ pub mod c_float {
168129
#[link_name="__lgammaf_r"]
169130
pub fn lgamma(n: c_float, sign: &mut c_int) -> c_float;
170131

171-
#[link_name="logf"]
172-
pub fn ln(n: c_float) -> c_float;
173132
#[link_name="logbf"]
174133
pub fn log_radix(n: c_float) -> c_float;
175134
#[link_name="log1pf"]
176135
pub fn ln_1p(n: c_float) -> c_float;
177-
#[link_name="log2f"]
178-
pub fn log2(n: c_float) -> c_float;
179-
#[link_name="log10f"]
180-
pub fn log10(n: c_float) -> c_float;
181136
#[link_name="ilogbf"]
182137
pub fn ilog_radix(n: c_float) -> c_int;
183138
#[link_name="modff"]
184139
pub fn modf(n: c_float, iptr: &mut c_float) -> c_float;
185-
#[link_name="powf"]
186-
pub fn pow(n: c_float, e: c_float) -> c_float;
187-
// FIXME (#1379): enable when rounding modes become available
188-
// #[link_name="rintf"] fn rint(n: c_float) -> c_float;
189-
#[link_name="roundf"]
190-
pub fn round(n: c_float) -> c_float;
191140
#[link_name="scalbnf"]
192141
pub fn ldexp_radix(n: c_float, i: c_int) -> c_float;
193-
#[link_name="sinf"]
194-
pub fn sin(n: c_float) -> c_float;
195142
#[link_name="sinhf"]
196143
pub fn sinh(n: c_float) -> c_float;
197-
#[link_name="sqrtf"]
198-
pub fn sqrt(n: c_float) -> c_float;
199144
#[link_name="tanf"]
200145
pub fn tan(n: c_float) -> c_float;
201146
#[link_name="tanhf"]
202147
pub fn tanh(n: c_float) -> c_float;
203148
#[link_name="tgammaf"]
204149
pub fn tgamma(n: c_float) -> c_float;
205-
#[link_name="truncf"]
206-
pub fn trunc(n: c_float) -> c_float;
207150
}
208151
}

src/libstd/num/f32.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
//! Operations and constants for 32-bits floats (`f32` type)
12+
1213
#[allow(missing_doc)];
1314

1415
use prelude::*;
@@ -45,37 +46,32 @@ macro_rules! delegate(
4546

4647
delegate!(
4748
// intrinsics
48-
fn abs(n: f32) -> f32 = intrinsics::fabsf32,
49+
fn sqrt(n: f32) -> f32 = intrinsics::sqrtf32,
50+
fn powi(n: f32, e: i32) -> f32 = intrinsics::powif32,
51+
fn sin(n: f32) -> f32 = intrinsics::sinf32,
4952
fn cos(n: f32) -> f32 = intrinsics::cosf32,
53+
fn pow(n: f32, e: f32) -> f32 = intrinsics::powf32,
5054
fn exp(n: f32) -> f32 = intrinsics::expf32,
5155
fn exp2(n: f32) -> f32 = intrinsics::exp2f32,
52-
fn floor(x: f32) -> f32 = intrinsics::floorf32,
5356
fn ln(n: f32) -> f32 = intrinsics::logf32,
5457
fn log10(n: f32) -> f32 = intrinsics::log10f32,
5558
fn log2(n: f32) -> f32 = intrinsics::log2f32,
5659
fn mul_add(a: f32, b: f32, c: f32) -> f32 = intrinsics::fmaf32,
57-
fn pow(n: f32, e: f32) -> f32 = intrinsics::powf32,
58-
// fn powi(n: f32, e: c_int) -> f32 = intrinsics::powif32,
59-
fn sin(n: f32) -> f32 = intrinsics::sinf32,
60-
fn sqrt(n: f32) -> f32 = intrinsics::sqrtf32,
61-
62-
// LLVM 3.3 required to use intrinsics for these four
63-
fn ceil(n: c_float) -> c_float = cmath::c_float::ceil,
64-
fn trunc(n: c_float) -> c_float = cmath::c_float::trunc,
65-
/*
60+
fn abs(n: f32) -> f32 = intrinsics::fabsf32,
61+
fn copysign(x: f32, y: f32) -> f32 = intrinsics::copysignf32,
62+
fn floor(x: f32) -> f32 = intrinsics::floorf32,
6663
fn ceil(n: f32) -> f32 = intrinsics::ceilf32,
6764
fn trunc(n: f32) -> f32 = intrinsics::truncf32,
6865
fn rint(n: f32) -> f32 = intrinsics::rintf32,
6966
fn nearbyint(n: f32) -> f32 = intrinsics::nearbyintf32,
70-
*/
67+
fn round(n: f32) -> f32 = intrinsics::roundf32,
7168

7269
// cmath
7370
fn acos(n: c_float) -> c_float = cmath::c_float::acos,
7471
fn asin(n: c_float) -> c_float = cmath::c_float::asin,
7572
fn atan(n: c_float) -> c_float = cmath::c_float::atan,
7673
fn atan2(a: c_float, b: c_float) -> c_float = cmath::c_float::atan2,
7774
fn cbrt(n: c_float) -> c_float = cmath::c_float::cbrt,
78-
fn copysign(x: c_float, y: c_float) -> c_float = cmath::c_float::copysign,
7975
fn cosh(n: c_float) -> c_float = cmath::c_float::cosh,
8076
// fn erf(n: c_float) -> c_float = cmath::c_float::erf,
8177
// fn erfc(n: c_float) -> c_float = cmath::c_float::erfc,
@@ -89,7 +85,6 @@ delegate!(
8985
fn ln_1p(n: c_float) -> c_float = cmath::c_float::ln_1p,
9086
// fn ilog_radix(n: c_float) -> c_int = cmath::c_float::ilog_radix,
9187
// fn modf(n: c_float, iptr: &mut c_float) -> c_float = cmath::c_float::modf,
92-
fn round(n: c_float) -> c_float = cmath::c_float::round,
9388
// fn ldexp_radix(n: c_float, i: c_int) -> c_float = cmath::c_float::ldexp_radix,
9489
fn sinh(n: c_float) -> c_float = cmath::c_float::sinh,
9590
fn tan(n: c_float) -> c_float = cmath::c_float::tan,
@@ -311,6 +306,16 @@ impl Bounded for f32 {
311306
impl Primitive for f32 {}
312307

313308
impl Float for f32 {
309+
#[inline]
310+
fn max(self, other: f32) -> f32 {
311+
unsafe { cmath::c_float::fmax(self, other) }
312+
}
313+
314+
#[inline]
315+
fn min(self, other: f32) -> f32 {
316+
unsafe { cmath::c_float::fmin(self, other) }
317+
}
318+
314319
#[inline]
315320
fn nan() -> f32 { 0.0 / 0.0 }
316321

src/libstd/num/f64.rs

+20-18
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ use num::{Zero, One, Bounded, strconv};
2323
use num;
2424
use intrinsics;
2525

26-
pub use cmp::{min, max};
27-
2826
macro_rules! delegate(
2927
(
3028
$(
@@ -48,37 +46,32 @@ macro_rules! delegate(
4846

4947
delegate!(
5048
// intrinsics
51-
fn abs(n: f64) -> f64 = intrinsics::fabsf64,
49+
fn sqrt(n: f64) -> f64 = intrinsics::sqrtf64,
50+
fn powi(n: f64, e: i32) -> f64 = intrinsics::powif64,
51+
fn sin(n: f64) -> f64 = intrinsics::sinf64,
5252
fn cos(n: f64) -> f64 = intrinsics::cosf64,
53+
fn pow(n: f64, e: f64) -> f64 = intrinsics::powf64,
5354
fn exp(n: f64) -> f64 = intrinsics::expf64,
5455
fn exp2(n: f64) -> f64 = intrinsics::exp2f64,
55-
fn floor(x: f64) -> f64 = intrinsics::floorf64,
5656
fn ln(n: f64) -> f64 = intrinsics::logf64,
5757
fn log10(n: f64) -> f64 = intrinsics::log10f64,
5858
fn log2(n: f64) -> f64 = intrinsics::log2f64,
5959
fn mul_add(a: f64, b: f64, c: f64) -> f64 = intrinsics::fmaf64,
60-
fn pow(n: f64, e: f64) -> f64 = intrinsics::powf64,
61-
// fn powi(n: f64, e: c_int) -> f64 = intrinsics::powif64,
62-
fn sin(n: f64) -> f64 = intrinsics::sinf64,
63-
fn sqrt(n: f64) -> f64 = intrinsics::sqrtf64,
64-
65-
// LLVM 3.3 required to use intrinsics for these four
66-
fn ceil(n: c_double) -> c_double = cmath::c_double::ceil,
67-
fn trunc(n: c_double) -> c_double = cmath::c_double::trunc,
68-
/*
60+
fn abs(n: f64) -> f64 = intrinsics::fabsf64,
61+
fn copysign(x: f64, y: f64) -> f64 = intrinsics::copysignf64,
62+
fn floor(x: f64) -> f64 = intrinsics::floorf64,
6963
fn ceil(n: f64) -> f64 = intrinsics::ceilf64,
7064
fn trunc(n: f64) -> f64 = intrinsics::truncf64,
71-
fn rint(n: c_double) -> c_double = intrinsics::rintf64,
72-
fn nearbyint(n: c_double) -> c_double = intrinsics::nearbyintf64,
73-
*/
65+
fn rint(n: f64) -> f64 = intrinsics::rintf64,
66+
fn nearbyint(n: f64) -> f64 = intrinsics::nearbyintf64,
67+
fn round(n: f64) -> f64 = intrinsics::roundf64,
7468

7569
// cmath
7670
fn acos(n: c_double) -> c_double = cmath::c_double::acos,
7771
fn asin(n: c_double) -> c_double = cmath::c_double::asin,
7872
fn atan(n: c_double) -> c_double = cmath::c_double::atan,
7973
fn atan2(a: c_double, b: c_double) -> c_double = cmath::c_double::atan2,
8074
fn cbrt(n: c_double) -> c_double = cmath::c_double::cbrt,
81-
fn copysign(x: c_double, y: c_double) -> c_double = cmath::c_double::copysign,
8275
fn cosh(n: c_double) -> c_double = cmath::c_double::cosh,
8376
// fn erf(n: c_double) -> c_double = cmath::c_double::erf,
8477
// fn erfc(n: c_double) -> c_double = cmath::c_double::erfc,
@@ -92,7 +85,6 @@ delegate!(
9285
fn ln_1p(n: c_double) -> c_double = cmath::c_double::ln_1p,
9386
// fn ilog_radix(n: c_double) -> c_int = cmath::c_double::ilog_radix,
9487
// fn modf(n: c_double, iptr: &mut c_double) -> c_double = cmath::c_double::modf,
95-
fn round(n: c_double) -> c_double = cmath::c_double::round,
9688
// fn ldexp_radix(n: c_double, i: c_int) -> c_double = cmath::c_double::ldexp_radix,
9789
fn sinh(n: c_double) -> c_double = cmath::c_double::sinh,
9890
fn tan(n: c_double) -> c_double = cmath::c_double::tan,
@@ -313,6 +305,16 @@ impl Bounded for f64 {
313305
impl Primitive for f64 {}
314306

315307
impl Float for f64 {
308+
#[inline]
309+
fn max(self, other: f64) -> f64 {
310+
unsafe { cmath::c_double::fmax(self, other) }
311+
}
312+
313+
#[inline]
314+
fn min(self, other: f64) -> f64 {
315+
unsafe { cmath::c_double::fmin(self, other) }
316+
}
317+
316318
#[inline]
317319
fn nan() -> f64 { 0.0 / 0.0 }
318320

src/libstd/num/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ pub enum FPCategory {
313313
pub trait Float: Signed
314314
+ Round
315315
+ Primitive {
316+
fn max(self, other: Self) -> Self;
317+
fn min(self, other: Self) -> Self;
318+
316319
// FIXME (#5527): These should be associated constants
317320
fn nan() -> Self;
318321
fn infinity() -> Self;

src/libtest/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ impl MetricMap {
10631063
Some(v) => {
10641064
let delta = v.value - vold.value;
10651065
let noise = match noise_pct {
1066-
None => f64::max(vold.noise.abs(), v.noise.abs()),
1066+
None => vold.noise.abs().max(v.noise.abs()),
10671067
Some(pct) => vold.value * pct / 100.0
10681068
};
10691069
if delta.abs() <= noise {

0 commit comments

Comments
 (0)