Skip to content

Commit 60d3c08

Browse files
committed
auto merge of #13331 : pongad/rust/remove-wrapper, r=thestinger
Fixes #12713
2 parents e714859 + d27dd82 commit 60d3c08

File tree

3 files changed

+84
-205
lines changed

3 files changed

+84
-205
lines changed

src/libstd/num/f32.rs

+39-102
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use prelude::*;
1616

1717
use default::Default;
1818
use from_str::FromStr;
19-
use libc::{c_float, c_int};
19+
use libc::{c_int};
2020
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
2121
use num::{Zero, One, Bounded, strconv};
2222
use num;
@@ -62,67 +62,6 @@ mod cmath {
6262
}
6363
}
6464

65-
macro_rules! delegate(
66-
(
67-
$(
68-
fn $name:ident(
69-
$(
70-
$arg:ident : $arg_ty:ty
71-
),*
72-
) -> $rv:ty = $bound_name:path
73-
),*
74-
) => (
75-
$(
76-
#[inline]
77-
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
78-
unsafe {
79-
$bound_name($( $arg ),*)
80-
}
81-
}
82-
)*
83-
)
84-
)
85-
86-
delegate!(
87-
// intrinsics
88-
fn sqrt(n: f32) -> f32 = intrinsics::sqrtf32,
89-
fn powi(n: f32, e: i32) -> f32 = intrinsics::powif32,
90-
fn sin(n: f32) -> f32 = intrinsics::sinf32,
91-
fn cos(n: f32) -> f32 = intrinsics::cosf32,
92-
fn pow(n: f32, e: f32) -> f32 = intrinsics::powf32,
93-
fn exp(n: f32) -> f32 = intrinsics::expf32,
94-
fn exp2(n: f32) -> f32 = intrinsics::exp2f32,
95-
fn ln(n: f32) -> f32 = intrinsics::logf32,
96-
fn log10(n: f32) -> f32 = intrinsics::log10f32,
97-
fn log2(n: f32) -> f32 = intrinsics::log2f32,
98-
fn mul_add(a: f32, b: f32, c: f32) -> f32 = intrinsics::fmaf32,
99-
fn abs(n: f32) -> f32 = intrinsics::fabsf32,
100-
fn copysign(x: f32, y: f32) -> f32 = intrinsics::copysignf32,
101-
fn floor(x: f32) -> f32 = intrinsics::floorf32,
102-
fn ceil(n: f32) -> f32 = intrinsics::ceilf32,
103-
fn trunc(n: f32) -> f32 = intrinsics::truncf32,
104-
fn rint(n: f32) -> f32 = intrinsics::rintf32,
105-
fn nearbyint(n: f32) -> f32 = intrinsics::nearbyintf32,
106-
fn round(n: f32) -> f32 = intrinsics::roundf32,
107-
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
124-
)
125-
12665
// FIXME(#11621): These constants should be deprecated once CTFE is implemented
12766
// in favour of calling their respective functions in `Bounded` and `Float`.
12867

