@@ -625,16 +625,7 @@ extension ${Self}: BinaryFloatingPoint {
625
625
/// almost never is.
626
626
@_inlineable // FIXME(sil-serialize-all)
627
627
public var ulp : ${ Self} {
628
- % if bits != 80 :
629
- guard _fastPath ( isFinite) else { return . nan }
630
- if _fastPath ( isNormal) {
631
- let bitPattern_ = bitPattern & ${ Self} . infinity. bitPattern
632
- return ${ Self} ( bitPattern: bitPattern_) * 0x1 p- ${ SignificandBitCount}
633
- }
634
- // On arm, flush subnormal values to 0.
635
- return . leastNormalMagnitude * 0x1 p- ${ SignificandBitCount}
636
- % else :
637
- guard _fastPath ( isFinite) else { return . nan }
628
+ if !isFinite { return ${ Self} . nan }
638
629
if exponentBitPattern > UInt ( ${ Self} . significandBitCount) {
639
630
// self is large enough that self.ulp is normal, so we just compute its
640
631
// exponent and construct it with a significand of zero.
@@ -654,7 +645,6 @@ extension ${Self}: BinaryFloatingPoint {
654
645
return ${ Self} ( sign: . plus,
655
646
exponentBitPattern: 0 ,
656
647
significandBitPattern: 1 )
657
- % end
658
648
}
659
649
660
650
/// The least positive normal number.
@@ -927,23 +917,17 @@ extension ${Self}: BinaryFloatingPoint {
927
917
/// - If `x` is `greatestFiniteMagnitude`, then `x.nextUp` is `infinity`.
928
918
@_inlineable // FIXME(sil-serialize-all)
929
919
public var nextUp : ${ Self} {
930
- % if bits != 80 :
931
- // Silence signaling NaNs, map -0 to +0.
932
- let x = self + 0
920
+ if isNaN { return self }
921
+ if sign == . minus {
933
922
#if arch(arm)
934
- // On arm, treat subnormal values as zero.
935
- if _slowPath ( x == 0 ) { return . leastNonzeroMagnitude }
936
- if _slowPath ( x == - . leastNonzeroMagnitude) { return - 0.0 }
923
+ // On arm, subnormals are flushed to zero.
924
+ if ( exponentBitPattern == 1 && significandBitPattern == 0 ) ||
925
+ ( exponentBitPattern == 0 && significandBitPattern != 0 ) {
926
+ return ${ Self} ( sign: . minus,
927
+ exponentBitPattern: 0 ,
928
+ significandBitPattern: 0 )
929
+ }
937
930
#endif
938
- if _fastPath ( x < . infinity) {
939
- let increment = Int ${ bits} ( bitPattern: x. bitPattern) &>> ${ bits - 1 } | 1
940
- let bitPattern_ = x. bitPattern &+ UInt${ bits} ( bitPattern: increment)
941
- return ${ Self} ( bitPattern: bitPattern_)
942
- }
943
- return x
944
- % else :
945
- if isNaN { /* Silence signaling NaNs. */ return self + 0 }
946
- if sign == . minus {
947
931
if significandBitPattern == 0 {
948
932
if exponentBitPattern == 0 {
949
933
return . leastNonzeroMagnitude
@@ -962,10 +946,15 @@ extension ${Self}: BinaryFloatingPoint {
962
946
exponentBitPattern: exponentBitPattern + 1 ,
963
947
significandBitPattern: 0 )
964
948
}
949
+ #if arch(arm)
950
+ // On arm, subnormals are skipped.
951
+ if exponentBitPattern == 0 {
952
+ return . leastNonzeroMagnitude
953
+ }
954
+ #endif
965
955
return ${ Self} ( sign: . plus,
966
956
exponentBitPattern: exponentBitPattern,
967
957
significandBitPattern: significandBitPattern + 1 )
968
- % end
969
958
}
970
959
971
960
/// Rounds the value to an integral value using the specified rounding rule.
@@ -1380,19 +1369,7 @@ extension ${Self}: BinaryFloatingPoint {
1380
1369
/// // y.exponent == 4
1381
1370
@_inlineable // FIXME(sil-serialize-all)
1382
1371
public var binade : ${ Self} {
1383
- % if bits != 80 :
1384
- guard _fastPath ( isFinite) else { return . nan }
1385
- #if !arch(arm)
1386
- if _slowPath ( isSubnormal) {
1387
- let bitPattern_ =
1388
- ( self * 0x1 p${ SignificandBitCount} ) . bitPattern
1389
- & ( - ${ Self} . infinity) . bitPattern
1390
- return ${ Self} ( bitPattern: bitPattern_) * 0x1 p- ${ SignificandBitCount}
1391
- }
1392
- #endif
1393
- return ${ Self} ( bitPattern: bitPattern & ( - ${ Self} . infinity) . bitPattern)
1394
- % else :
1395
- guard _fastPath ( isFinite) else { return . nan }
1372
+ if !isFinite { return . nan }
1396
1373
if exponentBitPattern != 0 {
1397
1374
return ${ Self} ( sign: sign, exponentBitPattern: exponentBitPattern,
1398
1375
significandBitPattern: 0 )
@@ -1402,7 +1379,6 @@ extension ${Self}: BinaryFloatingPoint {
1402
1379
let index = significandBitPattern. _binaryLogarithm ( )
1403
1380
return ${ Self} ( sign: sign, exponentBitPattern: 0 ,
1404
1381
significandBitPattern: 1 &<< index)
1405
- % end
1406
1382
}
1407
1383
1408
1384
/// The number of bits required to represent the value's significand.
@@ -1514,7 +1490,6 @@ extension ${Self} : _ExpressibleByBuiltinFloatLiteral {
1514
1490
% if bits == builtinFloatLiteralBits:
1515
1491
self = ${ Self} ( _bits: value)
1516
1492
% elif bits < builtinFloatLiteralBits :
1517
- // FIXME: This can result in double rounding errors (SR-7124).
1518
1493
self = ${ Self} ( _bits: Builtin . fptrunc_FPIEEE ${ builtinFloatLiteralBits} _FPIEEE${ bits} ( value) )
1519
1494
% else:
1520
1495
// FIXME: This is actually losing precision <rdar://problem/14073102>.
0 commit comments