@@ -536,23 +536,21 @@ impl<S: Semantics> fmt::Display for IeeeFloat<S> {
536536 // Check whether we should use scientific notation.
537537 let scientific = if width == 0 {
538538 true
539+ } else if exp >= 0 {
540+ // 765e3 --> 765000
541+ // ^^^
542+ // But we shouldn't make the number look more precise than it is.
543+ exp as usize > width || digits + exp as usize > precision
539544 } else {
540- if exp >= 0 {
541- // 765e3 --> 765000
542- // ^^^
543- // But we shouldn't make the number look more precise than it is.
544- exp as usize > width || digits + exp as usize > precision
545+ // Power of the most significant digit.
546+ let msd = exp + ( digits - 1 ) as ExpInt ;
547+ if msd >= 0 {
548+ // 765e-2 == 7.65
549+ false
545550 } else {
546- // Power of the most significant digit.
547- let msd = exp + ( digits - 1 ) as ExpInt ;
548- if msd >= 0 {
549- // 765e-2 == 7.65
550- false
551- } else {
552- // 765e-5 == 0.00765
553- // ^ ^^
554- -msd as usize > width
555- }
551+ // 765e-5 == 0.00765
552+ // ^ ^^
553+ -msd as usize > width
556554 }
557555 } ;
558556
@@ -702,7 +700,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
702700 // exponent = 1..10
703701 // significand = 1..1
704702 IeeeFloat {
705- sig : [ ! 0 & ( ( 1 << S :: PRECISION ) - 1 ) ] ,
703+ sig : [ ( 1 << S :: PRECISION ) - 1 ] ,
706704 exp : S :: MAX_EXP ,
707705 category : Category :: Normal ,
708706 sign : false ,
@@ -1507,10 +1505,11 @@ impl<S: Semantics, T: Semantics> FloatConvert<IeeeFloat<T>> for IeeeFloat<S> {
15071505 }
15081506
15091507 // If this is a truncation, perform the shift.
1510- let mut loss = Loss :: ExactlyZero ;
1511- if shift < 0 && ( r. is_finite_non_zero ( ) || r. category == Category :: NaN ) {
1512- loss = sig:: shift_right ( & mut r. sig , & mut 0 , -shift as usize ) ;
1513- }
1508+ let loss = if shift < 0 && ( r. is_finite_non_zero ( ) || r. category == Category :: NaN ) {
1509+ sig:: shift_right ( & mut r. sig , & mut 0 , -shift as usize )
1510+ } else {
1511+ Loss :: ExactlyZero
1512+ } ;
15141513
15151514 // If this is an extension, perform the shift.
15161515 if shift > 0 && ( r. is_finite_non_zero ( ) || r. category == Category :: NaN ) {
@@ -1738,27 +1737,25 @@ impl<S: Semantics> IeeeFloat<S> {
17381737 bit_pos -= 4 ;
17391738 if bit_pos >= 0 {
17401739 r. sig [ 0 ] |= ( hex_value as Limb ) << bit_pos;
1741- } else {
1742- // If zero or one-half (the hexadecimal digit 8) are followed
1743- // by non-zero, they're a little more than zero or one-half.
1744- if let Some ( ref mut loss) = loss {
1745- if hex_value != 0 {
1746- if * loss == Loss :: ExactlyZero {
1747- * loss = Loss :: LessThanHalf ;
1748- }
1749- if * loss == Loss :: ExactlyHalf {
1750- * loss = Loss :: MoreThanHalf ;
1751- }
1740+ // If zero or one-half (the hexadecimal digit 8) are followed
1741+ // by non-zero, they're a little more than zero or one-half.
1742+ } else if let Some ( ref mut loss) = loss {
1743+ if hex_value != 0 {
1744+ if * loss == Loss :: ExactlyZero {
1745+ * loss = Loss :: LessThanHalf ;
1746+ }
1747+ if * loss == Loss :: ExactlyHalf {
1748+ * loss = Loss :: MoreThanHalf ;
17521749 }
1753- } else {
1754- loss = Some ( match hex_value {
1755- 0 => Loss :: ExactlyZero ,
1756- 1 ..=7 => Loss :: LessThanHalf ,
1757- 8 => Loss :: ExactlyHalf ,
1758- 9 ..=15 => Loss :: MoreThanHalf ,
1759- _ => unreachable ! ( ) ,
1760- } ) ;
17611750 }
1751+ } else {
1752+ loss = Some ( match hex_value {
1753+ 0 => Loss :: ExactlyZero ,
1754+ 1 ..=7 => Loss :: LessThanHalf ,
1755+ 8 => Loss :: ExactlyHalf ,
1756+ 9 ..=15 => Loss :: MoreThanHalf ,
1757+ _ => unreachable ! ( ) ,
1758+ } ) ;
17621759 }
17631760 } else if c == 'p' || c == 'P' {
17641761 if !any_digits {
@@ -2309,9 +2306,9 @@ mod sig {
23092306
23102307 /// One, not zero, based LSB. That is, returns 0 for a zeroed significand.
23112308 pub ( super ) fn olsb ( limbs : & [ Limb ] ) -> usize {
2312- for i in 0 .. limbs. len ( ) {
2313- if limbs [ i ] != 0 {
2314- return i * LIMB_BITS + limbs [ i ] . trailing_zeros ( ) as usize + 1 ;
2309+ for ( i , & limb ) in limbs. iter ( ) . enumerate ( ) {
2310+ if limb != 0 {
2311+ return i * LIMB_BITS + limb . trailing_zeros ( ) as usize + 1 ;
23152312 }
23162313 }
23172314
@@ -2320,9 +2317,9 @@ mod sig {
23202317
23212318 /// One, not zero, based MSB. That is, returns 0 for a zeroed significand.
23222319 pub ( super ) fn omsb ( limbs : & [ Limb ] ) -> usize {
2323- for i in ( 0 .. limbs. len ( ) ) . rev ( ) {
2324- if limbs [ i ] != 0 {
2325- return ( i + 1 ) * LIMB_BITS - limbs [ i ] . leading_zeros ( ) as usize ;
2320+ for ( i , & limb ) in limbs. iter ( ) . enumerate ( ) . rev ( ) {
2321+ if limb != 0 {
2322+ return ( i + 1 ) * LIMB_BITS - limb . leading_zeros ( ) as usize ;
23262323 }
23272324 }
23282325
@@ -2378,7 +2375,7 @@ mod sig {
23782375 limb = dst[ i - jump] ;
23792376 if shift > 0 {
23802377 limb <<= shift;
2381- if i >= jump + 1 {
2378+ if i > jump {
23822379 limb |= dst[ i - jump - 1 ] >> ( LIMB_BITS - shift) ;
23832380 }
23842381 }
@@ -2448,7 +2445,7 @@ mod sig {
24482445 let n = dst_limbs * LIMB_BITS - shift;
24492446 if n < src_bits {
24502447 let mask = ( 1 << ( src_bits - n) ) - 1 ;
2451- dst[ dst_limbs - 1 ] |= ( src[ dst_limbs] & mask) << n % LIMB_BITS ;
2448+ dst[ dst_limbs - 1 ] |= ( src[ dst_limbs] & mask) << ( n % LIMB_BITS ) ;
24522449 } else if n > src_bits && src_bits % LIMB_BITS > 0 {
24532450 dst[ dst_limbs - 1 ] &= ( 1 << ( src_bits % LIMB_BITS ) ) - 1 ;
24542451 }
0 commit comments