@@ -274,12 +213,12 @@ impl Neg<f32> for f32 {
274213
impl Signed for f32 {
275214
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
276215
#[inline]
277-
fn abs(&self) -> f32 { abs(*self) }
216+
fn abs(&self) -> f32 { unsafe{intrinsics::fabsf32(*self)} }
278217

279218
/// The positive difference of two numbers. Returns `0.0` if the number is less than or
280219
/// equal to `other`, otherwise the difference between`self` and `other` is returned.
281220
#[inline]
282-
fn abs_sub(&self, other: &f32) -> f32 { abs_sub(*self, *other) }
221+
fn abs_sub(&self, other: &f32) -> f32 { unsafe{cmath::fdimf(*self, *other)} }
283222

284223
/// # Returns
285224
///
@@ -288,7 +227,7 @@ impl Signed for f32 {
288227
/// - `NAN` if the number is NaN
289228
#[inline]
290229
fn signum(&self) -> f32 {
291-
if self.is_nan() { NAN } else { copysign(1.0, *self) }
230+
if self.is_nan() { NAN } else { unsafe{intrinsics::copysignf32(1.0, *self)} }
292231
}
293232

294233
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
@@ -303,19 +242,19 @@ impl Signed for f32 {
303242
impl Round for f32 {
304243
/// Round half-way cases toward `NEG_INFINITY`
305244
#[inline]
306-
fn floor(&self) -> f32 { floor(*self) }
245+
fn floor(&self) -> f32 { unsafe{intrinsics::floorf32(*self)} }
307246

308247
/// Round half-way cases toward `INFINITY`
309248
#[inline]
310-
fn ceil(&self) -> f32 { ceil(*self) }
249+
fn ceil(&self) -> f32 { unsafe{intrinsics::ceilf32(*self)} }
311250

312251
/// Round half-way cases away from `0.0`
313252
#[inline]
314-
fn round(&self) -> f32 { round(*self) }
253+
fn round(&self) -> f32 { unsafe{intrinsics::roundf32(*self)} }
315254

316255
/// The integer part of the number (rounds towards `0.0`)
317256
#[inline]
318-
fn trunc(&self) -> f32 { trunc(*self) }
257+
fn trunc(&self) -> f32 { unsafe{intrinsics::truncf32(*self)} }
319258

320259
/// The fractional part of the number, satisfying:
321260
///
@@ -338,6 +277,8 @@ impl Bounded for f32 {
338277
impl Primitive for f32 {}
339278

340279
impl Float for f32 {
280+
fn powi(&self, n: i32) -> f32 { unsafe{intrinsics::powif32(*self, n)} }
281+
341282
#[inline]
342283
fn max(self, other: f32) -> f32 {
343284
unsafe { cmath::fmaxf(self, other) }
@@ -421,44 +362,40 @@ impl Float for f32 {
421362

422363
/// Constructs a floating point number by multiplying `x` by 2 raised to the power of `exp`
423364
#[inline]
424-
fn ldexp(x: f32, exp: int) -> f32 {
425-
ldexp(x, exp as c_int)
426-
}
365+
fn ldexp(x: f32, exp: int) -> f32 { unsafe{cmath::ldexpf(x, exp as c_int)} }
427366

428367
/// Breaks the number into a normalized fraction and a base-2 exponent, satisfying:
429368
///
430369
/// - `self = x * pow(2, exp)`
431370
/// - `0.5 <= abs(x) < 1.0`
432371
#[inline]
433372
fn frexp(&self) -> (f32, int) {
434-
let mut exp = 0;
435-
let x = frexp(*self, &mut exp);
436-
(x, exp as int)
373+
unsafe {
374+
let mut exp = 0;
375+
let x = cmath::frexpf(*self, &mut exp);
376+
(x, exp as int)
377+
}
437378
}
438379

439380
/// Returns the exponential of the number, minus `1`, in a way that is accurate
440381
/// even if the number is close to zero
441382
#[inline]
442-
fn exp_m1(&self) -> f32 { exp_m1(*self) }
383+
fn exp_m1(&self) -> f32 { unsafe{cmath::expm1f(*self)} }
443384

444385
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
445386
/// than if the operations were performed separately
446387
#[inline]
447-
fn ln_1p(&self) -> f32 { ln_1p(*self) }
388+
fn ln_1p(&self) -> f32 { unsafe{cmath::log1pf(*self)} }
448389

449390
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
450391
/// produces a more accurate result with better performance than a separate multiplication
451392
/// operation followed by an add.
452393
#[inline]
453-
fn mul_add(&self, a: f32, b: f32) -> f32 {
454-
mul_add(*self, a, b)
455-
}
394+
fn mul_add(&self, a: f32, b: f32) -> f32 { unsafe{intrinsics::fmaf32(*self, a, b)} }
456395

457396
/// Returns the next representable floating-point value in the direction of `other`
458397
#[inline]
459-
fn next_after(&self, other: f32) -> f32 {
460-
next_after(*self, other)
461-
}
398+
fn next_after(&self, other: f32) -> f32 { unsafe{cmath::nextafterf(*self, other)} }
462399

463400
/// Returns the mantissa, exponent and sign as integers.
464401
fn integer_decode(&self) -> (u64, i16, i8) {
@@ -550,40 +487,40 @@ impl Float for f32 {
550487
fn recip(&self) -> f32 { 1.0 / *self }
551488

552489
#[inline]
553-
fn powf(&self, n: &f32) -> f32 { pow(*self, *n) }
490+
fn powf(&self, n: &f32) -> f32 { unsafe{intrinsics::powf32(*self, *n)} }
554491

555492
#[inline]
556-
fn sqrt(&self) -> f32 { sqrt(*self) }
493+
fn sqrt(&self) -> f32 { unsafe{intrinsics::sqrtf32(*self)} }
557494

558495
#[inline]
559496
fn rsqrt(&self) -> f32 { self.sqrt().recip() }
560497

561498
#[inline]
562-
fn cbrt(&self) -> f32 { cbrt(*self) }
499+
fn cbrt(&self) -> f32 { unsafe{cmath::cbrtf(*self)} }
563500

564501
#[inline]
565-
fn hypot(&self, other: &f32) -> f32 { hypot(*self, *other) }
502+
fn hypot(&self, other: &f32) -> f32 { unsafe{cmath::hypotf(*self, *other)} }
566503

567504
#[inline]
568-
fn sin(&self) -> f32 { sin(*self) }
505+
fn sin(&self) -> f32 { unsafe{intrinsics::sinf32(*self)} }
569506

570507
#[inline]
571-
fn cos(&self) -> f32 { cos(*self) }
508+
fn cos(&self) -> f32 { unsafe{intrinsics::cosf32(*self)} }
572509

573510
#[inline]
574-
fn tan(&self) -> f32 { tan(*self) }
511+
fn tan(&self) -> f32 { unsafe{cmath::tanf(*self)} }
575512

576513
#[inline]
577-
fn asin(&self) -> f32 { asin(*self) }
514+
fn asin(&self) -> f32 { unsafe{cmath::asinf(*self)} }
578515

579516
#[inline]
580-
fn acos(&self) -> f32 { acos(*self) }
517+
fn acos(&self) -> f32 { unsafe{cmath::acosf(*self)} }
581518

582519
#[inline]
583-
fn atan(&self) -> f32 { atan(*self) }
520+
fn atan(&self) -> f32 { unsafe{cmath::atanf(*self)} }
584521

585522
#[inline]
586-
fn atan2(&self, other: &f32) -> f32 { atan2(*self, *other) }
523+
fn atan2(&self, other: &f32) -> f32 { unsafe{cmath::atan2f(*self, *other)} }
587524

588525
/// Simultaneously computes the sine and cosine of the number
589526
#[inline]
@@ -593,36 +530,36 @@ impl Float for f32 {
593530

594531
/// Returns the exponential of the number
595532
#[inline]
596-
fn exp(&self) -> f32 { exp(*self) }
533+
fn exp(&self) -> f32 { unsafe{intrinsics::expf32(*self)} }
597534

598535
/// Returns 2 raised to the power of the number
599536
#[inline]
600-
fn exp2(&self) -> f32 { exp2(*self) }
537+
fn exp2(&self) -> f32 { unsafe{intrinsics::exp2f32(*self)} }
601538

602539
/// Returns the natural logarithm of the number
603540
#[inline]
604-
fn ln(&self) -> f32 { ln(*self) }
541+
fn ln(&self) -> f32 { unsafe{intrinsics::logf32(*self)} }
605542

606543
/// Returns the logarithm of the number with respect to an arbitrary base
607544
#[inline]
608545
fn log(&self, base: &f32) -> f32 { self.ln() / base.ln() }
609546

610547
/// Returns the base 2 logarithm of the number
611548
#[inline]
612-
fn log2(&self) -> f32 { log2(*self) }
549+
fn log2(&self) -> f32 { unsafe{intrinsics::log2f32(*self)} }
613550

614551
/// Returns the base 10 logarithm of the number
615552
#[inline]
616-
fn log10(&self) -> f32 { log10(*self) }
553+
fn log10(&self) -> f32 { unsafe{intrinsics::log10f32(*self)} }
617554

618555
#[inline]
619-
fn sinh(&self) -> f32 { sinh(*self) }
556+
fn sinh(&self) -> f32 { unsafe{cmath::sinhf(*self)} }
620557

621558
#[inline]
622-
fn cosh(&self) -> f32 { cosh(*self) }
559+
fn cosh(&self) -> f32 { unsafe{cmath::coshf(*self)} }
623560

624561
#[inline]
625-
fn tanh(&self) -> f32 { tanh(*self) }
562+
fn tanh(&self) -> f32 { unsafe{cmath::tanhf(*self)} }
626563

627564
/// Inverse hyperbolic sine
628565
///

0 commit comments

Comments
 (0)