@@ -1858,23 +1858,24 @@ extension BinaryFloatingPoint {
1858
1858
if source. significandWidth <= leadingBitIndex {
1859
1859
return ( value, true )
1860
1860
}
1861
- // We promise to round to the closest representation, and if two
1862
- // representable values are equally close, the value with more trailing
1863
- // zeros in its significand bit pattern. Therefore, we must take a look at
1864
- // the bits that we've just truncated.
1861
+ // We promise to round to the closest representation. Therefore, we must
1862
+ // take a look at the bits that we've just truncated.
1865
1863
let ulp = ( 1 as Source . RawSignificand) << - shift
1866
1864
let truncatedBits = source. significandBitPattern & ( ulp - 1 )
1867
1865
if truncatedBits < ulp / 2 {
1868
1866
return ( value, false )
1869
1867
}
1870
1868
let rounded = source. sign == . minus ? value. nextDown : value. nextUp
1871
- guard _fastPath (
1872
- truncatedBits != ulp / 2 ||
1873
- exponentBitPattern. trailingZeroBitCount <
1874
- rounded. exponentBitPattern. trailingZeroBitCount) else {
1875
- return ( value, false )
1869
+ if _fastPath ( truncatedBits > ulp / 2 ) {
1870
+ return ( rounded, false )
1876
1871
}
1877
- return ( rounded, false )
1872
+ // If two representable values are equally close, we return the value with
1873
+ // more trailing zeros in its significand bit pattern.
1874
+ return
1875
+ significandBitPattern. trailingZeroBitCount >
1876
+ rounded. significandBitPattern. trailingZeroBitCount
1877
+ ? ( value, false )
1878
+ : ( rounded, false )
1878
1879
}
1879
1880
1880
1881
/// Creates a new instance from the given value, rounded to the closest
0 commit comments