@@ -16,7 +16,7 @@ use prelude::*;
16
16
17
17
use default:: Default ;
18
18
use from_str:: FromStr ;
19
- use libc:: { c_float , c_int} ;
19
+ use libc:: { c_int} ;
20
20
use num:: { FPCategory , FPNaN , FPInfinite , FPZero , FPSubnormal , FPNormal } ;
21
21
use num:: { Zero , One , Bounded , strconv} ;
22
22
use num;
@@ -62,67 +62,6 @@ mod cmath {
62
62
}
63
63
}
64
64
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
-
126
65
// FIXME(#11621): These constants should be deprecated once CTFE is implemented
127
66
// in favour of calling their respective functions in `Bounded` and `Float`.
128
67
@@ -274,12 +213,12 @@ impl Neg<f32> for f32 {
274
213
impl Signed for f32 {
275
214
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
276
215
#[ inline]
277
- fn abs ( & self ) -> f32 { abs ( * self ) }
216
+ fn abs ( & self ) -> f32 { unsafe { intrinsics :: fabsf32 ( * self ) } }
278
217
279
218
/// The positive difference of two numbers. Returns `0.0` if the number is less than or
280
219
/// equal to `other`, otherwise the difference between`self` and `other` is returned.
281
220
#[ 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) } }
283
222
284
223
/// # Returns
285
224
///
@@ -288,7 +227,7 @@ impl Signed for f32 {
288
227
/// - `NAN` if the number is NaN
289
228
#[ inline]
290
229
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 ) } }
292
231
}
293
232
294
233
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
@@ -303,19 +242,19 @@ impl Signed for f32 {
303
242
impl Round for f32 {
304
243
/// Round half-way cases toward `NEG_INFINITY`
305
244
#[ inline]
306
- fn floor ( & self ) -> f32 { floor ( * self ) }
245
+ fn floor ( & self ) -> f32 { unsafe { intrinsics :: floorf32 ( * self ) } }
307
246
308
247
/// Round half-way cases toward `INFINITY`
309
248
#[ inline]
310
- fn ceil ( & self ) -> f32 { ceil ( * self ) }
249
+ fn ceil ( & self ) -> f32 { unsafe { intrinsics :: ceilf32 ( * self ) } }
311
250
312
251
/// Round half-way cases away from `0.0`
313
252
#[ inline]
314
- fn round ( & self ) -> f32 { round ( * self ) }
253
+ fn round ( & self ) -> f32 { unsafe { intrinsics :: roundf32 ( * self ) } }
315
254
316
255
/// The integer part of the number (rounds towards `0.0`)
317
256
#[ inline]
318
- fn trunc ( & self ) -> f32 { trunc ( * self ) }
257
+ fn trunc ( & self ) -> f32 { unsafe { intrinsics :: truncf32 ( * self ) } }
319
258
320
259
/// The fractional part of the number, satisfying:
321
260
///
@@ -338,6 +277,8 @@ impl Bounded for f32 {
338
277
impl Primitive for f32 { }
339
278
340
279
impl Float for f32 {
280
+ fn powi ( & self , n : i32 ) -> f32 { unsafe { intrinsics:: powif32 ( * self , n) } }
281
+
341
282
#[ inline]
342
283
fn max ( self , other : f32 ) -> f32 {
343
284
unsafe { cmath:: fmaxf ( self , other) }
@@ -421,44 +362,40 @@ impl Float for f32 {
421
362
422
363
/// Constructs a floating point number by multiplying `x` by 2 raised to the power of `exp`
423
364
#[ 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 ) } }
427
366
428
367
/// Breaks the number into a normalized fraction and a base-2 exponent, satisfying:
429
368
///
430
369
/// - `self = x * pow(2, exp)`
431
370
/// - `0.5 <= abs(x) < 1.0`
432
371
#[ inline]
433
372
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
+ }
437
378
}
438
379
439
380
/// Returns the exponential of the number, minus `1`, in a way that is accurate
440
381
/// even if the number is close to zero
441
382
#[ inline]
442
- fn exp_m1 ( & self ) -> f32 { exp_m1 ( * self ) }
383
+ fn exp_m1 ( & self ) -> f32 { unsafe { cmath :: expm1f ( * self ) } }
443
384
444
385
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
445
386
/// than if the operations were performed separately
446
387
#[ inline]
447
- fn ln_1p ( & self ) -> f32 { ln_1p ( * self ) }
388
+ fn ln_1p ( & self ) -> f32 { unsafe { cmath :: log1pf ( * self ) } }
448
389
449
390
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
450
391
/// produces a more accurate result with better performance than a separate multiplication
451
392
/// operation followed by an add.
452
393
#[ 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) } }
456
395
457
396
/// Returns the next representable floating-point value in the direction of `other`
458
397
#[ 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) } }
462
399
463
400
/// Returns the mantissa, exponent and sign as integers.
464
401
fn integer_decode ( & self ) -> ( u64 , i16 , i8 ) {
@@ -550,40 +487,40 @@ impl Float for f32 {
550
487
fn recip ( & self ) -> f32 { 1.0 / * self }
551
488
552
489
#[ inline]
553
- fn powf ( & self , n : & f32 ) -> f32 { pow ( * self , * n) }
490
+ fn powf ( & self , n : & f32 ) -> f32 { unsafe { intrinsics :: powf32 ( * self , * n) } }
554
491
555
492
#[ inline]
556
- fn sqrt ( & self ) -> f32 { sqrt ( * self ) }
493
+ fn sqrt ( & self ) -> f32 { unsafe { intrinsics :: sqrtf32 ( * self ) } }
557
494
558
495
#[ inline]
559
496
fn rsqrt ( & self ) -> f32 { self . sqrt ( ) . recip ( ) }
560
497
561
498
#[ inline]
562
- fn cbrt ( & self ) -> f32 { cbrt ( * self ) }
499
+ fn cbrt ( & self ) -> f32 { unsafe { cmath :: cbrtf ( * self ) } }
563
500
564
501
#[ inline]
565
- fn hypot ( & self , other : & f32 ) -> f32 { hypot ( * self , * other) }
502
+ fn hypot ( & self , other : & f32 ) -> f32 { unsafe { cmath :: hypotf ( * self , * other) } }
566
503
567
504
#[ inline]
568
- fn sin ( & self ) -> f32 { sin ( * self ) }
505
+ fn sin ( & self ) -> f32 { unsafe { intrinsics :: sinf32 ( * self ) } }
569
506
570
507
#[ inline]
571
- fn cos ( & self ) -> f32 { cos ( * self ) }
508
+ fn cos ( & self ) -> f32 { unsafe { intrinsics :: cosf32 ( * self ) } }
572
509
573
510
#[ inline]
574
- fn tan ( & self ) -> f32 { tan ( * self ) }
511
+ fn tan ( & self ) -> f32 { unsafe { cmath :: tanf ( * self ) } }
575
512
576
513
#[ inline]
577
- fn asin ( & self ) -> f32 { asin ( * self ) }
514
+ fn asin ( & self ) -> f32 { unsafe { cmath :: asinf ( * self ) } }
578
515
579
516
#[ inline]
580
- fn acos ( & self ) -> f32 { acos ( * self ) }
517
+ fn acos ( & self ) -> f32 { unsafe { cmath :: acosf ( * self ) } }
581
518
582
519
#[ inline]
583
- fn atan ( & self ) -> f32 { atan ( * self ) }
520
+ fn atan ( & self ) -> f32 { unsafe { cmath :: atanf ( * self ) } }
584
521
585
522
#[ inline]
586
- fn atan2 ( & self , other : & f32 ) -> f32 { atan2 ( * self , * other) }
523
+ fn atan2 ( & self , other : & f32 ) -> f32 { unsafe { cmath :: atan2f ( * self , * other) } }
587
524
588
525
/// Simultaneously computes the sine and cosine of the number
589
526
#[ inline]
@@ -593,36 +530,36 @@ impl Float for f32 {
593
530
594
531
/// Returns the exponential of the number
595
532
#[ inline]
596
- fn exp ( & self ) -> f32 { exp ( * self ) }
533
+ fn exp ( & self ) -> f32 { unsafe { intrinsics :: expf32 ( * self ) } }
597
534
598
535
/// Returns 2 raised to the power of the number
599
536
#[ inline]
600
- fn exp2 ( & self ) -> f32 { exp2 ( * self ) }
537
+ fn exp2 ( & self ) -> f32 { unsafe { intrinsics :: exp2f32 ( * self ) } }
601
538
602
539
/// Returns the natural logarithm of the number
603
540
#[ inline]
604
- fn ln ( & self ) -> f32 { ln ( * self ) }
541
+ fn ln ( & self ) -> f32 { unsafe { intrinsics :: logf32 ( * self ) } }
605
542
606
543
/// Returns the logarithm of the number with respect to an arbitrary base
607
544
#[ inline]
608
545
fn log ( & self , base : & f32 ) -> f32 { self . ln ( ) / base. ln ( ) }
609
546
610
547
/// Returns the base 2 logarithm of the number
611
548
#[ inline]
612
- fn log2 ( & self ) -> f32 { log2 ( * self ) }
549
+ fn log2 ( & self ) -> f32 { unsafe { intrinsics :: log2f32 ( * self ) } }
613
550
614
551
/// Returns the base 10 logarithm of the number
615
552
#[ inline]
616
- fn log10 ( & self ) -> f32 { log10 ( * self ) }
553
+ fn log10 ( & self ) -> f32 { unsafe { intrinsics :: log10f32 ( * self ) } }
617
554
618
555
#[ inline]
619
- fn sinh ( & self ) -> f32 { sinh ( * self ) }
556
+ fn sinh ( & self ) -> f32 { unsafe { cmath :: sinhf ( * self ) } }
620
557
621
558
#[ inline]
622
- fn cosh ( & self ) -> f32 { cosh ( * self ) }
559
+ fn cosh ( & self ) -> f32 { unsafe { cmath :: coshf ( * self ) } }
623
560
624
561
#[ inline]
625
- fn tanh ( & self ) -> f32 { tanh ( * self ) }
562
+ fn tanh ( & self ) -> f32 { unsafe { cmath :: tanhf ( * self ) } }
626
563
627
564
/// Inverse hyperbolic sine
628
565
///
0 commit comments