Skip to content

Commit 5e12e1b

Browse files
committed
remove the cmath module
This is an implementation detail of the `f32` and `f64` modules and it should not be public. It renames many functions and leaves out any provided by LLVM intrinsics, so it is not a sensible binding to the C standard library's math library and will never be a stable target. This also removes the abuse of link_name so that this can be switched to using automatically generated definitions in the future. This also removes the `scalbn` binding as it is equivalent to `ldexp` when `FLT_RADIX` is 2, which must always be true for Rust.
1 parent 8ca5caf commit 5e12e1b

File tree

4 files changed

+126
-205
lines changed

4 files changed

+126
-205
lines changed

src/libstd/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ pub mod raw;
204204
/* For internal use, not exported */
205205

206206
mod unicode;
207-
#[path = "num/cmath.rs"]
208-
mod cmath;
209207

210208
// FIXME #7809: This shouldn't be pub, and it should be reexported under 'unstable'
211209
// but name resolution doesn't work without it being pub.

src/libstd/num/cmath.rs

Lines changed: 0 additions & 151 deletions
This file was deleted.

src/libstd/num/f32.rs

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use prelude::*;
1616

17-
use cmath;
1817
use default::Default;
1918
use from_str::FromStr;
2019
use libc::{c_float, c_int};
@@ -23,6 +22,46 @@ use num::{Zero, One, Bounded, strconv};
2322
use num;
2423
use intrinsics;
2524

