File tree 2 files changed +18
-20
lines changed
2 files changed +18
-20
lines changed Original file line number Diff line number Diff line change @@ -470,22 +470,21 @@ impl f32 {
470
470
return unsafe { intrinsics:: logf32 ( self ) } ;
471
471
}
472
472
473
- /// Returns the logarithm of the number with respect to an arbitrary base.
473
+ /// Returns the logarithm of the number with respect to an arbitrary base,
474
+ /// calculated as `self.ln() / base.ln()`.
475
+ ///
476
+ /// `self.log2()` can produce more accurate results for base 2, and
477
+ /// `self.log10()` can produce more accurate results for base 10.
474
478
///
475
479
/// ```
476
480
/// use std::f32;
477
481
///
478
- /// let ten = 10.0f32;
479
- /// let two = 2.0f32;
480
- ///
481
- /// // log10(10) - 1 == 0
482
- /// let abs_difference_10 = (ten.log(10.0) - 1.0).abs();
482
+ /// let five = 5.0f32;
483
483
///
484
- /// // log2(2 ) - 1 == 0
485
- /// let abs_difference_2 = (two .log(2 .0) - 1.0).abs();
484
+ /// // log5(5 ) - 1 == 0
485
+ /// let abs_difference = (five .log(5 .0) - 1.0).abs();
486
486
///
487
- /// assert!(abs_difference_10 <= f32::EPSILON);
488
- /// assert!(abs_difference_2 <= f32::EPSILON);
487
+ /// assert!(abs_difference <= f32::EPSILON);
489
488
/// ```
490
489
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
491
490
#[ inline]
Original file line number Diff line number Diff line change @@ -430,20 +430,19 @@ impl f64 {
430
430
self . log_wrapper ( |n| { unsafe { intrinsics:: logf64 ( n) } } )
431
431
}
432
432
433
- /// Returns the logarithm of the number with respect to an arbitrary base.
433
+ /// Returns the logarithm of the number with respect to an arbitrary base,
434
+ /// calculated as `self.ln() / base.ln()`.
434
435
///
435
- /// ```
436
- /// let ten = 10.0_f64;
437
- /// let two = 2.0_f64;
436
+ /// `self.log2()` can produce more accurate results for base 2, and
437
+ /// `self.log10()` can produce more accurate results for base 10.
438
438
///
439
- /// // log10(10) - 1 == 0
440
- /// let abs_difference_10 = (ten.log(10.0) - 1.0).abs() ;
439
+ /// ```
440
+ /// let five = 5.0_f64 ;
441
441
///
442
- /// // log2(2 ) - 1 == 0
443
- /// let abs_difference_2 = (two .log(2 .0) - 1.0).abs();
442
+ /// // log5(5 ) - 1 == 0
443
+ /// let abs_difference = (five .log(5 .0) - 1.0).abs();
444
444
///
445
- /// assert!(abs_difference_10 < 1e-10);
446
- /// assert!(abs_difference_2 < 1e-10);
445
+ /// assert!(abs_difference < 1e-10);
447
446
/// ```
448
447
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
449
448
#[ inline]
You can’t perform that action at this time.
0 commit comments