14
14
15
15
use prelude:: * ;
16
16
17
+ use cast;
17
18
use default:: Default ;
18
19
use from_str:: FromStr ;
19
20
use libc:: { c_int} ;
@@ -213,12 +214,16 @@ impl Neg<f32> for f32 {
213
214
impl Signed for f32 {
214
215
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
215
216
#[ inline]
216
- fn abs ( & self ) -> f32 { unsafe { intrinsics:: fabsf32 ( * self ) } }
217
+ fn abs ( & self ) -> f32 {
218
+ unsafe { intrinsics:: fabsf32 ( * self ) }
219
+ }
217
220
218
221
/// The positive difference of two numbers. Returns `0.0` if the number is less than or
219
222
/// equal to `other`, otherwise the difference between`self` and `other` is returned.
220
223
#[ inline]
221
- fn abs_sub ( & self , other : & f32 ) -> f32 { unsafe { cmath:: fdimf ( * self , * other) } }
224
+ fn abs_sub ( & self , other : & f32 ) -> f32 {
225
+ unsafe { cmath:: fdimf ( * self , * other) }
226
+ }
222
227
223
228
/// # Returns
224
229
///
@@ -227,7 +232,9 @@ impl Signed for f32 {
227
232
/// - `NAN` if the number is NaN
228
233
#[ inline]
229
234
fn signum ( & self ) -> f32 {
230
- if self . is_nan ( ) { NAN } else { unsafe { intrinsics:: copysignf32 ( 1.0 , * self ) } }
235
+ if self . is_nan ( ) { NAN } else {
236
+ unsafe { intrinsics:: copysignf32 ( 1.0 , * self ) }
237
+ }
231
238
}
232
239
233
240
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
@@ -250,7 +257,9 @@ impl Bounded for f32 {
250
257
impl Primitive for f32 { }
251
258
252
259
impl Float for f32 {
253
- fn powi ( self , n : i32 ) -> f32 { unsafe { intrinsics:: powif32 ( self , n) } }
260
+ fn powi ( self , n : i32 ) -> f32 {
261
+ unsafe { intrinsics:: powif32 ( self , n) }
262
+ }
254
263
255
264
#[ inline]
256
265
fn max ( self , other : f32 ) -> f32 {
@@ -302,7 +311,7 @@ impl Float for f32 {
302
311
static EXP_MASK : u32 = 0x7f800000 ;
303
312
static MAN_MASK : u32 = 0x007fffff ;
304
313
305
- let bits: u32 = unsafe { :: cast:: transmute ( self ) } ;
314
+ let bits: u32 = unsafe { cast:: transmute ( self ) } ;
306
315
match ( bits & MAN_MASK , bits & EXP_MASK ) {
307
316
( 0 , 0 ) => FPZero ,
308
317
( _, 0 ) => FPSubnormal ,
@@ -335,7 +344,9 @@ impl Float for f32 {
335
344
336
345
/// Constructs a floating point number by multiplying `x` by 2 raised to the power of `exp`
337
346
#[ inline]
338
- fn ldexp ( x : f32 , exp : int ) -> f32 { unsafe { cmath:: ldexpf ( x, exp as c_int ) } }
347
+ fn ldexp ( x : f32 , exp : int ) -> f32 {
348
+ unsafe { cmath:: ldexpf ( x, exp as c_int ) }
349
+ }
339
350
340
351
/// Breaks the number into a normalized fraction and a base-2 exponent, satisfying:
341
352
///
@@ -353,28 +364,34 @@ impl Float for f32 {
353
364
/// Returns the exponential of the number, minus `1`, in a way that is accurate
354
365
/// even if the number is close to zero
355
366
#[ inline]
356
- fn exp_m1 ( self ) -> f32 { unsafe { cmath:: expm1f ( self ) } }
367
+ fn exp_m1 ( self ) -> f32 {
368
+ unsafe { cmath:: expm1f ( self ) }
369
+ }
357
370
358
371
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
359
372
/// than if the operations were performed separately
360
373
#[ inline]
361
- fn ln_1p ( self ) -> f32 { unsafe { cmath:: log1pf ( self ) } }
374
+ fn ln_1p ( self ) -> f32 {
375
+ unsafe { cmath:: log1pf ( self ) }
376
+ }
362
377
363
378
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
364
379
/// produces a more accurate result with better performance than a separate multiplication
365
380
/// operation followed by an add.
366
381
#[ inline]
367
- fn mul_add ( self , a : f32 , b : f32 ) -> f32 { unsafe { intrinsics:: fmaf32 ( self , a, b) } }
382
+ fn mul_add ( self , a : f32 , b : f32 ) -> f32 {
383
+ unsafe { intrinsics:: fmaf32 ( self , a, b) }
384
+ }
368
385
369
386
/// Returns the next representable floating-point value in the direction of `other`
370
387
#[ inline]
371
- fn next_after ( self , other : f32 ) -> f32 { unsafe { cmath:: nextafterf ( self , other) } }
388
+ fn next_after ( self , other : f32 ) -> f32 {
389
+ unsafe { cmath:: nextafterf ( self , other) }
390
+ }
372
391
373
392
/// Returns the mantissa, exponent and sign as integers.
374
393
fn integer_decode ( self ) -> ( u64 , i16 , i8 ) {
375
- let bits: u32 = unsafe {
376
- :: cast:: transmute ( self )
377
- } ;
394
+ let bits: u32 = unsafe { cast:: transmute ( self ) } ;
378
395
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 } ;
379
396
let mut exponent: i16 = ( ( bits >> 23 ) & 0xff ) as i16 ;
380
397
let mantissa = if exponent == 0 {
@@ -389,19 +406,27 @@ impl Float for f32 {
389
406
390
407
/// Round half-way cases toward `NEG_INFINITY`
391
408
#[ inline]
392
- fn floor ( self ) -> f32 { unsafe { intrinsics:: floorf32 ( self ) } }
409
+ fn floor ( self ) -> f32 {
410
+ unsafe { intrinsics:: floorf32 ( self ) }
411
+ }
393
412
394
413
/// Round half-way cases toward `INFINITY`
395
414
#[ inline]
396
- fn ceil ( self ) -> f32 { unsafe { intrinsics:: ceilf32 ( self ) } }
415
+ fn ceil ( self ) -> f32 {
416
+ unsafe { intrinsics:: ceilf32 ( self ) }
417
+ }
397
418
398
419
/// Round half-way cases away from `0.0`
399
420
#[ inline]
400
- fn round ( self ) -> f32 { unsafe { intrinsics:: roundf32 ( self ) } }
421
+ fn round ( self ) -> f32 {
422
+ unsafe { intrinsics:: roundf32 ( self ) }
423
+ }
401
424
402
425
/// The integer part of the number (rounds towards `0.0`)
403
426
#[ inline]
404
- fn trunc ( self ) -> f32 { unsafe { intrinsics:: truncf32 ( self ) } }
427
+ fn trunc ( self ) -> f32 {
428
+ unsafe { intrinsics:: truncf32 ( self ) }
429
+ }
405
430
406
431
/// The fractional part of the number, satisfying:
407
432
///
@@ -485,40 +510,62 @@ impl Float for f32 {
485
510
fn recip ( self ) -> f32 { 1.0 / self }
486
511
487
512
#[ inline]
488
- fn powf ( self , n : f32 ) -> f32 { unsafe { intrinsics:: powf32 ( self , n) } }
513
+ fn powf ( self , n : f32 ) -> f32 {
514
+ unsafe { intrinsics:: powf32 ( self , n) }
515
+ }
489
516
490
517
#[ inline]
491
- fn sqrt ( self ) -> f32 { unsafe { intrinsics:: sqrtf32 ( self ) } }
518
+ fn sqrt ( self ) -> f32 {
519
+ unsafe { intrinsics:: sqrtf32 ( self ) }
520
+ }
492
521
493
522
#[ inline]
494
523
fn rsqrt ( self ) -> f32 { self . sqrt ( ) . recip ( ) }
495
524
496
525
#[ inline]
497
- fn cbrt ( self ) -> f32 { unsafe { cmath:: cbrtf ( self ) } }
526
+ fn cbrt ( self ) -> f32 {
527
+ unsafe { cmath:: cbrtf ( self ) }
528
+ }
498
529
499
530
#[ inline]
500
- fn hypot ( self , other : f32 ) -> f32 { unsafe { cmath:: hypotf ( self , other) } }
531
+ fn hypot ( self , other : f32 ) -> f32 {
532
+ unsafe { cmath:: hypotf ( self , other) }
533
+ }
501
534
502
535
#[ inline]
503
- fn sin ( self ) -> f32 { unsafe { intrinsics:: sinf32 ( self ) } }
536
+ fn sin ( self ) -> f32 {
537
+ unsafe { intrinsics:: sinf32 ( self ) }
538
+ }
504
539
505
540
#[ inline]
506
- fn cos ( self ) -> f32 { unsafe { intrinsics:: cosf32 ( self ) } }
541
+ fn cos ( self ) -> f32 {
542
+ unsafe { intrinsics:: cosf32 ( self ) }
543
+ }
507
544
508
545
#[ inline]
509
- fn tan ( self ) -> f32 { unsafe { cmath:: tanf ( self ) } }
546
+ fn tan ( self ) -> f32 {
547
+ unsafe { cmath:: tanf ( self ) }
548
+ }
510
549
511
550
#[ inline]
512
- fn asin ( self ) -> f32 { unsafe { cmath:: asinf ( self ) } }
551
+ fn asin ( self ) -> f32 {
552
+ unsafe { cmath:: asinf ( self ) }
553
+ }
513
554
514
555
#[ inline]
515
- fn acos ( self ) -> f32 { unsafe { cmath:: acosf ( self ) } }
556
+ fn acos ( self ) -> f32 {
557
+ unsafe { cmath:: acosf ( self ) }
558
+ }
516
559
517
560
#[ inline]
518
- fn atan ( self ) -> f32 { unsafe { cmath:: atanf ( self ) } }
561
+ fn atan ( self ) -> f32 {
562
+ unsafe { cmath:: atanf ( self ) }
563
+ }
519
564
520
565
#[ inline]
521
- fn atan2 ( self , other : f32 ) -> f32 { unsafe { cmath:: atan2f ( self , other) } }
566
+ fn atan2 ( self , other : f32 ) -> f32 {
567
+ unsafe { cmath:: atan2f ( self , other) }
568
+ }
522
569
523
570
/// Simultaneously computes the sine and cosine of the number
524
571
#[ inline]
@@ -528,36 +575,52 @@ impl Float for f32 {
528
575
529
576
/// Returns the exponential of the number
530
577
#[ inline]
531
- fn exp ( self ) -> f32 { unsafe { intrinsics:: expf32 ( self ) } }
578
+ fn exp ( self ) -> f32 {
579
+ unsafe { intrinsics:: expf32 ( self ) }
580
+ }
532
581
533
582
/// Returns 2 raised to the power of the number
534
583
#[ inline]
535
- fn exp2 ( self ) -> f32 { unsafe { intrinsics:: exp2f32 ( self ) } }
584
+ fn exp2 ( self ) -> f32 {
585
+ unsafe { intrinsics:: exp2f32 ( self ) }
586
+ }
536
587
537
588
/// Returns the natural logarithm of the number
538
589
#[ inline]
539
- fn ln ( self ) -> f32 { unsafe { intrinsics:: logf32 ( self ) } }
590
+ fn ln ( self ) -> f32 {
591
+ unsafe { intrinsics:: logf32 ( self ) }
592
+ }
540
593
541
594
/// Returns the logarithm of the number with respect to an arbitrary base
542
595
#[ inline]
543
596
fn log ( self , base : f32 ) -> f32 { self . ln ( ) / base. ln ( ) }
544
597
545
598
/// Returns the base 2 logarithm of the number
546
599
#[ inline]
547
- fn log2 ( self ) -> f32 { unsafe { intrinsics:: log2f32 ( self ) } }
600
+ fn log2 ( self ) -> f32 {
601
+ unsafe { intrinsics:: log2f32 ( self ) }
602
+ }
548
603
549
604
/// Returns the base 10 logarithm of the number
550
605
#[ inline]
551
- fn log10 ( self ) -> f32 { unsafe { intrinsics:: log10f32 ( self ) } }
606
+ fn log10 ( self ) -> f32 {
607
+ unsafe { intrinsics:: log10f32 ( self ) }
608
+ }
552
609
553
610
#[ inline]
554
- fn sinh ( self ) -> f32 { unsafe { cmath:: sinhf ( self ) } }
611
+ fn sinh ( self ) -> f32 {
612
+ unsafe { cmath:: sinhf ( self ) }
613
+ }
555
614
556
615
#[ inline]
557
- fn cosh ( self ) -> f32 { unsafe { cmath:: coshf ( self ) } }
616
+ fn cosh ( self ) -> f32 {
617
+ unsafe { cmath:: coshf ( self ) }
618
+ }
558
619
559
620
#[ inline]
560
- fn tanh ( self ) -> f32 { unsafe { cmath:: tanhf ( self ) } }
621
+ fn tanh ( self ) -> f32 {
622
+ unsafe { cmath:: tanhf ( self ) }
623
+ }
561
624
562
625
/// Inverse hyperbolic sine
563
626
///
0 commit comments