@@ -14,15 +14,15 @@ use crate::intrinsics;
1414use crate :: sys:: cmath;
1515
1616#[ stable( feature = "rust1" , since = "1.0.0" ) ]
17- pub use core:: f32:: { RADIX , MANTISSA_DIGITS , DIGITS , EPSILON } ;
17+ pub use core:: f32:: consts ;
1818#[ stable( feature = "rust1" , since = "1.0.0" ) ]
19- pub use core:: f32:: { MIN_EXP , MAX_EXP , MIN_10_EXP } ;
19+ pub use core:: f32:: { DIGITS , EPSILON , MANTISSA_DIGITS , RADIX } ;
2020#[ stable( feature = "rust1" , since = "1.0.0" ) ]
21- pub use core:: f32:: { MAX_10_EXP , NAN , INFINITY , NEG_INFINITY } ;
21+ pub use core:: f32:: { INFINITY , MAX_10_EXP , NAN , NEG_INFINITY } ;
2222#[ stable( feature = "rust1" , since = "1.0.0" ) ]
23- pub use core:: f32:: { MIN , MIN_POSITIVE , MAX } ;
23+ pub use core:: f32:: { MAX , MIN , MIN_POSITIVE } ;
2424#[ stable( feature = "rust1" , since = "1.0.0" ) ]
25- pub use core:: f32:: consts ;
25+ pub use core:: f32:: { MAX_EXP , MIN_10_EXP , MIN_EXP } ;
2626
2727#[ cfg( not( test) ) ]
2828#[ lang = "f32_runtime" ]
@@ -142,7 +142,9 @@ impl f32 {
142142 #[ must_use = "method returns a new number and does not mutate the original value" ]
143143 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
144144 #[ inline]
145- pub fn fract ( self ) -> f32 { self - self . trunc ( ) }
145+ pub fn fract ( self ) -> f32 {
146+ self - self . trunc ( )
147+ }
146148
147149 /// Computes the absolute value of `self`. Returns `NAN` if the
148150 /// number is `NAN`.
@@ -192,11 +194,7 @@ impl f32 {
192194 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
193195 #[ inline]
194196 pub fn signum ( self ) -> f32 {
195- if self . is_nan ( ) {
196- NAN
197- } else {
198- 1.0_f32 . copysign ( self )
199- }
197+ if self . is_nan ( ) { NAN } else { 1.0_f32 . copysign ( self ) }
200198 }
201199
202200 /// Returns a number composed of the magnitude of `self` and the sign of
@@ -277,7 +275,7 @@ impl f32 {
277275 pub fn div_euclid ( self , rhs : f32 ) -> f32 {
278276 let q = ( self / rhs) . trunc ( ) ;
279277 if self % rhs < 0.0 {
280- return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }
278+ return if rhs > 0.0 { q - 1.0 } else { q + 1.0 } ;
281279 }
282280 q
283281 }
@@ -310,14 +308,9 @@ impl f32 {
310308 #[ stable( feature = "euclidean_division" , since = "1.38.0" ) ]
311309 pub fn rem_euclid ( self , rhs : f32 ) -> f32 {
312310 let r = self % rhs;
313- if r < 0.0 {
314- r + rhs. abs ( )
315- } else {
316- r
317- }
311+ if r < 0.0 { r + rhs. abs ( ) } else { r }
318312 }
319313
320-
321314 /// Raises a number to an integer power.
322315 ///
323316 /// Using this function is generally faster than using `powf`
@@ -383,11 +376,7 @@ impl f32 {
383376 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
384377 #[ inline]
385378 pub fn sqrt ( self ) -> f32 {
386- if self < 0.0 {
387- NAN
388- } else {
389- unsafe { intrinsics:: sqrtf32 ( self ) }
390- }
379+ if self < 0.0 { NAN } else { unsafe { intrinsics:: sqrtf32 ( self ) } }
391380 }
392381
393382 /// Returns `e^(self)`, (the exponential function).
@@ -486,7 +475,9 @@ impl f32 {
486475 #[ must_use = "method returns a new number and does not mutate the original value" ]
487476 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
488477 #[ inline]
489- pub fn log ( self , base : f32 ) -> f32 { self . ln ( ) / base. ln ( ) }
478+ pub fn log ( self , base : f32 ) -> f32 {
479+ self . ln ( ) / base. ln ( )
480+ }
490481
491482 /// Returns the base 2 logarithm of the number.
492483 ///
@@ -559,14 +550,16 @@ impl f32 {
559550 #[ must_use = "method returns a new number and does not mutate the original value" ]
560551 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
561552 #[ inline]
562- #[ rustc_deprecated( since = "1.10.0" ,
563- reason = "you probably meant `(self - other).abs()`: \
564- this operation is `(self - other).max(0.0)` \
565- except that `abs_sub` also propagates NaNs (also \
566- known as `fdimf` in C). If you truly need the positive \
567- difference, consider using that expression or the C function \
568- `fdimf`, depending on how you wish to handle NaN (please consider \
569- filing an issue describing your use-case too).") ]
553+ #[ rustc_deprecated(
554+ since = "1.10.0" ,
555+ reason = "you probably meant `(self - other).abs()`: \
556+ this operation is `(self - other).max(0.0)` \
557+ except that `abs_sub` also propagates NaNs (also \
558+ known as `fdimf` in C). If you truly need the positive \
559+ difference, consider using that expression or the C function \
560+ `fdimf`, depending on how you wish to handle NaN (please consider \
561+ filing an issue describing your use-case too)."
562+ ) ]
570563 pub fn abs_sub ( self , other : f32 ) -> f32 {
571564 unsafe { cmath:: fdimf ( self , other) }
572565 }
@@ -967,11 +960,7 @@ impl f32 {
967960 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
968961 #[ inline]
969962 pub fn acosh ( self ) -> f32 {
970- if self < 1.0 {
971- crate :: f32:: NAN
972- } else {
973- ( self + ( ( self * self ) - 1.0 ) . sqrt ( ) ) . ln ( )
974- }
963+ if self < 1.0 { crate :: f32:: NAN } else { ( self + ( ( self * self ) - 1.0 ) . sqrt ( ) ) . ln ( ) }
975964 }
976965
977966 /// Inverse hyperbolic tangent function.
@@ -1022,19 +1011,22 @@ impl f32 {
10221011 pub fn clamp ( self , min : f32 , max : f32 ) -> f32 {
10231012 assert ! ( min <= max) ;
10241013 let mut x = self ;
1025- if x < min { x = min; }
1026- if x > max { x = max; }
1014+ if x < min {
1015+ x = min;
1016+ }
1017+ if x > max {
1018+ x = max;
1019+ }
10271020 x
10281021 }
1029-
10301022}
10311023
10321024#[ cfg( test) ]
10331025mod tests {
10341026 use crate :: f32;
10351027 use crate :: f32:: * ;
1036- use crate :: num:: * ;
10371028 use crate :: num:: FpCategory as Fp ;
1029+ use crate :: num:: * ;
10381030
10391031 #[ test]
10401032 fn test_num_f32 ( ) {
@@ -1279,7 +1271,7 @@ mod tests {
12791271 assert_eq ! ( ( -0f32 ) . abs( ) , 0f32 ) ;
12801272 assert_eq ! ( ( -1f32 ) . abs( ) , 1f32 ) ;
12811273 assert_eq ! ( NEG_INFINITY . abs( ) , INFINITY ) ;
1282- assert_eq ! ( ( 1f32 / NEG_INFINITY ) . abs( ) , 0f32 ) ;
1274+ assert_eq ! ( ( 1f32 / NEG_INFINITY ) . abs( ) , 0f32 ) ;
12831275 assert ! ( NAN . abs( ) . is_nan( ) ) ;
12841276 }
12851277
@@ -1291,7 +1283,7 @@ mod tests {
12911283 assert_eq ! ( ( -0f32 ) . signum( ) , -1f32 ) ;
12921284 assert_eq ! ( ( -1f32 ) . signum( ) , -1f32 ) ;
12931285 assert_eq ! ( NEG_INFINITY . signum( ) , -1f32 ) ;
1294- assert_eq ! ( ( 1f32 / NEG_INFINITY ) . signum( ) , -1f32 ) ;
1286+ assert_eq ! ( ( 1f32 / NEG_INFINITY ) . signum( ) , -1f32 ) ;
12951287 assert ! ( NAN . signum( ) . is_nan( ) ) ;
12961288 }
12971289
@@ -1303,7 +1295,7 @@ mod tests {
13031295 assert ! ( !( -0f32 ) . is_sign_positive( ) ) ;
13041296 assert ! ( !( -1f32 ) . is_sign_positive( ) ) ;
13051297 assert ! ( !NEG_INFINITY . is_sign_positive( ) ) ;
1306- assert ! ( !( 1f32 / NEG_INFINITY ) . is_sign_positive( ) ) ;
1298+ assert ! ( !( 1f32 / NEG_INFINITY ) . is_sign_positive( ) ) ;
13071299 assert ! ( NAN . is_sign_positive( ) ) ;
13081300 assert ! ( !( -NAN ) . is_sign_positive( ) ) ;
13091301 }
@@ -1316,7 +1308,7 @@ mod tests {
13161308 assert ! ( ( -0f32 ) . is_sign_negative( ) ) ;
13171309 assert ! ( ( -1f32 ) . is_sign_negative( ) ) ;
13181310 assert ! ( NEG_INFINITY . is_sign_negative( ) ) ;
1319- assert ! ( ( 1f32 / NEG_INFINITY ) . is_sign_negative( ) ) ;
1311+ assert ! ( ( 1f32 / NEG_INFINITY ) . is_sign_negative( ) ) ;
13201312 assert ! ( !NAN . is_sign_negative( ) ) ;
13211313 assert ! ( ( -NAN ) . is_sign_negative( ) ) ;
13221314 }
0 commit comments