@@ -250,7 +250,7 @@ impl Bounded for f32 {
250
250
impl Primitive for f32 { }
251
251
252
252
impl Float for f32 {
253
- fn powi ( & self , n : i32 ) -> f32 { unsafe { intrinsics:: powif32 ( * self , n) } }
253
+ fn powi ( self , n : i32 ) -> f32 { unsafe { intrinsics:: powif32 ( self , n) } }
254
254
255
255
#[ inline]
256
256
fn max ( self , other : f32 ) -> f32 {
@@ -276,33 +276,33 @@ impl Float for f32 {
276
276
277
277
/// Returns `true` if the number is NaN
278
278
#[ inline]
279
- fn is_nan ( & self ) -> bool { * self != * self }
279
+ fn is_nan ( self ) -> bool { self != self }
280
280
281
281
/// Returns `true` if the number is infinite
282
282
#[ inline]
283
- fn is_infinite ( & self ) -> bool {
284
- * self == Float :: infinity ( ) || * self == Float :: neg_infinity ( )
283
+ fn is_infinite ( self ) -> bool {
284
+ self == Float :: infinity ( ) || self == Float :: neg_infinity ( )
285
285
}
286
286
287
287
/// Returns `true` if the number is neither infinite or NaN
288
288
#[ inline]
289
- fn is_finite ( & self ) -> bool {
289
+ fn is_finite ( self ) -> bool {
290
290
!( self . is_nan ( ) || self . is_infinite ( ) )
291
291
}
292
292
293
293
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN
294
294
#[ inline]
295
- fn is_normal ( & self ) -> bool {
295
+ fn is_normal ( self ) -> bool {
296
296
self . classify ( ) == FPNormal
297
297
}
298
298
299
299
/// Returns the floating point category of the number. If only one property is going to
300
300
/// be tested, it is generally faster to use the specific predicate instead.
301
- fn classify ( & self ) -> FPCategory {
301
+ fn classify ( self ) -> FPCategory {
302
302
static EXP_MASK : u32 = 0x7f800000 ;
303
303
static MAN_MASK : u32 = 0x007fffff ;
304
304
305
- let bits: u32 = unsafe { :: cast:: transmute ( * self ) } ;
305
+ let bits: u32 = unsafe { :: cast:: transmute ( self ) } ;
306
306
match ( bits & MAN_MASK , bits & EXP_MASK ) {
307
307
( 0 , 0 ) => FPZero ,
308
308
( _, 0 ) => FPSubnormal ,
@@ -342,38 +342,38 @@ impl Float for f32 {
342
342
/// - `self = x * pow(2, exp)`
343
343
/// - `0.5 <= abs(x) < 1.0`
344
344
#[ inline]
345
- fn frexp ( & self ) -> ( f32 , int ) {
345
+ fn frexp ( self ) -> ( f32 , int ) {
346
346
unsafe {
347
347
let mut exp = 0 ;
348
- let x = cmath:: frexpf ( * self , & mut exp) ;
348
+ let x = cmath:: frexpf ( self , & mut exp) ;
349
349
( x, exp as int )
350
350
}
351
351
}
352
352
353
353
/// Returns the exponential of the number, minus `1`, in a way that is accurate
354
354
/// even if the number is close to zero
355
355
#[ inline]
356
- fn exp_m1 ( & self ) -> f32 { unsafe { cmath:: expm1f ( * self ) } }
356
+ fn exp_m1 ( self ) -> f32 { unsafe { cmath:: expm1f ( self ) } }
357
357
358
358
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
359
359
/// than if the operations were performed separately
360
360
#[ inline]
361
- fn ln_1p ( & self ) -> f32 { unsafe { cmath:: log1pf ( * self ) } }
361
+ fn ln_1p ( self ) -> f32 { unsafe { cmath:: log1pf ( self ) } }
362
362
363
363
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
364
364
/// produces a more accurate result with better performance than a separate multiplication
365
365
/// operation followed by an add.
366
366
#[ inline]
367
- fn mul_add ( & self , a : f32 , b : f32 ) -> f32 { unsafe { intrinsics:: fmaf32 ( * self , a, b) } }
367
+ fn mul_add ( self , a : f32 , b : f32 ) -> f32 { unsafe { intrinsics:: fmaf32 ( self , a, b) } }
368
368
369
369
/// Returns the next representable floating-point value in the direction of `other`
370
370
#[ inline]
371
- fn next_after ( & self , other : f32 ) -> f32 { unsafe { cmath:: nextafterf ( * self , other) } }
371
+ fn next_after ( self , other : f32 ) -> f32 { unsafe { cmath:: nextafterf ( self , other) } }
372
372
373
373
/// Returns the mantissa, exponent and sign as integers.
374
- fn integer_decode ( & self ) -> ( u64 , i16 , i8 ) {
374
+ fn integer_decode ( self ) -> ( u64 , i16 , i8 ) {
375
375
let bits: u32 = unsafe {
376
- :: cast:: transmute ( * self )
376
+ :: cast:: transmute ( self )
377
377
} ;
378
378
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 } ;
379
379
let mut exponent: i16 = ( ( bits >> 23 ) & 0xff ) as i16 ;
@@ -389,19 +389,19 @@ impl Float for f32 {
389
389
390
390
/// Round half-way cases toward `NEG_INFINITY`
391
391
#[ inline]
392
- fn floor ( & self ) -> f32 { unsafe { intrinsics:: floorf32 ( * self ) } }
392
+ fn floor ( self ) -> f32 { unsafe { intrinsics:: floorf32 ( self ) } }
393
393
394
394
/// Round half-way cases toward `INFINITY`
395
395
#[ inline]
396
- fn ceil ( & self ) -> f32 { unsafe { intrinsics:: ceilf32 ( * self ) } }
396
+ fn ceil ( self ) -> f32 { unsafe { intrinsics:: ceilf32 ( self ) } }
397
397
398
398
/// Round half-way cases away from `0.0`
399
399
#[ inline]
400
- fn round ( & self ) -> f32 { unsafe { intrinsics:: roundf32 ( * self ) } }
400
+ fn round ( self ) -> f32 { unsafe { intrinsics:: roundf32 ( self ) } }
401
401
402
402
/// The integer part of the number (rounds towards `0.0`)
403
403
#[ inline]
404
- fn trunc ( & self ) -> f32 { unsafe { intrinsics:: truncf32 ( * self ) } }
404
+ fn trunc ( self ) -> f32 { unsafe { intrinsics:: truncf32 ( self ) } }
405
405
406
406
/// The fractional part of the number, satisfying:
407
407
///
@@ -410,7 +410,7 @@ impl Float for f32 {
410
410
/// assert!(x == x.trunc() + x.fract())
411
411
/// ```
412
412
#[ inline]
413
- fn fract ( & self ) -> f32 { * self - self . trunc ( ) }
413
+ fn fract ( self ) -> f32 { self - self . trunc ( ) }
414
414
415
415
/// Archimedes' constant
416
416
#[ inline]
@@ -482,82 +482,82 @@ impl Float for f32 {
482
482
483
483
/// The reciprocal (multiplicative inverse) of the number
484
484
#[ inline]
485
- fn recip ( & self ) -> f32 { 1.0 / * self }
485
+ fn recip ( self ) -> f32 { 1.0 / self }
486
486
487
487
#[ inline]
488
- fn powf ( & self , n : & f32 ) -> f32 { unsafe { intrinsics:: powf32 ( * self , * n) } }
488
+ fn powf ( self , n : f32 ) -> f32 { unsafe { intrinsics:: powf32 ( self , n) } }
489
489
490
490
#[ inline]
491
- fn sqrt ( & self ) -> f32 { unsafe { intrinsics:: sqrtf32 ( * self ) } }
491
+ fn sqrt ( self ) -> f32 { unsafe { intrinsics:: sqrtf32 ( self ) } }
492
492
493
493
#[ inline]
494
- fn rsqrt ( & self ) -> f32 { self . sqrt ( ) . recip ( ) }
494
+ fn rsqrt ( self ) -> f32 { self . sqrt ( ) . recip ( ) }
495
495
496
496
#[ inline]
497
- fn cbrt ( & self ) -> f32 { unsafe { cmath:: cbrtf ( * self ) } }
497
+ fn cbrt ( self ) -> f32 { unsafe { cmath:: cbrtf ( self ) } }
498
498
499
499
#[ inline]
500
- fn hypot ( & self , other : & f32 ) -> f32 { unsafe { cmath:: hypotf ( * self , * other) } }
500
+ fn hypot ( self , other : f32 ) -> f32 { unsafe { cmath:: hypotf ( self , other) } }
501
501
502
502
#[ inline]
503
- fn sin ( & self ) -> f32 { unsafe { intrinsics:: sinf32 ( * self ) } }
503
+ fn sin ( self ) -> f32 { unsafe { intrinsics:: sinf32 ( self ) } }
504
504
505
505
#[ inline]
506
- fn cos ( & self ) -> f32 { unsafe { intrinsics:: cosf32 ( * self ) } }
506
+ fn cos ( self ) -> f32 { unsafe { intrinsics:: cosf32 ( self ) } }
507
507
508
508
#[ inline]
509
- fn tan ( & self ) -> f32 { unsafe { cmath:: tanf ( * self ) } }
509
+ fn tan ( self ) -> f32 { unsafe { cmath:: tanf ( self ) } }
510
510
511
511
#[ inline]
512
- fn asin ( & self ) -> f32 { unsafe { cmath:: asinf ( * self ) } }
512
+ fn asin ( self ) -> f32 { unsafe { cmath:: asinf ( self ) } }
513
513
514
514
#[ inline]
515
- fn acos ( & self ) -> f32 { unsafe { cmath:: acosf ( * self ) } }
515
+ fn acos ( self ) -> f32 { unsafe { cmath:: acosf ( self ) } }
516
516
517
517
#[ inline]
518
- fn atan ( & self ) -> f32 { unsafe { cmath:: atanf ( * self ) } }
518
+ fn atan ( self ) -> f32 { unsafe { cmath:: atanf ( self ) } }
519
519
520
520
#[ inline]
521
- fn atan2 ( & self , other : & f32 ) -> f32 { unsafe { cmath:: atan2f ( * self , * other) } }
521
+ fn atan2 ( self , other : f32 ) -> f32 { unsafe { cmath:: atan2f ( self , other) } }
522
522
523
523
/// Simultaneously computes the sine and cosine of the number
524
524
#[ inline]
525
- fn sin_cos ( & self ) -> ( f32 , f32 ) {
525
+ fn sin_cos ( self ) -> ( f32 , f32 ) {
526
526
( self . sin ( ) , self . cos ( ) )
527
527
}
528
528
529
529
/// Returns the exponential of the number
530
530
#[ inline]
531
- fn exp ( & self ) -> f32 { unsafe { intrinsics:: expf32 ( * self ) } }
531
+ fn exp ( self ) -> f32 { unsafe { intrinsics:: expf32 ( self ) } }
532
532
533
533
/// Returns 2 raised to the power of the number
534
534
#[ inline]
535
- fn exp2 ( & self ) -> f32 { unsafe { intrinsics:: exp2f32 ( * self ) } }
535
+ fn exp2 ( self ) -> f32 { unsafe { intrinsics:: exp2f32 ( self ) } }
536
536
537
537
/// Returns the natural logarithm of the number
538
538
#[ inline]
539
- fn ln ( & self ) -> f32 { unsafe { intrinsics:: logf32 ( * self ) } }
539
+ fn ln ( self ) -> f32 { unsafe { intrinsics:: logf32 ( self ) } }
540
540
541
541
/// Returns the logarithm of the number with respect to an arbitrary base
542
542
#[ inline]
543
- fn log ( & self , base : & f32 ) -> f32 { self . ln ( ) / base. ln ( ) }
543
+ fn log ( self , base : f32 ) -> f32 { self . ln ( ) / base. ln ( ) }
544
544
545
545
/// Returns the base 2 logarithm of the number
546
546
#[ inline]
547
- fn log2 ( & self ) -> f32 { unsafe { intrinsics:: log2f32 ( * self ) } }
547
+ fn log2 ( self ) -> f32 { unsafe { intrinsics:: log2f32 ( self ) } }
548
548
549
549
/// Returns the base 10 logarithm of the number
550
550
#[ inline]
551
- fn log10 ( & self ) -> f32 { unsafe { intrinsics:: log10f32 ( * self ) } }
551
+ fn log10 ( self ) -> f32 { unsafe { intrinsics:: log10f32 ( self ) } }
552
552
553
553
#[ inline]
554
- fn sinh ( & self ) -> f32 { unsafe { cmath:: sinhf ( * self ) } }
554
+ fn sinh ( self ) -> f32 { unsafe { cmath:: sinhf ( self ) } }
555
555
556
556
#[ inline]
557
- fn cosh ( & self ) -> f32 { unsafe { cmath:: coshf ( * self ) } }
557
+ fn cosh ( self ) -> f32 { unsafe { cmath:: coshf ( self ) } }
558
558
559
559
#[ inline]
560
- fn tanh ( & self ) -> f32 { unsafe { cmath:: tanhf ( * self ) } }
560
+ fn tanh ( self ) -> f32 { unsafe { cmath:: tanhf ( self ) } }
561
561
562
562
/// Inverse hyperbolic sine
563
563
///
@@ -567,8 +567,8 @@ impl Float for f32 {
567
567
/// - `self` if `self` is `0.0`, `-0.0`, `INFINITY`, or `NEG_INFINITY`
568
568
/// - `NAN` if `self` is `NAN`
569
569
#[ inline]
570
- fn asinh ( & self ) -> f32 {
571
- match * self {
570
+ fn asinh ( self ) -> f32 {
571
+ match self {
572
572
NEG_INFINITY => NEG_INFINITY ,
573
573
x => ( x + ( ( x * x) + 1.0 ) . sqrt ( ) ) . ln ( ) ,
574
574
}
@@ -582,8 +582,8 @@ impl Float for f32 {
582
582
/// - `INFINITY` if `self` is `INFINITY`
583
583
/// - `NAN` if `self` is `NAN` or `self < 1.0` (including `NEG_INFINITY`)
584
584
#[ inline]
585
- fn acosh ( & self ) -> f32 {
586
- match * self {
585
+ fn acosh ( self ) -> f32 {
586
+ match self {
587
587
x if x < 1.0 => Float :: nan ( ) ,
588
588
x => ( x + ( ( x * x) - 1.0 ) . sqrt ( ) ) . ln ( ) ,
589
589
}
@@ -600,19 +600,19 @@ impl Float for f32 {
600
600
/// - `NAN` if the `self` is `NAN` or outside the domain of `-1.0 <= self <= 1.0`
601
601
/// (including `INFINITY` and `NEG_INFINITY`)
602
602
#[ inline]
603
- fn atanh ( & self ) -> f32 {
604
- 0.5 * ( ( 2.0 * * self ) / ( 1.0 - * self ) ) . ln_1p ( )
603
+ fn atanh ( self ) -> f32 {
604
+ 0.5 * ( ( 2.0 * self ) / ( 1.0 - self ) ) . ln_1p ( )
605
605
}
606
606
607
607
/// Converts to degrees, assuming the number is in radians
608
608
#[ inline]
609
- fn to_degrees ( & self ) -> f32 { * self * ( 180.0f32 / Float :: pi ( ) ) }
609
+ fn to_degrees ( self ) -> f32 { self * ( 180.0f32 / Float :: pi ( ) ) }
610
610
611
611
/// Converts to radians, assuming the number is in degrees
612
612
#[ inline]
613
- fn to_radians ( & self ) -> f32 {
613
+ fn to_radians ( self ) -> f32 {
614
614
let value: f32 = Float :: pi ( ) ;
615
- * self * ( value / 180.0f32 )
615
+ self * ( value / 180.0f32 )
616
616
}
617
617
}
618
618
@@ -1162,7 +1162,7 @@ mod tests {
1162
1162
fn test_integer_decode ( ) {
1163
1163
assert_eq ! ( 3.14159265359f32 . integer_decode( ) , ( 13176795u64 , -22i16 , 1i8 ) ) ;
1164
1164
assert_eq ! ( ( -8573.5918555f32 ) . integer_decode( ) , ( 8779358u64 , -10i16 , -1i8 ) ) ;
1165
- assert_eq ! ( 2f32 . powf( & 100.0 ) . integer_decode( ) , ( 8388608u64 , 77i16 , 1i8 ) ) ;
1165
+ assert_eq ! ( 2f32 . powf( 100.0 ) . integer_decode( ) , ( 8388608u64 , 77i16 , 1i8 ) ) ;
1166
1166
assert_eq ! ( 0f32 . integer_decode( ) , ( 0u64 , -150i16 , 1i8 ) ) ;
1167
1167
assert_eq ! ( ( -0f32 ) . integer_decode( ) , ( 0u64 , -150i16 , -1i8 ) ) ;
1168
1168
assert_eq ! ( INFINITY . integer_decode( ) , ( 8388608u64 , 105i16 , 1i8 ) ) ;
0 commit comments