25+
#[allow(dead_code)]
26+
mod cmath {
27+
use libc::{c_float, c_int};
28+
29+
#[link_name = "m"]
30+
extern {
31+
pub fn acosf(n: c_float) -> c_float;
32+
pub fn asinf(n: c_float) -> c_float;
33+
pub fn atanf(n: c_float) -> c_float;
34+
pub fn atan2f(a: c_float, b: c_float) -> c_float;
35+
pub fn cbrtf(n: c_float) -> c_float;
36+
pub fn coshf(n: c_float) -> c_float;
37+
pub fn erff(n: c_float) -> c_float;
38+
pub fn erfcf(n: c_float) -> c_float;
39+
pub fn expm1f(n: c_float) -> c_float;
40+
pub fn fdimf(a: c_float, b: c_float) -> c_float;
41+
pub fn frexpf(n: c_float, value: &mut c_int) -> c_float;
42+
pub fn fmaxf(a: c_float, b: c_float) -> c_float;
43+
pub fn fminf(a: c_float, b: c_float) -> c_float;
44+
pub fn nextafterf(x: c_float, y: c_float) -> c_float;
45+
pub fn hypotf(x: c_float, y: c_float) -> c_float;
46+
pub fn ldexpf(x: c_float, n: c_int) -> c_float;
47+
pub fn logbf(n: c_float) -> c_float;
48+
pub fn log1pf(n: c_float) -> c_float;
49+
pub fn ilogbf(n: c_float) -> c_int;
50+
pub fn modff(n: c_float, iptr: &mut c_float) -> c_float;
51+
pub fn sinhf(n: c_float) -> c_float;
52+
pub fn tanf(n: c_float) -> c_float;
53+
pub fn tanhf(n: c_float) -> c_float;
54+
pub fn tgammaf(n: c_float) -> c_float;
55+
56+
#[cfg(unix)]
57+
pub fn lgammaf_r(n: c_float, sign: &mut c_int) -> c_float;
58+
59+
#[cfg(windows)]
60+
#[link_name="__lgammaf_r"]
61+
pub fn lgammaf_r(n: c_float, sign: &mut c_int) -> c_float;
62+
}
63+
}
64+
2665
macro_rules! delegate(
2766
(
2867
$(
@@ -66,29 +105,22 @@ delegate!(
66105
fn nearbyint(n: f32) -> f32 = intrinsics::nearbyintf32,
67106
fn round(n: f32) -> f32 = intrinsics::roundf32,
68107

69-
// cmath
70-
fn acos(n: c_float) -> c_float = cmath::c_float::acos,
71-
fn asin(n: c_float) -> c_float = cmath::c_float::asin,
72-
fn atan(n: c_float) -> c_float = cmath::c_float::atan,
73-
fn atan2(a: c_float, b: c_float) -> c_float = cmath::c_float::atan2,
74-
fn cbrt(n: c_float) -> c_float = cmath::c_float::cbrt,
75-
fn cosh(n: c_float) -> c_float = cmath::c_float::cosh,
76-
// fn erf(n: c_float) -> c_float = cmath::c_float::erf,
77-
// fn erfc(n: c_float) -> c_float = cmath::c_float::erfc,
78-
fn exp_m1(n: c_float) -> c_float = cmath::c_float::exp_m1,
79-
fn abs_sub(a: c_float, b: c_float) -> c_float = cmath::c_float::abs_sub,
80-
fn next_after(x: c_float, y: c_float) -> c_float = cmath::c_float::next_after,
81-
fn frexp(n: c_float, value: &mut c_int) -> c_float = cmath::c_float::frexp,
82-
fn hypot(x: c_float, y: c_float) -> c_float = cmath::c_float::hypot,
83-
fn ldexp(x: c_float, n: c_int) -> c_float = cmath::c_float::ldexp,
84-
// fn log_radix(n: c_float) -> c_float = cmath::c_float::log_radix,
85-
fn ln_1p(n: c_float) -> c_float = cmath::c_float::ln_1p,
86-
// fn ilog_radix(n: c_float) -> c_int = cmath::c_float::ilog_radix,
87-
// fn modf(n: c_float, iptr: &mut c_float) -> c_float = cmath::c_float::modf,
88-
// fn ldexp_radix(n: c_float, i: c_int) -> c_float = cmath::c_float::ldexp_radix,
89-
fn sinh(n: c_float) -> c_float = cmath::c_float::sinh,
90-
fn tan(n: c_float) -> c_float = cmath::c_float::tan,
91-
fn tanh(n: c_float) -> c_float = cmath::c_float::tanh
108+
fn acos(n: c_float) -> c_float = cmath::acosf,
109+
fn asin(n: c_float) -> c_float = cmath::asinf,
110+
fn atan(n: c_float) -> c_float = cmath::atanf,
111+
fn atan2(a: c_float, b: c_float) -> c_float = cmath::atan2f,
112+
fn cbrt(n: c_float) -> c_float = cmath::cbrtf,
113+
fn cosh(n: c_float) -> c_float = cmath::coshf,
114+
fn exp_m1(n: c_float) -> c_float = cmath::expm1f,
115+
fn abs_sub(a: c_float, b: c_float) -> c_float = cmath::fdimf,
116+
fn next_after(x: c_float, y: c_float) -> c_float = cmath::nextafterf,
117+
fn frexp(n: c_float, value: &mut c_int) -> c_float = cmath::frexpf,
118+
fn hypot(x: c_float, y: c_float) -> c_float = cmath::hypotf,
119+
fn ldexp(x: c_float, n: c_int) -> c_float = cmath::ldexpf,
120+
fn ln_1p(n: c_float) -> c_float = cmath::log1pf,
121+
fn sinh(n: c_float) -> c_float = cmath::sinhf,
122+
fn tan(n: c_float) -> c_float = cmath::tanf,
123+
fn tanh(n: c_float) -> c_float = cmath::tanhf
92124
)
93125

94126
// FIXME(#11621): These constants should be deprecated once CTFE is implemented
@@ -308,12 +340,12 @@ impl Primitive for f32 {}
308340
impl Float for f32 {
309341
#[inline]
310342
fn max(self, other: f32) -> f32 {
311-
unsafe { cmath::c_float::fmax(self, other) }
343+
unsafe { cmath::fmaxf(self, other) }
312344
}
313345

314346
#[inline]
315347
fn min(self, other: f32) -> f32 {
316-
unsafe { cmath::c_float::fmin(self, other) }
348+
unsafe { cmath::fminf(self, other) }
317349
}
318350

319351
#[inline]

0 commit comments

Comments
 (0)