@@ -819,8 +819,8 @@ def overflowOperationComment(operator):
819
819
/// - Parameter rhs: The value to add to this value.
820
820
/// - Returns: A tuple containing the result of the addition along with a
821
821
/// flag indicating whether overflow occurred. If the `overflow` component
822
- /// is `.none `, the `partialValue` component contains the entire sum. If
823
- /// the `overflow` component is `.overflow `, an overflow occurred and the
822
+ /// is `false `, the `partialValue` component contains the entire sum. If
823
+ /// the `overflow` component is `true `, an overflow occurred and the
824
824
/// `partialValue` component contains the truncated sum of this value and
825
825
/// `rhs`.
826
826
""" ,
@@ -831,8 +831,8 @@ def overflowOperationComment(operator):
831
831
/// - Parameter rhs: The value to subtract from this value.
832
832
/// - Returns: A tuple containing the result of the subtraction along with a
833
833
/// flag indicating whether overflow occurred. If the `overflow` component
834
- /// is `.none `, the `partialValue` component contains the entire
835
- /// difference. If the `overflow` component is `.overflow `, an overflow
834
+ /// is `false `, the `partialValue` component contains the entire
835
+ /// difference. If the `overflow` component is `true `, an overflow
836
836
/// occurred and the `partialValue` component contains the truncated
837
837
/// result of `rhs` subtracted from this value.
838
838
""" ,
@@ -843,8 +843,8 @@ def overflowOperationComment(operator):
843
843
/// - Parameter rhs: The value to multiply by this value.
844
844
/// - Returns: A tuple containing the result of the multiplication along with
845
845
/// a flag indicating whether overflow occurred. If the `overflow`
846
- /// component is `.none `, the `partialValue` component contains the entire
847
- /// product. If the `overflow` component is `.overflow `, an overflow
846
+ /// component is `false `, the `partialValue` component contains the entire
847
+ /// product. If the `overflow` component is `true `, an overflow
848
848
/// occurred and the `partialValue` component contains the truncated
849
849
/// product of this value and `rhs`.
850
850
""" ,
@@ -853,13 +853,13 @@ def overflowOperationComment(operator):
853
853
/// a flag indicating whether overflow occurred in the operation.
854
854
///
855
855
/// Dividing by zero is not an error when using this method. For a value `x`,
856
- /// the result of `x.dividedReportingOverflow(by: 0)` is `(x, .overflow )`.
856
+ /// the result of `x.dividedReportingOverflow(by: 0)` is `(x, true )`.
857
857
///
858
858
/// - Parameter rhs: The value to divide this value by.
859
859
/// - Returns: A tuple containing the result of the division along with a
860
860
/// flag indicating whether overflow occurred. If the `overflow` component
861
- /// is `.none `, the `partialValue` component contains the entire quotient.
862
- /// If the `overflow` component is `.overflow `, an overflow occurred and
861
+ /// is `false `, the `partialValue` component contains the entire quotient.
862
+ /// If the `overflow` component is `true `, an overflow occurred and
863
863
/// the `partialValue` component contains the truncated quotient.
864
864
""" ,
865
865
'% ': """ \
@@ -868,13 +868,13 @@ def overflowOperationComment(operator):
868
868
/// a flag indicating whether overflow occurred in the operation.
869
869
///
870
870
/// Dividing by zero is not an error when using this method. For a value `x`,
871
- /// the result of `x.dividedReportingOverflow(by: 0)` is `(x, .overflow )`.
871
+ /// the result of `x.dividedReportingOverflow(by: 0)` is `(x, true )`.
872
872
///
873
873
/// - Parameter rhs: The value to divide this value by.
874
874
/// - Returns: A tuple containing the result of the division along with a
875
875
/// flag indicating whether overflow occurred. If the `overflow` component
876
- /// is `.none `, the `partialValue` component contains the entire quotient.
877
- /// If the `overflow` component is `.overflow `, an overflow occurred and
876
+ /// is `false `, the `partialValue` component contains the entire quotient.
877
+ /// If the `overflow` component is `true `, an overflow occurred and
878
878
/// the `partialValue` component contains the truncated quotient.
879
879
""" ,
880
880
}
@@ -1883,28 +1883,6 @@ extension BinaryInteger {
1883
1883
//===--- FixedWidthInteger ------------------------------------------------===//
1884
1884
//===----------------------------------------------------------------------===//
1885
1885
1886
- /// An indicator of whether an arithmetic operation overflowed.
1887
- ///
1888
- /// Some arithmetic operations on fixed-width integers return an
1889
- /// `ArithmeticOverflow` instance to indicate whether an overflow has
1890
- /// occurred. For example, adding `UInt8.max` to itself results in a value that
1891
- /// can't be represented by an `UInt8` instance without overflowing.
1892
- ///
1893
- /// let x = UInt8.max
1894
- /// // x == 255
1895
- /// let (y, overflow) = x.addingReportingOverflow(x)
1896
- /// // y == 254
1897
- /// // overflow == ArithmeticOverflow.overflow
1898
- @_fixed_layout
1899
- public enum ArithmeticOverflow {
1900
- @_transparent
1901
- public init( _ overflow: Bool ) { self = overflow ? . overflow : . none }
1902
- /// An indication that no overflow occurred in the operation.
1903
- case none
1904
- /// An indication that an overflow did occur in the operation.
1905
- case overflow
1906
- }
1907
-
1908
1886
/// An integer type that uses a fixed size for every instance.
1909
1887
///
1910
1888
/// The `FixedWidthInteger` protocol adds binary bitwise operations, bit
@@ -1948,7 +1926,7 @@ public enum ArithmeticOverflow {
1948
1926
///
1949
1927
/// func squared<T: FixedWidthInteger>(_ x: T) -> T? {
1950
1928
/// let (result, overflow) = x.multipliedReportingOverflow(by: x)
1951
- /// guard overflow == .none else {
1929
+ /// if overflow {
1952
1930
/// return nil
1953
1931
/// }
1954
1932
/// return result
@@ -2001,7 +1979,7 @@ public protocol FixedWidthInteger : BinaryInteger, _BitwiseOperations
2001
1979
${ overflowOperationComment ( x. operator) }
2002
1980
func ${ x. name} ReportingOverflow(
2003
1981
${ x. firstArg} rhs: Self
2004
- ) - > ( partialValue: Self, overflow: ArithmeticOverflow )
1982
+ ) - > ( partialValue: Self, overflow: Bool )
2005
1983
% end
2006
1984
2007
1985
/// Returns a tuple containing the high and low parts of the result of
@@ -2267,7 +2245,7 @@ ${assignmentOperatorComment(x.operator, True)}
2267
2245
@_transparent
2268
2246
public static func ${ x. operator} = ( _ lhs: inout Self, _ rhs: Self) {
2269
2247
let ( result, overflow) = lhs . ${ x. name} ReportingOverflow( ${ callLabel} rhs)
2270
- _precondition ( overflow == . none , " Overflow in ${x.operator}= " )
2248
+ _precondition ( ! overflow, " Overflow in ${x.operator}= " )
2271
2249
lhs = result
2272
2250
}
2273
2251
#endif
@@ -2278,7 +2256,7 @@ ${unsafeOperationComment(x.operator)}
2278
2256
public func unsafe${ capitalize ( x. name) } ( ${ x. firstArg} other: Self) - > Self {
2279
2257
let ( result, overflow) = self . ${ x. name} ReportingOverflow( ${ callLabel} other)
2280
2258
2281
- if ( overflow != . none ) {
2259
+ if overflow {
2282
2260
if ( _isDebugAssertConfiguration ( ) ) {
2283
2261
_preconditionFailure ( " overflow in unsafe${capitalize(x.name)} " )
2284
2262
}
@@ -2660,7 +2638,7 @@ public struct ${Self}
2660
2638
@_transparent
2661
2639
public func ${ x. name} ReportingOverflow(
2662
2640
${ x. firstArg} other: ${ Self}
2663
- ) - > ( partialValue: ${ Self} , overflow: ArithmeticOverflow ) {
2641
+ ) - > ( partialValue: ${ Self} , overflow: Bool ) {
2664
2642
2665
2643
% if x. kind == '/ ':
2666
2644
// No LLVM primitives for checking overflow of division
@@ -2669,7 +2647,7 @@ public struct ${Self}
2669
2647
other == ( 0 as ${ Self} )
2670
2648
${ '|| self == % s. min && other == ( - 1 as % s) ' % ( Self, Self) if signed else ''}
2671
2649
) {
2672
- return ( partialValue: self , overflow: . overflow )
2650
+ return ( partialValue: self , overflow: true )
2673
2651
}
2674
2652
2675
2653
let ( newStorage, overflow) = (
@@ -2685,7 +2663,7 @@ public struct ${Self}
2685
2663
2686
2664
return (
2687
2665
partialValue: ${ Self} ( newStorage) ,
2688
- overflow: ArithmeticOverflow ( Bool ( overflow) ) )
2666
+ overflow: Bool ( overflow) )
2689
2667
}
2690
2668
% end
2691
2669
@@ -3230,7 +3208,7 @@ extension FixedWidthInteger {
3230
3208
) - > ( Self, overflow: Bool) {
3231
3209
let ( partialValue, overflow) =
3232
3210
lhs . ${ newPrefix} ReportingOverflow( ${ argLabel} rhs)
3233
- return ( partialValue, overflow == . overflow)
3211
+ return ( partialValue, overflow: overflow)
3234
3212
}
3235
3213
3236
3214
% end
0 commit comments