@@ -536,23 +536,21 @@ impl<S: Semantics> fmt::Display for IeeeFloat<S> {
536
536
// Check whether we should use scientific notation.
537
537
let scientific = if width == 0 {
538
538
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
539
544
} 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
545
550
} 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
556
554
}
557
555
} ;
558
556
@@ -702,7 +700,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
702
700
// exponent = 1..10
703
701
// significand = 1..1
704
702
IeeeFloat {
705
- sig : [ ! 0 & ( ( 1 << S :: PRECISION ) - 1 ) ] ,
703
+ sig : [ ( 1 << S :: PRECISION ) - 1 ] ,
706
704
exp : S :: MAX_EXP ,
707
705
category : Category :: Normal ,
708
706
sign : false ,
@@ -1507,10 +1505,11 @@ impl<S: Semantics, T: Semantics> FloatConvert<IeeeFloat<T>> for IeeeFloat<S> {
1507
1505
}
1508
1506
1509
1507
// 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
+ } ;
1514
1513
1515
1514
// If this is an extension, perform the shift.
1516
1515
if shift > 0 && ( r. is_finite_non_zero ( ) || r. category == Category :: NaN ) {
@@ -1738,27 +1737,25 @@ impl<S: Semantics> IeeeFloat<S> {
1738
1737
bit_pos -= 4 ;
1739
1738
if bit_pos >= 0 {
1740
1739
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 ;
1752
1749
}
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
- } ) ;
1761
1750
}
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
+ } ) ;
1762
1759
}
1763
1760
} else if c == 'p' || c == 'P' {
1764
1761
if !any_digits {
@@ -2309,9 +2306,9 @@ mod sig {
2309
2306
2310
2307
/// One, not zero, based LSB. That is, returns 0 for a zeroed significand.
2311
2308
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 ;
2315
2312
}
2316
2313
}
2317
2314
@@ -2320,9 +2317,9 @@ mod sig {
2320
2317
2321
2318
/// One, not zero, based MSB. That is, returns 0 for a zeroed significand.
2322
2319
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 ;
2326
2323
}
2327
2324
}
2328
2325
@@ -2378,7 +2375,7 @@ mod sig {
2378
2375
limb = dst[ i - jump] ;
2379
2376
if shift > 0 {
2380
2377
limb <<= shift;
2381
- if i >= jump + 1 {
2378
+ if i > jump {
2382
2379
limb |= dst[ i - jump - 1 ] >> ( LIMB_BITS - shift) ;
2383
2380
}
2384
2381
}
@@ -2448,7 +2445,7 @@ mod sig {
2448
2445
let n = dst_limbs * LIMB_BITS - shift;
2449
2446
if n < src_bits {
2450
2447
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 ) ;
2452
2449
} else if n > src_bits && src_bits % LIMB_BITS > 0 {
2453
2450
dst[ dst_limbs - 1 ] &= ( 1 << ( src_bits % LIMB_BITS ) ) - 1 ;
2454
2451
}
0 commit comments