@@ -285,20 +285,16 @@ impl Signed for f32 {
285
285
#[ inline]
286
286
fn abs ( & self ) -> f32 { abs ( * self ) }
287
287
288
- ///
289
288
/// The positive difference of two numbers. Returns `0.0` if the number is less than or
290
289
/// equal to `other`, otherwise the difference between`self` and `other` is returned.
291
- ///
292
290
#[ inline]
293
291
fn abs_sub ( & self , other : & f32 ) -> f32 { abs_sub ( * self , * other) }
294
292
295
- ///
296
293
/// # Returns
297
294
///
298
295
/// - `1.0` if the number is positive, `+0.0` or `INFINITY`
299
296
/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
300
297
/// - `NAN` if the number is NaN
301
- ///
302
298
#[ inline]
303
299
fn signum ( & self ) -> f32 {
304
300
if self . is_nan ( ) { NAN } else { copysign ( 1.0 , * self ) }
@@ -330,14 +326,12 @@ impl Round for f32 {
330
326
#[ inline]
331
327
fn trunc ( & self ) -> f32 { trunc ( * self ) }
332
328
333
- ///
334
329
/// The fractional part of the number, satisfying:
335
330
///
336
331
/// ```rust
337
332
/// let x = 1.65f32;
338
333
/// assert!(x == x.trunc() + x.fract())
339
334
/// ```
340
- ///
341
335
#[ inline]
342
336
fn fract ( & self ) -> f32 { * self - self . trunc ( ) }
343
337
}
@@ -490,15 +484,13 @@ impl Real for f32 {
490
484
#[ inline]
491
485
fn tanh ( & self ) -> f32 { tanh ( * self ) }
492
486
493
- ///
494
487
/// Inverse hyperbolic sine
495
488
///
496
489
/// # Returns
497
490
///
498
491
/// - on success, the inverse hyperbolic sine of `self` will be returned
499
492
/// - `self` if `self` is `0.0`, `-0.0`, `INFINITY`, or `NEG_INFINITY`
500
493
/// - `NAN` if `self` is `NAN`
501
- ///
502
494
#[ inline]
503
495
fn asinh ( & self ) -> f32 {
504
496
match * self {
@@ -507,15 +499,13 @@ impl Real for f32 {
507
499
}
508
500
}
509
501
510
- ///
511
502
/// Inverse hyperbolic cosine
512
503
///
513
504
/// # Returns
514
505
///
515
506
/// - on success, the inverse hyperbolic cosine of `self` will be returned
516
507
/// - `INFINITY` if `self` is `INFINITY`
517
508
/// - `NAN` if `self` is `NAN` or `self < 1.0` (including `NEG_INFINITY`)
518
- ///
519
509
#[ inline]
520
510
fn acosh ( & self ) -> f32 {
521
511
match * self {
@@ -524,7 +514,6 @@ impl Real for f32 {
524
514
}
525
515
}
526
516
527
- ///
528
517
/// Inverse hyperbolic tangent
529
518
///
530
519
/// # Returns
@@ -535,7 +524,6 @@ impl Real for f32 {
535
524
/// - `NEG_INFINITY` if `self` is `-1.0`
536
525
/// - `NAN` if the `self` is `NAN` or outside the domain of `-1.0 <= self <= 1.0`
537
526
/// (including `INFINITY` and `NEG_INFINITY`)
538
- ///
539
527
#[ inline]
540
528
fn atanh ( & self ) -> f32 {
541
529
0.5 * ( ( 2.0 * * self ) / ( 1.0 - * self ) ) . ln_1p ( )
@@ -643,38 +631,30 @@ impl Float for f32 {
643
631
ldexp ( x, exp as c_int )
644
632
}
645
633
646
- ///
647
634
/// Breaks the number into a normalized fraction and a base-2 exponent, satisfying:
648
635
///
649
636
/// - `self = x * pow(2, exp)`
650
637
/// - `0.5 <= abs(x) < 1.0`
651
- ///
652
638
#[ inline]
653
639
fn frexp ( & self ) -> ( f32 , int ) {
654
640
let mut exp = 0 ;
655
641
let x = frexp ( * self , & mut exp) ;
656
642
( x, exp as int )
657
643
}
658
644
659
- ///
660
645
/// Returns the exponential of the number, minus `1`, in a way that is accurate
661
646
/// even if the number is close to zero
662
- ///
663
647
#[ inline]
664
648
fn exp_m1 ( & self ) -> f32 { exp_m1 ( * self ) }
665
649
666
- ///
667
650
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
668
651
/// than if the operations were performed separately
669
- ///
670
652
#[ inline]
671
653
fn ln_1p ( & self ) -> f32 { ln_1p ( * self ) }
672
654
673
- ///
674
655
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
675
656
/// produces a more accurate result with better performance than a separate multiplication
676
657
/// operation followed by an add.
677
- ///
678
658
#[ inline]
679
659
fn mul_add ( & self , a : f32 , b : f32 ) -> f32 {
680
660
mul_add ( * self , a, b)
@@ -708,78 +688,98 @@ impl Float for f32 {
708
688
// Section: String Conversions
709
689
//
710
690
711
- ///
712
691
/// Converts a float to a string
713
692
///
714
693
/// # Arguments
715
694
///
716
695
/// * num - The float value
717
- ///
718
696
#[ inline]
719
697
pub fn to_str ( num : f32 ) -> ~str {
720
698
let ( r, _) = strconv:: float_to_str_common (
721
- num, 10 u, true , strconv:: SignNeg , strconv:: DigAll ) ;
699
+ num, 10 u, true , strconv:: SignNeg , strconv:: DigAll , strconv :: ExpNone , false ) ;
722
700
r
723
701
}
724
702
725
- ///
726
703
/// Converts a float to a string in hexadecimal format
727
704
///
728
705
/// # Arguments
729
706
///
730
707
/// * num - The float value
731
- ///
732
708
#[ inline]
733
709
pub fn to_str_hex ( num : f32 ) -> ~str {
734
710
let ( r, _) = strconv:: float_to_str_common (
735
- num, 16 u, true , strconv:: SignNeg , strconv:: DigAll ) ;
711
+ num, 16 u, true , strconv:: SignNeg , strconv:: DigAll , strconv :: ExpNone , false ) ;
736
712
r
737
713
}
738
714
739
- ///
740
715
/// Converts a float to a string in a given radix, and a flag indicating
741
716
/// whether it's a special value
742
717
///
743
718
/// # Arguments
744
719
///
745
720
/// * num - The float value
746
721
/// * radix - The base to use
747
- ///
748
722
#[ inline]
749
723
pub fn to_str_radix_special ( num : f32 , rdx : uint ) -> ( ~str , bool ) {
750
724
strconv:: float_to_str_common ( num, rdx, true ,
751
- strconv:: SignNeg , strconv:: DigAll )
725
+ strconv:: SignNeg , strconv:: DigAll , strconv :: ExpNone , false )
752
726
}
753
727
754
- ///
755
728
/// Converts a float to a string with exactly the number of
756
729
/// provided significant digits
757
730
///
758
731
/// # Arguments
759
732
///
760
733
/// * num - The float value
761
734
/// * digits - The number of significant digits
762
- ///
763
735
#[ inline]
764
736
pub fn to_str_exact ( num : f32 , dig : uint ) -> ~str {
765
737
let ( r, _) = strconv:: float_to_str_common (
766
- num, 10 u, true , strconv:: SignNeg , strconv:: DigExact ( dig) ) ;
738
+ num, 10 u, true , strconv:: SignNeg , strconv:: DigExact ( dig) , strconv :: ExpNone , false ) ;
767
739
r
768
740
}
769
741
770
- ///
771
742
/// Converts a float to a string with a maximum number of
772
743
/// significant digits
773
744
///
774
745
/// # Arguments
775
746
///
776
747
/// * num - The float value
777
748
/// * digits - The number of significant digits
778
- ///
779
749
#[ inline]
780
750
pub fn to_str_digits ( num : f32 , dig : uint ) -> ~str {
781
751
let ( r, _) = strconv:: float_to_str_common (
782
- num, 10 u, true , strconv:: SignNeg , strconv:: DigMax ( dig) ) ;
752
+ num, 10 u, true , strconv:: SignNeg , strconv:: DigMax ( dig) , strconv:: ExpNone , false ) ;
753
+ r
754
+ }
755
+
756
+ /// Converts a float to a string using the exponential notation with exactly the number of
757
+ /// provided digits after the decimal point in the significand
758
+ ///
759
+ /// # Arguments
760
+ ///
761
+ /// * num - The float value
762
+ /// * digits - The number of digits after the decimal point
763
+ /// * upper - Use `E` instead of `e` for the exponent sign
764
+ #[ inline]
765
+ pub fn to_str_exp_exact ( num : f32 , dig : uint , upper : bool ) -> ~str {
766
+ let ( r, _) = strconv:: float_to_str_common (
767
+ num, 10 u, true , strconv:: SignNeg , strconv:: DigExact ( dig) , strconv:: ExpDec , upper) ;
768
+ r
769
+ }
770
+
771
+ /// Converts a float to a string using the exponential notation with the maximum number of
772
+ /// digits after the decimal point in the significand
773
+ ///
774
+ /// # Arguments
775
+ ///
776
+ /// * num - The float value
777
+ /// * digits - The number of digits after the decimal point
778
+ /// * upper - Use `E` instead of `e` for the exponent sign
779
+ #[ inline]
780
+ pub fn to_str_exp_digits ( num : f32 , dig : uint , upper : bool ) -> ~str {
781
+ let ( r, _) = strconv:: float_to_str_common (
782
+ num, 10 u, true , strconv:: SignNeg , strconv:: DigMax ( dig) , strconv:: ExpDec , upper) ;
783
783
r
784
784
}
785
785
@@ -804,14 +804,13 @@ impl num::ToStrRadix for f32 {
804
804
#[ inline]
805
805
fn to_str_radix ( & self , rdx : uint ) -> ~str {
806
806
let ( r, special) = strconv:: float_to_str_common (
807
- * self , rdx, true , strconv:: SignNeg , strconv:: DigAll ) ;
807
+ * self , rdx, true , strconv:: SignNeg , strconv:: DigAll , strconv :: ExpNone , false ) ;
808
808
if special { fail ! ( "number has a special value, \
809
809
try to_str_radix_special() if those are expected") }
810
810
r
811
811
}
812
812
}
813
813
814
- ///
815
814
/// Convert a string in base 16 to a float.
816
815
/// Accepts a optional binary exponent.
817
816
///
@@ -837,15 +836,13 @@ impl num::ToStrRadix for f32 {
837
836
///
838
837
/// `None` if the string did not represent a valid number. Otherwise,
839
838
/// `Some(n)` where `n` is the floating-point number represented by `[num]`.
840
- ///
841
839
#[ inline]
842
840
pub fn from_str_hex ( num : & str ) -> Option < f32 > {
843
841
strconv:: from_str_common ( num, 16 u, true , true , true ,
844
842
strconv:: ExpBin , false , false )
845
843
}
846
844
847
845
impl FromStr for f32 {
848
- ///
849
846
/// Convert a string in base 10 to a float.
850
847
/// Accepts a optional decimal exponent.
851
848
///
@@ -871,7 +868,6 @@ impl FromStr for f32 {
871
868
///
872
869
/// `None` if the string did not represent a valid number. Otherwise,
873
870
/// `Some(n)` where `n` is the floating-point number represented by `num`.
874
- ///
875
871
#[ inline]
876
872
fn from_str ( val : & str ) -> Option < f32 > {
877
873
strconv:: from_str_common ( val, 10 u, true , true , true ,
@@ -880,7 +876,6 @@ impl FromStr for f32 {
880
876
}
881
877
882
878
impl num:: FromStrRadix for f32 {
883
- ///
884
879
/// Convert a string in an given base to a float.
885
880
///
886
881
/// Due to possible conflicts, this function does **not** accept
@@ -898,7 +893,6 @@ impl num::FromStrRadix for f32 {
898
893
///
899
894
/// `None` if the string did not represent a valid number. Otherwise,
900
895
/// `Some(n)` where `n` is the floating-point number represented by `num`.
901
- ///
902
896
#[ inline]
903
897
fn from_str_radix ( val : & str , rdx : uint ) -> Option < f32 > {
904
898
strconv:: from_str_common ( val, rdx, true , true , false ,
0 commit comments