@@ -82,7 +82,7 @@ delegate!(
82
82
fn cosh( n: c_float) -> c_float = c_float_utils:: cosh,
83
83
fn erf( n: c_float) -> c_float = c_float_utils:: erf,
84
84
fn erfc( n: c_float) -> c_float = c_float_utils:: erfc,
85
- fn exp_m1 ( n: c_float) -> c_float = c_float_utils:: exp_m1 ,
85
+ fn expm1 ( n: c_float) -> c_float = c_float_utils:: expm1 ,
86
86
fn abs_sub( a: c_float, b: c_float) -> c_float = c_float_utils:: abs_sub,
87
87
fn fmax( a: c_float, b: c_float) -> c_float = c_float_utils:: fmax,
88
88
fn fmin( a: c_float, b: c_float) -> c_float = c_float_utils:: fmin,
@@ -92,7 +92,7 @@ delegate!(
92
92
fn ldexp( x: c_float, n: c_int) -> c_float = c_float_utils:: ldexp,
93
93
fn lgamma( n: c_float, sign: & mut c_int) -> c_float = c_float_utils:: lgamma,
94
94
fn log_radix( n: c_float) -> c_float = c_float_utils:: log_radix,
95
- fn ln_1p ( n: c_float) -> c_float = c_float_utils:: ln_1p ,
95
+ fn ln1p ( n: c_float) -> c_float = c_float_utils:: ln1p ,
96
96
fn ilog_radix( n: c_float) -> c_int = c_float_utils:: ilog_radix,
97
97
fn modf( n: c_float, iptr: & mut c_float) -> c_float = c_float_utils:: modf,
98
98
fn round( n: c_float) -> c_float = c_float_utils:: round,
@@ -195,6 +195,11 @@ pub mod consts {
195
195
pub static ln_10: f32 = 2.30258509299404568401799145468436421_f32 ;
196
196
}
197
197
198
+ #[ inline( always) ]
199
+ pub fn logarithm ( n : f32 , b : f32 ) -> f32 {
200
+ return log2 ( n) / log2 ( b) ;
201
+ }
202
+
198
203
impl Num for f32 { }
199
204
200
205
#[ cfg( notest) ]
@@ -312,13 +317,6 @@ impl Signed for f32 {
312
317
#[ inline( always) ]
313
318
fn abs ( & self ) -> f32 { abs ( * self ) }
314
319
315
- ///
316
- /// The positive difference of two numbers. Returns `0.0` if the number is less than or
317
- /// equal to `other`, otherwise the difference between`self` and `other` is returned.
318
- ///
319
- #[ inline( always) ]
320
- fn abs_sub ( & self , other : & f32 ) -> f32 { abs_sub ( * self , * other) }
321
-
322
320
///
323
321
/// # Returns
324
322
///
@@ -415,27 +413,21 @@ impl Trigonometric for f32 {
415
413
}
416
414
417
415
impl Exponential for f32 {
418
- /// Returns the exponential of the number
419
416
#[ inline( always) ]
420
417
fn exp ( & self ) -> f32 { exp ( * self ) }
421
418
422
- /// Returns 2 raised to the power of the number
423
419
#[ inline( always) ]
424
420
fn exp2 ( & self ) -> f32 { exp2 ( * self ) }
425
421
426
- /// Returns the natural logarithm of the number
427
422
#[ inline( always) ]
428
- fn ln ( & self ) -> f32 { ln ( * self ) }
423
+ fn expm1 ( & self ) -> f32 { expm1 ( * self ) }
429
424
430
- /// Returns the logarithm of the number with respect to an arbitrary base
431
425
#[ inline( always) ]
432
- fn log ( & self , base : f32 ) -> f32 { self . ln ( ) / base . ln ( ) }
426
+ fn log ( & self ) -> f32 { ln ( * self ) }
433
427
434
- /// Returns the base 2 logarithm of the number
435
428
#[ inline( always) ]
436
429
fn log2 ( & self ) -> f32 { log2 ( * self ) }
437
430
438
- /// Returns the base 10 logarithm of the number
439
431
#[ inline( always) ]
440
432
fn log10 ( & self ) -> f32 { log10 ( * self ) }
441
433
}
@@ -512,13 +504,13 @@ impl Real for f32 {
512
504
#[ inline( always) ]
513
505
fn log10_e ( ) -> f32 { 0.434294481903251827651128918916605082 }
514
506
515
- /// ln (2.0)
507
+ /// log (2.0)
516
508
#[ inline( always) ]
517
- fn ln_2 ( ) -> f32 { 0.693147180559945309417232121458176568 }
509
+ fn log_2 ( ) -> f32 { 0.693147180559945309417232121458176568 }
518
510
519
- /// ln (10.0)
511
+ /// log (10.0)
520
512
#[ inline( always) ]
521
- fn ln_10 ( ) -> f32 { 2.30258509299404568401799145468436421 }
513
+ fn log_10 ( ) -> f32 { 2.30258509299404568401799145468436421 }
522
514
523
515
/// Converts to degrees, assuming the number is in radians
524
516
#[ inline( always) ]
@@ -558,22 +550,9 @@ impl Float for f32 {
558
550
#[ inline( always) ]
559
551
fn neg_zero ( ) -> f32 { -0.0 }
560
552
561
- /// Returns `true` if the number is NaN
562
553
#[ inline( always) ]
563
554
fn is_NaN ( & self ) -> bool { * self != * self }
564
555
565
- /// Returns `true` if the number is infinite
566
- #[ inline( always) ]
567
- fn is_infinite ( & self ) -> bool {
568
- * self == Float :: infinity ( ) || * self == Float :: neg_infinity ( )
569
- }
570
-
571
- /// Returns `true` if the number is not infinite or NaN
572
- #[ inline( always) ]
573
- fn is_finite ( & self ) -> bool {
574
- !( self . is_NaN ( ) || self . is_infinite ( ) )
575
- }
576
-
577
556
#[ inline( always) ]
578
557
fn mantissa_digits ( ) -> uint { 24 }
579
558
@@ -595,19 +574,17 @@ impl Float for f32 {
595
574
#[ inline( always) ]
596
575
fn max_10_exp ( ) -> int { 38 }
597
576
598
- ///
599
- /// Returns the exponential of the number, minus `1`, in a way that is accurate
600
- /// even if the number is close to zero
601
- ///
577
+ /// Returns `true` if the number is infinite
602
578
#[ inline( always) ]
603
- fn exp_m1 ( & self ) -> f32 { exp_m1 ( * self ) }
579
+ fn is_infinite ( & self ) -> bool {
580
+ * self == Float :: infinity ( ) || * self == Float :: neg_infinity ( )
581
+ }
604
582
605
- ///
606
- /// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
607
- /// than if the operations were performed separately
608
- ///
583
+ /// Returns `true` if the number is finite
609
584
#[ inline( always) ]
610
- fn ln_1p ( & self ) -> f32 { ln_1p ( * self ) }
585
+ fn is_finite ( & self ) -> bool {
586
+ !( self . is_NaN ( ) || self . is_infinite ( ) )
587
+ }
611
588
612
589
///
613
590
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
@@ -961,12 +938,12 @@ mod tests {
961
938
assert_approx_eq ! ( Real :: frac_1_sqrt2:: <f32 >( ) , 1f32 / 2f32 . sqrt( ) ) ;
962
939
assert_approx_eq ! ( Real :: log2_e:: <f32 >( ) , Real :: e:: <f32 >( ) . log2( ) ) ;
963
940
assert_approx_eq ! ( Real :: log10_e:: <f32 >( ) , Real :: e:: <f32 >( ) . log10( ) ) ;
964
- assert_approx_eq ! ( Real :: ln_2 :: <f32 >( ) , 2f32 . ln ( ) ) ;
965
- assert_approx_eq ! ( Real :: ln_10 :: <f32 >( ) , 10f32 . ln ( ) ) ;
941
+ assert_approx_eq ! ( Real :: log_2 :: <f32 >( ) , 2f32 . log ( ) ) ;
942
+ assert_approx_eq ! ( Real :: log_10 :: <f32 >( ) , 10f32 . log ( ) ) ;
966
943
}
967
944
968
945
#[ test]
969
- pub fn test_abs ( ) {
946
+ pub fn test_signed ( ) {
970
947
assert_eq ! ( infinity. abs( ) , infinity) ;
971
948
assert_eq ! ( 1f32 . abs( ) , 1f32 ) ;
972
949
assert_eq ! ( 0f32 . abs( ) , 0f32 ) ;
@@ -975,24 +952,7 @@ mod tests {
975
952
assert_eq ! ( neg_infinity. abs( ) , infinity) ;
976
953
assert_eq ! ( ( 1f32 /neg_infinity) . abs( ) , 0f32 ) ;
977
954
assert ! ( NaN . abs( ) . is_NaN( ) ) ;
978
- }
979
-
980
- #[ test]
981
- fn test_abs_sub ( ) {
982
- assert_eq ! ( ( -1f32 ) . abs_sub( & 1f32 ) , 0f32 ) ;
983
- assert_eq ! ( 1f32 . abs_sub( & 1f32 ) , 0f32 ) ;
984
- assert_eq ! ( 1f32 . abs_sub( & 0f32 ) , 1f32 ) ;
985
- assert_eq ! ( 1f32 . abs_sub( & -1f32 ) , 2f32 ) ;
986
- assert_eq ! ( neg_infinity. abs_sub( & 0f32 ) , 0f32 ) ;
987
- assert_eq ! ( infinity. abs_sub( & 1f32 ) , infinity) ;
988
- assert_eq ! ( 0f32 . abs_sub( & neg_infinity) , infinity) ;
989
- assert_eq ! ( 0f32 . abs_sub( & infinity) , 0f32 ) ;
990
- assert ! ( NaN . abs_sub( & -1f32 ) . is_NaN( ) ) ;
991
- assert ! ( 1f32 . abs_sub( & NaN ) . is_NaN( ) ) ;
992
- }
993
955
994
- #[ test]
995
- fn test_signum ( ) {
996
956
assert_eq ! ( infinity. signum( ) , 1f32 ) ;
997
957
assert_eq ! ( 1f32 . signum( ) , 1f32 ) ;
998
958
assert_eq ! ( 0f32 . signum( ) , 1f32 ) ;
@@ -1001,10 +961,7 @@ mod tests {
1001
961
assert_eq ! ( neg_infinity. signum( ) , -1f32 ) ;
1002
962
assert_eq ! ( ( 1f32 /neg_infinity) . signum( ) , -1f32 ) ;
1003
963
assert ! ( NaN . signum( ) . is_NaN( ) ) ;
1004
- }
1005
964
1006
- #[ test]
1007
- fn test_is_positive ( ) {
1008
965
assert ! ( infinity. is_positive( ) ) ;
1009
966
assert ! ( 1f32 . is_positive( ) ) ;
1010
967
assert ! ( 0f32 . is_positive( ) ) ;
@@ -1013,10 +970,7 @@ mod tests {
1013
970
assert ! ( !neg_infinity. is_positive( ) ) ;
1014
971
assert ! ( !( 1f32 /neg_infinity) . is_positive( ) ) ;
1015
972
assert ! ( !NaN . is_positive( ) ) ;
1016
- }
1017
973
1018
- #[ test]
1019
- fn test_is_negative ( ) {
1020
974
assert ! ( !infinity. is_negative( ) ) ;
1021
975
assert ! ( !1f32 . is_negative( ) ) ;
1022
976
assert ! ( !0f32 . is_negative( ) ) ;
0 commit comments