@@ -14,15 +14,15 @@ use crate::intrinsics;
14
14
use crate :: sys:: cmath;
15
15
16
16
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
17
- pub use core:: f32:: { RADIX , MANTISSA_DIGITS , DIGITS , EPSILON } ;
17
+ pub use core:: f32:: consts ;
18
18
#[ 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 } ;
20
20
#[ 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 } ;
22
22
#[ 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 } ;
24
24
#[ 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 } ;
26
26
27
27
#[ cfg( not( test) ) ]
28
28
#[ lang = "f32_runtime" ]
@@ -142,7 +142,9 @@ impl f32 {
142
142
#[ must_use = "method returns a new number and does not mutate the original value" ]
143
143
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
144
144
#[ inline]
145
- pub fn fract ( self ) -> f32 { self - self . trunc ( ) }
145
+ pub fn fract ( self ) -> f32 {
146
+ self - self . trunc ( )
147
+ }
146
148
147
149
/// Computes the absolute value of `self`. Returns `NAN` if the
148
150
/// number is `NAN`.
@@ -192,11 +194,7 @@ impl f32 {
192
194
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
193
195
#[ inline]
194
196
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 ) }
200
198
}
201
199
202
200
/// Returns a number composed of the magnitude of `self` and the sign of
@@ -277,7 +275,7 @@ impl f32 {
277
275
pub fn div_euclid ( self , rhs : f32 ) -> f32 {
278
276
let q = ( self / rhs) . trunc ( ) ;
279
277
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 } ;
281
279
}
282
280
q
283
281
}
@@ -310,14 +308,9 @@ impl f32 {
310
308
#[ stable( feature = "euclidean_division" , since = "1.38.0" ) ]
311
309
pub fn rem_euclid ( self , rhs : f32 ) -> f32 {
312
310
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 }
318
312
}
319
313
320
-
321
314
/// Raises a number to an integer power.
322
315
///
323
316
/// Using this function is generally faster than using `powf`
@@ -383,11 +376,7 @@ impl f32 {
383
376
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
384
377
#[ inline]
385
378
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 ) } }
391
380
}
392
381
393
382
/// Returns `e^(self)`, (the exponential function).
@@ -486,7 +475,9 @@ impl f32 {
486
475
#[ must_use = "method returns a new number and does not mutate the original value" ]
487
476
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
488
477
#[ 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
+ }
490
481
491
482
/// Returns the base 2 logarithm of the number.
492
483
///
@@ -559,14 +550,16 @@ impl f32 {
559
550
#[ must_use = "method returns a new number and does not mutate the original value" ]
560
551
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
561
552
#[ 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
+ ) ]
570
563
pub fn abs_sub ( self , other : f32 ) -> f32 {
571
564
unsafe { cmath:: fdimf ( self , other) }
572
565
}
@@ -967,11 +960,7 @@ impl f32 {
967
960
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
968
961
#[ inline]
969
962
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 ( ) }
975
964
}
976
965
977
966
/// Inverse hyperbolic tangent function.
@@ -1022,19 +1011,22 @@ impl f32 {
1022
1011
pub fn clamp ( self , min : f32 , max : f32 ) -> f32 {
1023
1012
assert ! ( min <= max) ;
1024
1013
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
+ }
1027
1020
x
1028
1021
}
1029
-
1030
1022
}
1031
1023
1032
1024
#[ cfg( test) ]
1033
1025
mod tests {
1034
1026
use crate :: f32;
1035
1027
use crate :: f32:: * ;
1036
- use crate :: num:: * ;
1037
1028
use crate :: num:: FpCategory as Fp ;
1029
+ use crate :: num:: * ;
1038
1030
1039
1031
#[ test]
1040
1032
fn test_num_f32 ( ) {
@@ -1279,7 +1271,7 @@ mod tests {
1279
1271
assert_eq ! ( ( -0f32 ) . abs( ) , 0f32 ) ;
1280
1272
assert_eq ! ( ( -1f32 ) . abs( ) , 1f32 ) ;
1281
1273
assert_eq ! ( NEG_INFINITY . abs( ) , INFINITY ) ;
1282
- assert_eq ! ( ( 1f32 / NEG_INFINITY ) . abs( ) , 0f32 ) ;
1274
+ assert_eq ! ( ( 1f32 / NEG_INFINITY ) . abs( ) , 0f32 ) ;
1283
1275
assert ! ( NAN . abs( ) . is_nan( ) ) ;
1284
1276
}
1285
1277
@@ -1291,7 +1283,7 @@ mod tests {
1291
1283
assert_eq ! ( ( -0f32 ) . signum( ) , -1f32 ) ;
1292
1284
assert_eq ! ( ( -1f32 ) . signum( ) , -1f32 ) ;
1293
1285
assert_eq ! ( NEG_INFINITY . signum( ) , -1f32 ) ;
1294
- assert_eq ! ( ( 1f32 / NEG_INFINITY ) . signum( ) , -1f32 ) ;
1286
+ assert_eq ! ( ( 1f32 / NEG_INFINITY ) . signum( ) , -1f32 ) ;
1295
1287
assert ! ( NAN . signum( ) . is_nan( ) ) ;
1296
1288
}
1297
1289
@@ -1303,7 +1295,7 @@ mod tests {
1303
1295
assert ! ( !( -0f32 ) . is_sign_positive( ) ) ;
1304
1296
assert ! ( !( -1f32 ) . is_sign_positive( ) ) ;
1305
1297
assert ! ( !NEG_INFINITY . is_sign_positive( ) ) ;
1306
- assert ! ( !( 1f32 / NEG_INFINITY ) . is_sign_positive( ) ) ;
1298
+ assert ! ( !( 1f32 / NEG_INFINITY ) . is_sign_positive( ) ) ;
1307
1299
assert ! ( NAN . is_sign_positive( ) ) ;
1308
1300
assert ! ( !( -NAN ) . is_sign_positive( ) ) ;
1309
1301
}
@@ -1316,7 +1308,7 @@ mod tests {
1316
1308
assert ! ( ( -0f32 ) . is_sign_negative( ) ) ;
1317
1309
assert ! ( ( -1f32 ) . is_sign_negative( ) ) ;
1318
1310
assert ! ( NEG_INFINITY . is_sign_negative( ) ) ;
1319
- assert ! ( ( 1f32 / NEG_INFINITY ) . is_sign_negative( ) ) ;
1311
+ assert ! ( ( 1f32 / NEG_INFINITY ) . is_sign_negative( ) ) ;
1320
1312
assert ! ( !NAN . is_sign_negative( ) ) ;
1321
1313
assert ! ( ( -NAN ) . is_sign_negative( ) ) ;
1322
1314
}
0 commit comments