Skip to content

Commit cd248e2

Browse files
committed
Clean up std::num::cmath and remove stale comments
1 parent 1246f0b commit cd248e2

File tree

4 files changed

+80
-187
lines changed

4 files changed

+80
-187
lines changed

src/libextra/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ impl MetricMap {
979979
if delta.abs() <= noise {
980980
LikelyNoise
981981
} else {
982-
let pct = delta.abs() / (vold.value).max(&f64::epsilon) * 100.0;
982+
let pct = delta.abs() / (vold.value).max(&f64::EPSILON) * 100.0;
983983
if vold.noise < 0.0 {
984984
// When 'noise' is negative, it means we want
985985
// to see deltas that go up over time, and can

src/libstd/num/cmath.rs

Lines changed: 9 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99
// except according to those terms.
1010

1111
#[allow(missing_doc)];
12-
#[allow(non_uppercase_statics)];
1312
#[allow(dead_code)];
1413

1514
//! Bindings for the C math library (for basic mathematic functions)
1615
17-
// function names are almost identical to C's libmath, a few have been
16+
// Function names are almost identical to C's libmath, a few have been
1817
// renamed, grep for "rename:"
1918

20-
pub mod c_double_utils {
19+
pub mod c_double {
2120
use libc::{c_double, c_int};
2221

2322
#[link_name = "m"]
2423
extern {
25-
// Alpabetically sorted by link_name
24+
// Alphabetically sorted by link_name
2625

2726
pub fn acos(n: c_double) -> c_double;
2827
pub fn asin(n: c_double) -> c_double;
@@ -79,8 +78,8 @@ pub mod c_double_utils {
7978
pub fn ilog_radix(n: c_double) -> c_int;
8079
pub fn modf(n: c_double, iptr: &mut c_double) -> c_double;
8180
pub fn pow(n: c_double, e: c_double) -> c_double;
82-
// FIXME (#1379): enable when rounding modes become available
83-
// fn rint(n: c_double) -> c_double;
81+
// FIXME (#1379): enable when rounding modes become available
82+
// fn rint(n: c_double) -> c_double;
8483
pub fn round(n: c_double) -> c_double;
8584
// rename: for consistency with logradix
8685
#[link_name="scalbn"]
@@ -105,12 +104,12 @@ pub mod c_double_utils {
105104
}
106105
}
107106

108-
pub mod c_float_utils {
107+
pub mod c_float {
109108
use libc::{c_float, c_int};
110109

111110
#[link_name = "m"]
112111
extern {
113-
// Alpabetically sorted by link_name
112+
// Alphabetically sorted by link_name
114113

115114
#[link_name="acosf"]
116115
pub fn acos(n: c_float) -> c_float;
@@ -185,8 +184,8 @@ pub mod c_float_utils {
185184
pub fn modf(n: c_float, iptr: &mut c_float) -> c_float;
186185
#[link_name="powf"]
187186
pub fn pow(n: c_float, e: c_float) -> c_float;
188-
// FIXME (#1379): enable when rounding modes become available
189-
// #[link_name="rintf"] fn rint(n: c_float) -> c_float;
187+
// FIXME (#1379): enable when rounding modes become available
188+
// #[link_name="rintf"] fn rint(n: c_float) -> c_float;
190189
#[link_name="roundf"]
191190
pub fn round(n: c_float) -> c_float;
192191
#[link_name="scalbnf"]
@@ -207,101 +206,3 @@ pub mod c_float_utils {
207206
pub fn trunc(n: c_float) -> c_float;
208207
}
209208
}
210-
211-
// PORT check these by running src/etc/machconsts.c for your architecture
212-
213-
// FIXME obtain machine float/math constants automatically (Issue #1986)
214-
215-
pub mod c_float_targ_consts {
216-
pub static radix: uint = 2u;
217-
pub static mantissa_digits: uint = 24u;
218-
pub static digits: uint = 6u;
219-
pub static min_exp: uint = -125u;
220-
pub static max_exp: uint = 128u;
221-
pub static min_10_exp: int = -37;
222-
pub static max_10_exp: int = 38;
223-
// FIXME (#1433): this is wrong, replace with hexadecimal (%a) staticants
224-
// below.
225-
pub static min_value: f32 = 1.175494e-38_f32;
226-
pub static max_value: f32 = 3.402823e+38_f32;
227-
pub static epsilon: f32 = 0.000000_f32;
228-
}
229-
230-
pub mod c_double_targ_consts {
231-
pub static radix: uint = 2u;
232-
pub static mantissa_digits: uint = 53u;
233-
pub static digits: uint = 15u;
234-
pub static min_exp: uint = -1021u;
235-
pub static max_exp: uint = 1024u;
236-
pub static min_10_exp: int = -307;
237-
pub static max_10_exp: int = 308;
238-
// FIXME (#1433): this is wrong, replace with hexadecimal (%a) staticants
239-
// below.
240-
pub static min_value: f64 = 2.225074e-308_f64;
241-
pub static max_value: f64 = 1.797693e+308_f64;
242-
pub static epsilon: f64 = 2.220446e-16_f64;
243-
}
244-
245-
/*
246-
247-
FIXME use these once they can be parsed (see Issue #1433)
248-
249-
pub mod c_float_math_consts {
250-
pub static pi: c_float = 0x1.921fb6p+1_f32;
251-
pub static div_1_pi: c_float = 0x1.45f306p-2_f32;
252-
pub static div_2_pi: c_float = 0x1.45f306p-1_f32;
253-
pub static div_pi_2: c_float = 0x1.921fb6p+0_f32;
254-
pub static div_pi_4: c_float = 0x1.921fb6p-1_f32;
255-
pub static div_2_sqrtpi: c_float = 0x1.20dd76p+0_f32;
256-
pub static e: c_float = 0x1.5bf0a8p+1_f32;
257-
pub static log2_e: c_float = 0x1.715476p+0_f32;
258-
pub static log10_e: c_float = 0x1.bcb7b2p-2_f32;
259-
pub static ln_2: c_float = 0x1.62e43p-1_f32;
260-
pub static ln_10: c_float = 0x1.26bb1cp+1_f32;
261-
pub static sqrt2: c_float = 0x1.6a09e6p+0_f32;
262-
pub static div_1_sqrt2: c_float = 0x1.6a09e6p-1_f32;
263-
}
264-
265-
pub mod c_double_math_consts {
266-
pub static pi: c_double = 0x1.921fb54442d18p+1_f64;
267-
pub static div_1_pi: c_double = 0x1.45f306dc9c883p-2_f64;
268-
pub static div_2_pi: c_double = 0x1.45f306dc9c883p-1_f64;
269-
pub static div_pi_2: c_double = 0x1.921fb54442d18p+0_f64;
270-
pub static div_pi_4: c_double = 0x1.921fb54442d18p-1_f64;
271-
pub static div_2_sqrtpi: c_double = 0x1.20dd750429b6dp+0_f64;
272-
pub static e: c_double = 0x1.5bf0a8b145769p+1_f64;
273-
pub static log2_e: c_double = 0x1.71547652b82fep+0_f64;
274-
pub static log10_e: c_double = 0x1.bcb7b1526e50ep-2_f64;
275-
pub static ln_2: c_double = 0x1.62e42fefa39efp-1_f64;
276-
pub static ln_10: c_double = 0x1.26bb1bbb55516p+1_f64;
277-
pub static sqrt2: c_double = 0x1.6a09e667f3bcdp+0_f64;
278-
pub static div_1_sqrt2: c_double = 0x1.6a09e667f3bcdp-1_f64;
279-
}
280-
281-
pub mod c_float_targ_consts {
282-
pub static radix: uint = 2u;
283-
pub static mantissa_digits: uint = 24u;
284-
pub static digits: uint = 6u;
285-
pub static min_exp: int = -125;
286-
pub static max_exp: int = 128;
287-
pub static min_10_exp: int = -37;
288-
pub static max_10_exp: int = 38;
289-
pub static min_value: c_float = 0x1p-126_f32;
290-
pub static max_value: c_float = 0x1.fffffep+127_f32;
291-
pub static epsilon: c_float = 0x1p-23_f32;
292-
}
293-
294-
pub mod c_double_targ_consts {
295-
pub static radix: uint = 2u;
296-
pub static mantissa_digits: uint = 53u;
297-
pub static digits: uint = 15u;
298-
pub static min_exp: int = -1021;
299-
pub static max_exp: int = 1024;
300-
pub static min_10_exp: int = -307;
301-
pub static max_10_exp: int = 308;
302-
pub static min_value: c_double = 0x1p-1022_f64;
303-
pub static max_value: c_double = 0x1.fffffffffffffp+1023_f64;
304-
pub static epsilon: c_double = 0x1p-52_f64;
305-
}
306-
307-
*/

src/libstd/num/f32.rs

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use prelude::*;
1515

16-
use cmath::c_float_utils;
16+
use cmath;
1717
use default::Default;
1818
use libc::{c_float, c_int};
1919
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
@@ -22,8 +22,6 @@ use num;
2222
use to_str;
2323
use unstable::intrinsics;
2424

25-
pub use cmath::c_float_targ_consts::*;
26-
2725
macro_rules! delegate(
2826
(
2927
$(
@@ -62,8 +60,8 @@ delegate!(
6260
fn sqrt(n: f32) -> f32 = intrinsics::sqrtf32,
6361

6462
// LLVM 3.3 required to use intrinsics for these four
65-
fn ceil(n: c_float) -> c_float = c_float_utils::ceil,
66-
fn trunc(n: c_float) -> c_float = c_float_utils::trunc,
63+
fn ceil(n: c_float) -> c_float = cmath::c_float::ceil,
64+
fn trunc(n: c_float) -> c_float = cmath::c_float::trunc,
6765
/*
6866
fn ceil(n: f32) -> f32 = intrinsics::ceilf32,
6967
fn trunc(n: f32) -> f32 = intrinsics::truncf32,
@@ -72,47 +70,53 @@ delegate!(
7270
*/
7371

7472
// cmath
75-
fn acos(n: c_float) -> c_float = c_float_utils::acos,
76-
fn asin(n: c_float) -> c_float = c_float_utils::asin,
77-
fn atan(n: c_float) -> c_float = c_float_utils::atan,
78-
fn atan2(a: c_float, b: c_float) -> c_float = c_float_utils::atan2,
79-
fn cbrt(n: c_float) -> c_float = c_float_utils::cbrt,
80-
fn copysign(x: c_float, y: c_float) -> c_float = c_float_utils::copysign,
81-
fn cosh(n: c_float) -> c_float = c_float_utils::cosh,
82-
// fn erf(n: c_float) -> c_float = c_float_utils::erf,
83-
// fn erfc(n: c_float) -> c_float = c_float_utils::erfc,
84-
fn exp_m1(n: c_float) -> c_float = c_float_utils::exp_m1,
85-
fn abs_sub(a: c_float, b: c_float) -> c_float = c_float_utils::abs_sub,
86-
fn next_after(x: c_float, y: c_float) -> c_float = c_float_utils::next_after,
87-
fn frexp(n: c_float, value: &mut c_int) -> c_float = c_float_utils::frexp,
88-
fn hypot(x: c_float, y: c_float) -> c_float = c_float_utils::hypot,
89-
fn ldexp(x: c_float, n: c_int) -> c_float = c_float_utils::ldexp,
90-
// fn lgamma(n: c_float, sign: &mut c_int) -> c_float = c_float_utils::lgamma,
91-
// fn log_radix(n: c_float) -> c_float = c_float_utils::log_radix,
92-
fn ln_1p(n: c_float) -> c_float = c_float_utils::ln_1p,
93-
// fn ilog_radix(n: c_float) -> c_int = c_float_utils::ilog_radix,
94-
// fn modf(n: c_float, iptr: &mut c_float) -> c_float = c_float_utils::modf,
95-
fn round(n: c_float) -> c_float = c_float_utils::round,
96-
// fn ldexp_radix(n: c_float, i: c_int) -> c_float = c_float_utils::ldexp_radix,
97-
fn sinh(n: c_float) -> c_float = c_float_utils::sinh,
98-
fn tan(n: c_float) -> c_float = c_float_utils::tan,
99-
fn tanh(n: c_float) -> c_float = c_float_utils::tanh
100-
// fn tgamma(n: c_float) -> c_float = c_float_utils::tgamma
73+
fn acos(n: c_float) -> c_float = cmath::c_float::acos,
74+
fn asin(n: c_float) -> c_float = cmath::c_float::asin,
75+
fn atan(n: c_float) -> c_float = cmath::c_float::atan,
76+
fn atan2(a: c_float, b: c_float) -> c_float = cmath::c_float::atan2,
77+
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,
79+
fn cosh(n: c_float) -> c_float = cmath::c_float::cosh,
80+
// fn erf(n: c_float) -> c_float = cmath::c_float::erf,
81+
// fn erfc(n: c_float) -> c_float = cmath::c_float::erfc,
82+
fn exp_m1(n: c_float) -> c_float = cmath::c_float::exp_m1,
83+
fn abs_sub(a: c_float, b: c_float) -> c_float = cmath::c_float::abs_sub,
84+
fn next_after(x: c_float, y: c_float) -> c_float = cmath::c_float::next_after,
85+
fn frexp(n: c_float, value: &mut c_int) -> c_float = cmath::c_float::frexp,
86+
fn hypot(x: c_float, y: c_float) -> c_float = cmath::c_float::hypot,
87+
fn ldexp(x: c_float, n: c_int) -> c_float = cmath::c_float::ldexp,
88+
// fn log_radix(n: c_float) -> c_float = cmath::c_float::log_radix,
89+
fn ln_1p(n: c_float) -> c_float = cmath::c_float::ln_1p,
90+
// fn ilog_radix(n: c_float) -> c_int = cmath::c_float::ilog_radix,
91+
// 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,
93+
// fn ldexp_radix(n: c_float, i: c_int) -> c_float = cmath::c_float::ldexp_radix,
94+
fn sinh(n: c_float) -> c_float = cmath::c_float::sinh,
95+
fn tan(n: c_float) -> c_float = cmath::c_float::tan,
96+
fn tanh(n: c_float) -> c_float = cmath::c_float::tanh
10197
)
10298

103-
// These are not defined inside consts:: for consistency with
104-
// the integer types
99+
pub static RADIX: uint = 2u;
105100

106-
pub static NAN: f32 = 0.0_f32/0.0_f32;
101+
pub static MANTISSA_DIGITS: uint = 53u;
102+
pub static DIGITS: uint = 15u;
107103

108-
pub static INFINITY: f32 = 1.0_f32/0.0_f32;
104+
pub static EPSILON: f64 = 2.220446e-16_f64;
109105

110-
pub static NEG_INFINITY: f32 = -1.0_f32/0.0_f32;
106+
// FIXME (#1433): this is wrong, replace with hexadecimal (%a) statics
107+
// below.
108+
pub static MIN_VALUE: f64 = 2.225074e-308_f64;
109+
pub static MAX_VALUE: f64 = 1.797693e+308_f64;
111110

112-
// FIXME (#1999): replace the predicates below with llvm intrinsics or
113-
// calls to the libmath macros in the rust runtime for performance.
111+
pub static MIN_EXP: uint = -1021u;
112+
pub static MAX_EXP: uint = 1024u;
114113

115-
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify.
114+
pub static MIN_10_EXP: int = -307;
115+
pub static MAX_10_EXP: int = 308;
116+
117+
pub static NAN: f32 = 0.0_f32/0.0_f32;
118+
pub static INFINITY: f32 = 1.0_f32/0.0_f32;
119+
pub static NEG_INFINITY: f32 = -1.0_f32/0.0_f32;
116120

117121
/* Module: consts */
118122
pub mod consts {

src/libstd/num/f64.rs

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use prelude::*;
1616

17-
use cmath::c_double_utils;
17+
use cmath;
1818
use default::Default;
1919
use libc::{c_double, c_int};
2020
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
@@ -23,7 +23,6 @@ use num;
2323
use to_str;
2424
use unstable::intrinsics;
2525

26-
pub use cmath::c_double_targ_consts::*;
2726
pub use cmp::{min, max};
2827

2928
macro_rules! delegate(
@@ -64,8 +63,8 @@ delegate!(
6463
fn sqrt(n: f64) -> f64 = intrinsics::sqrtf64,
6564

6665
// LLVM 3.3 required to use intrinsics for these four
67-
fn ceil(n: c_double) -> c_double = c_double_utils::ceil,
68-
fn trunc(n: c_double) -> c_double = c_double_utils::trunc,
66+
fn ceil(n: c_double) -> c_double = cmath::c_double::ceil,
67+
fn trunc(n: c_double) -> c_double = cmath::c_double::trunc,
6968
/*
7069
fn ceil(n: f64) -> f64 = intrinsics::ceilf64,
7170
fn trunc(n: f64) -> f64 = intrinsics::truncf64,
@@ -74,45 +73,34 @@ delegate!(
7473
*/
7574

7675
// cmath
77-
fn acos(n: c_double) -> c_double = c_double_utils::acos,
78-
fn asin(n: c_double) -> c_double = c_double_utils::asin,
79-
fn atan(n: c_double) -> c_double = c_double_utils::atan,
80-
fn atan2(a: c_double, b: c_double) -> c_double = c_double_utils::atan2,
81-
fn cbrt(n: c_double) -> c_double = c_double_utils::cbrt,
82-
fn copysign(x: c_double, y: c_double) -> c_double = c_double_utils::copysign,
83-
fn cosh(n: c_double) -> c_double = c_double_utils::cosh,
84-
// fn erf(n: c_double) -> c_double = c_double_utils::erf,
85-
// fn erfc(n: c_double) -> c_double = c_double_utils::erfc,
86-
fn exp_m1(n: c_double) -> c_double = c_double_utils::exp_m1,
87-
fn abs_sub(a: c_double, b: c_double) -> c_double = c_double_utils::abs_sub,
88-
fn next_after(x: c_double, y: c_double) -> c_double = c_double_utils::next_after,
89-
fn frexp(n: c_double, value: &mut c_int) -> c_double = c_double_utils::frexp,
90-
fn hypot(x: c_double, y: c_double) -> c_double = c_double_utils::hypot,
91-
fn ldexp(x: c_double, n: c_int) -> c_double = c_double_utils::ldexp,
92-
fn lgamma(n: c_double, sign: &mut c_int) -> c_double = c_double_utils::lgamma,
93-
// fn log_radix(n: c_double) -> c_double = c_double_utils::log_radix,
94-
fn ln_1p(n: c_double) -> c_double = c_double_utils::ln_1p,
95-
// fn ilog_radix(n: c_double) -> c_int = c_double_utils::ilog_radix,
96-
// fn modf(n: c_double, iptr: &mut c_double) -> c_double = c_double_utils::modf,
97-
fn round(n: c_double) -> c_double = c_double_utils::round,
98-
// fn ldexp_radix(n: c_double, i: c_int) -> c_double = c_double_utils::ldexp_radix,
99-
fn sinh(n: c_double) -> c_double = c_double_utils::sinh,
100-
fn tan(n: c_double) -> c_double = c_double_utils::tan,
101-
fn tanh(n: c_double) -> c_double = c_double_utils::tanh,
102-
fn tgamma(n: c_double) -> c_double = c_double_utils::tgamma,
103-
fn j0(n: c_double) -> c_double = c_double_utils::j0,
104-
fn j1(n: c_double) -> c_double = c_double_utils::j1,
105-
fn jn(i: c_int, n: c_double) -> c_double = c_double_utils::jn,
106-
fn y0(n: c_double) -> c_double = c_double_utils::y0,
107-
fn y1(n: c_double) -> c_double = c_double_utils::y1,
108-
fn yn(i: c_int, n: c_double) -> c_double = c_double_utils::yn
76+
fn acos(n: c_double) -> c_double = cmath::c_double::acos,
77+
fn asin(n: c_double) -> c_double = cmath::c_double::asin,
78+
fn atan(n: c_double) -> c_double = cmath::c_double::atan,
79+
fn atan2(a: c_double, b: c_double) -> c_double = cmath::c_double::atan2,
80+
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,
82+
fn cosh(n: c_double) -> c_double = cmath::c_double::cosh,
83+
// fn erf(n: c_double) -> c_double = cmath::c_double::erf,
84+
// fn erfc(n: c_double) -> c_double = cmath::c_double::erfc,
85+
fn exp_m1(n: c_double) -> c_double = cmath::c_double::exp_m1,
86+
fn abs_sub(a: c_double, b: c_double) -> c_double = cmath::c_double::abs_sub,
87+
fn next_after(x: c_double, y: c_double) -> c_double = cmath::c_double::next_after,
88+
fn frexp(n: c_double, value: &mut c_int) -> c_double = cmath::c_double::frexp,
89+
fn hypot(x: c_double, y: c_double) -> c_double = cmath::c_double::hypot,
90+
fn ldexp(x: c_double, n: c_int) -> c_double = cmath::c_double::ldexp,
91+
// fn log_radix(n: c_double) -> c_double = cmath::c_double::log_radix,
92+
fn ln_1p(n: c_double) -> c_double = cmath::c_double::ln_1p,
93+
// fn ilog_radix(n: c_double) -> c_int = cmath::c_double::ilog_radix,
94+
// 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,
96+
// fn ldexp_radix(n: c_double, i: c_int) -> c_double = cmath::c_double::ldexp_radix,
97+
fn sinh(n: c_double) -> c_double = cmath::c_double::sinh,
98+
fn tan(n: c_double) -> c_double = cmath::c_double::tan,
99+
fn tanh(n: c_double) -> c_double = cmath::c_double::tanh
109100
)
110101

111102
// FIXME (#1433): obtain these in a different way
112103

113-
// These are not defined inside consts:: for consistency with
114-
// the integer types
115-
116104
pub static RADIX: uint = 2u;
117105

118106
pub static MANTISSA_DIGITS: uint = 53u;

0 commit comments

Comments
 (0)