Skip to content

Commit b84dcf9

Browse files
committed
---
yaml --- r: 109816 b: refs/heads/master c: 08e95a8 h: refs/heads/master v: v3
1 parent 484fd62 commit b84dcf9

File tree

15 files changed

+342
-196
lines changed

15 files changed

+342
-196
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: e63346b9d8b1a8f38d9a3dbd694cc77b08ffa1e7
2+
refs/heads/master: 08e95a87b84aad8051ea806c963d089effaf0a7f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: c7fac4471201977fdb1c0c0a26c87287e12dc644
55
refs/heads/try: f64fdf524a434f0e5cd0bc91d09c144723f3c90d

trunk/src/doc/guide-pointers.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ sense, they're simple: just keep whatever ownership the data already has. For
332332
example:
333333

334334
~~~rust
335+
use std::num::sqrt;
336+
335337
struct Point {
336338
x: f32,
337339
y: f32,
@@ -341,7 +343,7 @@ fn compute_distance(p1: &Point, p2: &Point) -> f32 {
341343
let x_d = p1.x - p2.x;
342344
let y_d = p1.y - p2.y;
343345

344-
(x_d * x_d + y_d * y_d).sqrt()
346+
sqrt(x_d * x_d + y_d * y_d)
345347
}
346348

347349
fn main() {

trunk/src/doc/rust.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,14 +826,14 @@ Use declarations support a number of convenient shortcuts:
826826
An example of `use` declarations:
827827

828828
~~~~
829-
use std::iter::range_step;
829+
use std::num::sin;
830830
use std::option::{Some, None};
831831
832832
# fn foo<T>(_: T){}
833833
834834
fn main() {
835-
// Equivalent to 'std::iter::range_step(0, 10, 2);'
836-
range_step(0, 10, 2);
835+
// Equivalent to 'std::num::sin(1.0);'
836+
sin(1.0);
837837
838838
// Equivalent to 'foo(~[std::option::Some(1.0), std::option::None]);'
839839
foo(~[Some(1.0), None]);

trunk/src/doc/tutorial.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,13 @@ matching in order to bind names to the contents of data types.
504504
505505
~~~~
506506
use std::f64;
507+
use std::num::atan;
507508
fn angle(vector: (f64, f64)) -> f64 {
508509
let pi = f64::consts::PI;
509510
match vector {
510511
(0.0, y) if y < 0.0 => 1.5 * pi,
511512
(0.0, _) => 0.5 * pi,
512-
(x, y) => (y / x).atan()
513+
(x, y) => atan(y / x)
513514
}
514515
}
515516
~~~~
@@ -1429,11 +1430,12 @@ bad, but often copies are expensive. So we’d like to define a function
14291430
that takes the points by pointer. We can use references to do this:
14301431
14311432
~~~
1433+
use std::num::sqrt;
14321434
# struct Point { x: f64, y: f64 }
14331435
fn compute_distance(p1: &Point, p2: &Point) -> f64 {
14341436
let x_d = p1.x - p2.x;
14351437
let y_d = p1.y - p2.y;
1436-
(x_d * x_d + y_d * y_d).sqrt()
1438+
sqrt(x_d * x_d + y_d * y_d)
14371439
}
14381440
~~~
14391441
@@ -2301,7 +2303,7 @@ impl Shape for Circle {
23012303
fn new(area: f64) -> Circle { Circle { radius: (area / PI).sqrt() } }
23022304
}
23032305
impl Shape for Square {
2304-
fn new(area: f64) -> Square { Square { length: area.sqrt() } }
2306+
fn new(area: f64) -> Square { Square { length: (area).sqrt() } }
23052307
}
23062308
23072309
let area = 42.5;

trunk/src/librand/distributions/gamma.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! The Gamma and derived distributions.
1212
1313
use std::num::Float;
14+
use std::num;
1415
use {Rng, Open01};
1516
use super::normal::StandardNormal;
1617
use super::{IndependentSample, Sample, Exp};
@@ -113,7 +114,7 @@ impl GammaLargeShape {
113114
GammaLargeShape {
114115
shape: shape,
115116
scale: scale,
116-
c: 1. / (9. * d).sqrt(),
117+
c: 1. / num::sqrt(9. * d),
117118
d: d
118119
}
119120
}
@@ -142,7 +143,7 @@ impl IndependentSample<f64> for GammaSmallShape {
142143
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
143144
let Open01(u) = rng.gen::<Open01<f64>>();
144145

145-
self.large_shape.ind_sample(rng) * u.powf(&self.inv_shape)
146+
self.large_shape.ind_sample(rng) * num::powf(u, self.inv_shape)
146147
}
147148
}
148149
impl IndependentSample<f64> for GammaLargeShape {
@@ -159,7 +160,7 @@ impl IndependentSample<f64> for GammaLargeShape {
159160

160161
let x_sqr = x * x;
161162
if u < 1.0 - 0.0331 * x_sqr * x_sqr ||
162-
u.ln() < 0.5 * x_sqr + self.d * (1.0 - v + v.ln()) {
163+
num::ln(u) < 0.5 * x_sqr + self.d * (1.0 - v + num::ln(v)) {
163164
return self.d * v * self.scale
164165
}
165166
}

trunk/src/libstd/lib.rs

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

208208
mod unicode;
209+
#[path = "num/cmath.rs"]
210+
mod cmath;
209211

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

trunk/src/libstd/num/cmath.rs

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![allow(missing_doc)]
12+
#![allow(dead_code)]
13+
14+
//! Bindings for the C math library (for basic mathematic functions)
15+
16+
// Function names are almost identical to C's libmath, a few have been
17+
// renamed, grep for "rename:"
18+
19+
pub mod c_double {
20+
use libc::{c_double, c_int};
21+
22+
#[link_name = "m"]
23+
extern {
24+
// Alphabetically sorted by link_name
25+
26+
pub fn acos(n: c_double) -> c_double;
27+
pub fn asin(n: c_double) -> c_double;
28+
pub fn atan(n: c_double) -> c_double;
29+
pub fn atan2(a: c_double, b: c_double) -> c_double;
30+
pub fn cbrt(n: c_double) -> c_double;
31+
pub fn cosh(n: c_double) -> c_double;
32+
pub fn erf(n: c_double) -> c_double;
33+
pub fn erfc(n: c_double) -> c_double;
34+
// rename: for consistency with underscore usage elsewhere
35+
#[link_name="expm1"]
36+
pub fn exp_m1(n: c_double) -> c_double;
37+
// rename: for clarity and consistency with add/sub/mul/div
38+
#[link_name="fdim"]
39+
pub fn abs_sub(a: c_double, b: c_double) -> c_double;
40+
#[link_name="fmax"]
41+
pub fn fmax(a: c_double, b: c_double) -> c_double;
42+
#[link_name="fmin"]
43+
pub fn fmin(a: c_double, b: c_double) -> c_double;
44+
#[link_name="nextafter"]
45+
pub fn next_after(x: c_double, y: c_double) -> c_double;
46+
pub fn frexp(n: c_double, value: &mut c_int) -> c_double;
47+
pub fn hypot(x: c_double, y: c_double) -> c_double;
48+
pub fn ldexp(x: c_double, n: c_int) -> c_double;
49+
#[cfg(unix)]
50+
#[link_name="lgamma_r"]
51+
pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
52+
#[cfg(windows)]
53+
#[link_name="__lgamma_r"]
54+
pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
55+
// renamed: "logb" /often/ is confused for log2 by beginners
56+
#[link_name="logb"]
57+
pub fn log_radix(n: c_double) -> c_double;
58+
// renamed: to be consitent with log as ln
59+
#[link_name="log1p"]
60+
pub fn ln_1p(n: c_double) -> c_double;
61+
#[link_name="ilogb"]
62+
pub fn ilog_radix(n: c_double) -> c_int;
63+
pub fn modf(n: c_double, iptr: &mut c_double) -> c_double;
64+
// rename: for consistency with logradix
65+
#[link_name="scalbn"]
66+
pub fn ldexp_radix(n: c_double, i: c_int) -> c_double;
67+
pub fn sinh(n: c_double) -> c_double;
68+
pub fn tan(n: c_double) -> c_double;
69+
pub fn tanh(n: c_double) -> c_double;
70+
pub fn tgamma(n: c_double) -> c_double;
71+
72+
// These are commonly only available for doubles
73+
74+
pub fn j0(n: c_double) -> c_double;
75+
pub fn j1(n: c_double) -> c_double;
76+
pub fn jn(i: c_int, n: c_double) -> c_double;
77+
78+
pub fn y0(n: c_double) -> c_double;
79+
pub fn y1(n: c_double) -> c_double;
80+
pub fn yn(i: c_int, n: c_double) -> c_double;
81+
}
82+
}
83+
84+
pub mod c_float {
85+
use libc::{c_float, c_int};
86+
87+
#[link_name = "m"]
88+
extern {
89+
// Alphabetically sorted by link_name
90+
91+
#[link_name="acosf"]
92+
pub fn acos(n: c_float) -> c_float;
93+
#[link_name="asinf"]
94+
pub fn asin(n: c_float) -> c_float;
95+
#[link_name="atanf"]
96+
pub fn atan(n: c_float) -> c_float;
97+
#[link_name="atan2f"]
98+
pub fn atan2(a: c_float, b: c_float) -> c_float;
99+
#[link_name="cbrtf"]
100+
pub fn cbrt(n: c_float) -> c_float;
101+
#[link_name="coshf"]
102+
pub fn cosh(n: c_float) -> c_float;
103+
#[link_name="erff"]
104+
pub fn erf(n: c_float) -> c_float;
105+
#[link_name="erfcf"]
106+
pub fn erfc(n: c_float) -> c_float;
107+
#[link_name="expm1f"]
108+
pub fn exp_m1(n: c_float) -> c_float;
109+
#[link_name="fdimf"]
110+
pub fn abs_sub(a: c_float, b: c_float) -> c_float;
111+
#[link_name="frexpf"]
112+
pub fn frexp(n: c_float, value: &mut c_int) -> c_float;
113+
#[link_name="fmaxf"]
114+
pub fn fmax(a: c_float, b: c_float) -> c_float;
115+
#[link_name="fminf"]
116+
pub fn fmin(a: c_float, b: c_float) -> c_float;
117+
#[link_name="nextafterf"]
118+
pub fn next_after(x: c_float, y: c_float) -> c_float;
119+
#[link_name="hypotf"]
120+
pub fn hypot(x: c_float, y: c_float) -> c_float;
121+
#[link_name="ldexpf"]
122+
pub fn ldexp(x: c_float, n: c_int) -> c_float;
123+
124+
#[cfg(unix)]
125+
#[link_name="lgammaf_r"]
126+
pub fn lgamma(n: c_float, sign: &mut c_int) -> c_float;
127+
128+
#[cfg(windows)]
129+
#[link_name="__lgammaf_r"]
130+
pub fn lgamma(n: c_float, sign: &mut c_int) -> c_float;
131+
132+
#[link_name="logbf"]
133+
pub fn log_radix(n: c_float) -> c_float;
134+
#[link_name="log1pf"]
135+
pub fn ln_1p(n: c_float) -> c_float;
136+
#[link_name="ilogbf"]
137+
pub fn ilog_radix(n: c_float) -> c_int;
138+
#[link_name="modff"]
139+
pub fn modf(n: c_float, iptr: &mut c_float) -> c_float;
140+
#[link_name="scalbnf"]
141+
pub fn ldexp_radix(n: c_float, i: c_int) -> c_float;
142+
#[link_name="sinhf"]
143+
pub fn sinh(n: c_float) -> c_float;
144+
#[link_name="tanf"]
145+
pub fn tan(n: c_float) -> c_float;
146+
#[link_name="tanhf"]
147+
pub fn tanh(n: c_float) -> c_float;
148+
#[link_name="tgammaf"]
149+
pub fn tgamma(n: c_float) -> c_float;
150+
}
151+
}

trunk/src/libstd/num/f32.rs

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

1515
use prelude::*;
1616

17+
use cmath;
1718
use default::Default;
1819
use from_str::FromStr;
1920
use libc::{c_float, c_int};
@@ -22,46 +23,6 @@ use num::{Zero, One, Bounded, strconv};
2223
use num;
2324
use intrinsics;
2425

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-
6526
macro_rules! delegate(
6627
(
6728
$(
@@ -105,22 +66,29 @@ delegate!(
10566
fn nearbyint(n: f32) -> f32 = intrinsics::nearbyintf32,
10667
fn round(n: f32) -> f32 = intrinsics::roundf32,
10768

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
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
12492
)
12593

12694
// FIXME(#11621): These constants should be deprecated once CTFE is implemented
@@ -340,12 +308,12 @@ impl Primitive for f32 {}
340308
impl Float for f32 {
341309
#[inline]
342310
fn max(self, other: f32) -> f32 {
343-
unsafe { cmath::fmaxf(self, other) }
311+
unsafe { cmath::c_float::fmax(self, other) }
344312
}
345313

346314
#[inline]
347315
fn min(self, other: f32) -> f32 {
348-
unsafe { cmath::fminf(self, other) }
316+
unsafe { cmath::c_float::fmin(self, other) }
349317
}
350318

351319
#[inline]

0 commit comments

Comments
 (0)