@@ -1242,7 +1242,7 @@ extension Numeric {
1242
1242
/// Bit Pattern Conversion
1243
1243
/// ----------------------
1244
1244
///
1245
- /// Use the `init(extendingOrTruncating :)` initializer to create a new instance
1245
+ /// Use the `init(truncatingIfNeeded :)` initializer to create a new instance
1246
1246
/// with the same bit pattern as the passed value, extending or truncating the
1247
1247
/// value's representation as necessary. Note that the value may not be
1248
1248
/// preserved, particularly when converting between signed to unsigned integer
@@ -1253,11 +1253,11 @@ extension Numeric {
1253
1253
/// let q: Int16 = 850
1254
1254
/// // q == 0b00000011_01010010
1255
1255
///
1256
- /// let r = Int8(extendingOrTruncating : q) // truncate 'q' to fit in 8 bits
1256
+ /// let r = Int8(truncatingIfNeeded : q) // truncate 'q' to fit in 8 bits
1257
1257
/// // r == 82
1258
1258
/// // == 0b01010010
1259
1259
///
1260
- /// let s = Int16(extendingOrTruncating : s) // extend 'r' to fill 16 bits
1260
+ /// let s = Int16(truncatingIfNeeded : s) // extend 'r' to fill 16 bits
1261
1261
/// // s == 82
1262
1262
/// // == 0b00000000_01010010
1263
1263
///
@@ -1272,15 +1272,15 @@ extension Numeric {
1272
1272
/// // t == -100
1273
1273
/// // t's binary representation == 0b10011100
1274
1274
///
1275
- /// let u = UInt8(extendingOrTruncating : t)
1275
+ /// let u = UInt8(truncatingIfNeeded : t)
1276
1276
/// // u == 156
1277
1277
/// // u's binary representation == 0b10011100
1278
1278
///
1279
- /// let v = Int16(extendingOrTruncating : t)
1279
+ /// let v = Int16(truncatingIfNeeded : t)
1280
1280
/// // v == -100
1281
1281
/// // v's binary representation == 0b11111111_10011100
1282
1282
///
1283
- /// let w = UInt16(extendingOrTruncating : t)
1283
+ /// let w = UInt16(truncatingIfNeeded : t)
1284
1284
/// // w == 65436
1285
1285
/// // w's binary representation == 0b11111111_10011100
1286
1286
///
@@ -1377,7 +1377,7 @@ public protocol BinaryInteger :
1377
1377
///
1378
1378
/// let p: Int16 = -500
1379
1379
/// // 'p' has a binary representation of 11111110_00001100
1380
- /// let q = Int8(extendingOrTruncating : p)
1380
+ /// let q = Int8(truncatingIfNeeded : p)
1381
1381
/// // q == 12
1382
1382
/// // 'q' has a binary representation of 00001100
1383
1383
///
@@ -1388,21 +1388,21 @@ public protocol BinaryInteger :
1388
1388
///
1389
1389
/// let u: Int8 = 21
1390
1390
/// // 'u' has a binary representation of 00010101
1391
- /// let v = Int16(extendingOrTruncating : u)
1391
+ /// let v = Int16(truncatingIfNeeded : u)
1392
1392
/// // v == 21
1393
1393
/// // 'v' has a binary representation of 00000000_00010101
1394
1394
///
1395
1395
/// let w: Int8 = -21
1396
1396
/// // 'w' has a binary representation of 11101011
1397
- /// let x = Int16(extendingOrTruncating : w)
1397
+ /// let x = Int16(truncatingIfNeeded : w)
1398
1398
/// // x == -21
1399
1399
/// // 'x' has a binary representation of 11111111_11101011
1400
- /// let y = UInt16(extendingOrTruncating : w)
1400
+ /// let y = UInt16(truncatingIfNeeded : w)
1401
1401
/// // y == 65515
1402
1402
/// // 'y' has a binary representation of 11111111_11101011
1403
1403
///
1404
1404
/// - Parameter source: An integer to convert to this type.
1405
- init < T : BinaryInteger> ( extendingOrTruncating source: T)
1405
+ init < T : BinaryInteger> ( truncatingIfNeeded source: T)
1406
1406
1407
1407
/// Creates a new instance with the representable value that's closest to the
1408
1408
/// given integer.
@@ -1675,16 +1675,16 @@ extension BinaryInteger {
1675
1675
// sign bit. Therefore it is safe to convert to the unsigned type.
1676
1676
1677
1677
if lhs. bitWidth < rhs. bitWidth {
1678
- return Other ( extendingOrTruncating : lhs) == rhs
1678
+ return Other ( truncatingIfNeeded : lhs) == rhs
1679
1679
}
1680
1680
if lhs. bitWidth > rhs. bitWidth {
1681
- return lhs == Self ( extendingOrTruncating : rhs)
1681
+ return lhs == Self ( truncatingIfNeeded : rhs)
1682
1682
}
1683
1683
1684
1684
if Self . isSigned {
1685
- return Other ( extendingOrTruncating : lhs) == rhs
1685
+ return Other ( truncatingIfNeeded : lhs) == rhs
1686
1686
}
1687
- return lhs == Self ( extendingOrTruncating : rhs)
1687
+ return lhs == Self ( truncatingIfNeeded : rhs)
1688
1688
}
1689
1689
1690
1690
/// Returns a Boolean value indicating whether the two given values are not
@@ -1735,14 +1735,14 @@ extension BinaryInteger {
1735
1735
// values of the other type. Otherwise, lhs and rhs are positive, and one
1736
1736
// of Self, Other may be signed and the other unsigned.
1737
1737
1738
- let rhsAsSelf = Self ( extendingOrTruncating : rhs)
1738
+ let rhsAsSelf = Self ( truncatingIfNeeded : rhs)
1739
1739
let rhsAsSelfNegative = rhsAsSelf < ( 0 as Self )
1740
1740
1741
1741
1742
1742
// Can we round-trip rhs through Other?
1743
- if Other ( extendingOrTruncating : rhsAsSelf) == rhs &&
1743
+ if Other ( truncatingIfNeeded : rhsAsSelf) == rhs &&
1744
1744
// This additional check covers the `Int8.max < (128 as UInt8)` case.
1745
- // Since the types are of the same width, init(extendingOrTruncating :)
1745
+ // Since the types are of the same width, init(truncatingIfNeeded :)
1746
1746
// will result in a simple bitcast, so that rhsAsSelf would be -128, and
1747
1747
// `lhs < rhsAsSelf` will return false.
1748
1748
// We basically guard against that bitcast by requiring rhs and rhsAsSelf
@@ -1751,7 +1751,7 @@ extension BinaryInteger {
1751
1751
return lhs < rhsAsSelf
1752
1752
}
1753
1753
1754
- return Other ( extendingOrTruncating : lhs) < rhs
1754
+ return Other ( truncatingIfNeeded : lhs) < rhs
1755
1755
}
1756
1756
1757
1757
/// Returns a Boolean value indicating whether the value of the first
@@ -1861,7 +1861,7 @@ extension BinaryInteger {
1861
1861
/// var binaryString: String {
1862
1862
/// var result: [String] = []
1863
1863
/// for i in 0..<(Self.bitWidth / 8) {
1864
- /// let byte = UInt8(extendingOrTruncating : self >> (i * 8))
1864
+ /// let byte = UInt8(truncatingIfNeeded : self >> (i * 8))
1865
1865
/// let byteString = String(byte, radix: 2)
1866
1866
/// let padding = String(repeating: "0",
1867
1867
/// count: 8 - byteString.count)
@@ -2125,7 +2125,7 @@ ${operatorComment(x.operator, False)}
2125
2125
public static func ${ x. operator} <
2126
2126
Other : BinaryInteger
2127
2127
> ( lhs: Self, rhs: Other) - > Self {
2128
- return lhs ${ x. operator} Self( extendingOrTruncating : rhs)
2128
+ return lhs ${ x. operator} Self( truncatingIfNeeded : rhs)
2129
2129
}
2130
2130
2131
2131
// Heterogeneous masking shift assignment
@@ -2191,7 +2191,7 @@ ${operatorComment(x.nonMaskingOperator, True)}
2191
2191
let overshiftL : Self = 0
2192
2192
if _fastPath ( rhs >= 0 ) {
2193
2193
if _fastPath ( rhs < Self . bitWidth) {
2194
- return lhs ${ x. operator} Self( extendingOrTruncating : rhs)
2194
+ return lhs ${ x. operator} Self( truncatingIfNeeded : rhs)
2195
2195
}
2196
2196
return overshift ${ 'LR'[ isRightShift] }
2197
2197
}
@@ -2214,7 +2214,7 @@ extension FixedWidthInteger {
2214
2214
else if _slowPath ( source > Self . max) {
2215
2215
self = Self . max
2216
2216
}
2217
- else { self = Self ( extendingOrTruncating : source) }
2217
+ else { self = Self ( truncatingIfNeeded : source) }
2218
2218
}
2219
2219
2220
2220
% for x in binaryArithmetic [ 'Numeric'] + binaryArithmetic[ " BinaryInteger " ] [ : 1 ] :
@@ -2253,7 +2253,7 @@ ${unsafeOperationComment(x.operator)}
2253
2253
% end
2254
2254
2255
2255
@inline ( __always)
2256
- public init< T : BinaryInteger> ( extendingOrTruncating source: T) {
2256
+ public init< T : BinaryInteger> ( truncatingIfNeeded source: T) {
2257
2257
if Self . bitWidth <= ${ word_bits} {
2258
2258
self = Self . init ( _truncatingBits: source. _lowWord)
2259
2259
}
@@ -2322,7 +2322,7 @@ extension UnsignedInteger {
2322
2322
/// A textual representation of this value.
2323
2323
public var description : String {
2324
2324
if self . bitWidth <= ${ word_bits} {
2325
- return _uint64ToString ( UInt64 ( extendingOrTruncating : self ) )
2325
+ return _uint64ToString ( UInt64 ( truncatingIfNeeded : self ) )
2326
2326
}
2327
2327
if self == ( 0 as Self ) {
2328
2328
return " 0 "
@@ -2342,7 +2342,7 @@ extension UnsignedInteger {
2342
2342
x /= 10
2343
2343
buf. append (
2344
2344
Unicode . Scalar (
2345
- ascii0 + Int( UInt ( extendingOrTruncating : r) . _value) ) !)
2345
+ ascii0 + Int( UInt ( truncatingIfNeeded : r) . _value) ) !)
2346
2346
}
2347
2347
while x != ( 0 as Self )
2348
2348
return String ( buf. reversed ( ) . lazy. map { Character ( $0) } )
@@ -2362,7 +2362,7 @@ extension UnsignedInteger where Self : FixedWidthInteger {
2362
2362
_precondition ( source <= Self . max,
2363
2363
" Not enough bits to represent a signed value " )
2364
2364
}
2365
- self . init ( extendingOrTruncating : source)
2365
+ self . init ( truncatingIfNeeded : source)
2366
2366
}
2367
2367
2368
2368
@_semantics ( " optimize.sil.specialize.generic.partial.never " )
@@ -2377,7 +2377,7 @@ extension UnsignedInteger where Self : FixedWidthInteger {
2377
2377
source > Self . max {
2378
2378
return nil
2379
2379
}
2380
- self . init ( extendingOrTruncating : source)
2380
+ self . init ( truncatingIfNeeded : source)
2381
2381
}
2382
2382
2383
2383
/// The maximum representable integer in this type.
@@ -2415,7 +2415,7 @@ extension SignedInteger {
2415
2415
/// A textual representation of this value.
2416
2416
public var description : String {
2417
2417
if self . bitWidth <= ${ word_bits} {
2418
- return _int64ToString ( Int64 ( extendingOrTruncating : self ) )
2418
+ return _int64ToString ( Int64 ( truncatingIfNeeded : self ) )
2419
2419
}
2420
2420
2421
2421
let base = magnitude. description
@@ -2444,7 +2444,7 @@ extension SignedInteger where Self : FixedWidthInteger {
2444
2444
_precondition ( source <= Self . max,
2445
2445
" Not enough bits to represent a signed value " )
2446
2446
}
2447
- self . init ( extendingOrTruncating : source)
2447
+ self . init ( truncatingIfNeeded : source)
2448
2448
}
2449
2449
2450
2450
@_semantics ( " optimize.sil.specialize.generic.partial.never " )
@@ -2460,7 +2460,7 @@ extension SignedInteger where Self : FixedWidthInteger {
2460
2460
source > Self . max {
2461
2461
return nil
2462
2462
}
2463
- self . init ( extendingOrTruncating : source)
2463
+ self . init ( truncatingIfNeeded : source)
2464
2464
}
2465
2465
2466
2466
/// The maximum representable integer in this type.
@@ -2954,8 +2954,8 @@ extension ${Self} : Hashable {
2954
2954
% elif bits == word_bits * 2 :
2955
2955
// We have twice as many bits as we need to return.
2956
2956
return
2957
- Int ( extendingOrTruncating : self ) ^
2958
- Int ( extendingOrTruncating : self &>> 32 )
2957
+ Int ( truncatingIfNeeded : self ) ^
2958
+ Int ( truncatingIfNeeded : self &>> 32 )
2959
2959
% else :
2960
2960
_Unimplemented ( )
2961
2961
% end
@@ -2986,7 +2986,7 @@ extension ${Self} {
2986
2986
///
2987
2987
/// - Parameter source: An integer to use as the source of the new value's
2988
2988
/// bit pattern.
2989
- @available ( swift, obsoleted: 4.0 , renamed: " init(extendingOrTruncating :) " )
2989
+ @available ( swift, obsoleted: 4.0 , renamed: " init(truncatingIfNeeded :) " )
2990
2990
@_transparent
2991
2991
public init( truncatingBitPattern source: ${ Src} ) {
2992
2992
let src = source. _value
0 commit comments