@@ -24,7 +24,7 @@ public struct Decimal {
24
24
return Int32 ( __exponent)
25
25
}
26
26
set {
27
- __exponent = Int8 ( extendingOrTruncating : newValue)
27
+ __exponent = Int8 ( truncatingIfNeeded : newValue)
28
28
}
29
29
}
30
30
// length == 0 && isNegative -> NaN
@@ -90,7 +90,7 @@ public struct Decimal {
90
90
91
91
public init ( _exponent: Int32 , _length: UInt32 , _isNegative: UInt32 , _isCompact: UInt32 , _reserved: UInt32 , _mantissa: ( UInt16 , UInt16 , UInt16 , UInt16 , UInt16 , UInt16 , UInt16 , UInt16 ) ) {
92
92
self . _mantissa = _mantissa
93
- self . __exponent = Int8 ( extendingOrTruncating : _exponent)
93
+ self . __exponent = Int8 ( truncatingIfNeeded : _exponent)
94
94
self . __lengthAndFlags = UInt8 ( _length & 0b1111 )
95
95
self . __reserved = 0
96
96
self . _isNegative = _isNegative
@@ -412,21 +412,21 @@ extension Decimal {
412
412
while mantissa != 0 && i < NSDecimalMaxSize {
413
413
switch i {
414
414
case 0 :
415
- _mantissa. 0 = UInt16 ( extendingOrTruncating : mantissa)
415
+ _mantissa. 0 = UInt16 ( truncatingIfNeeded : mantissa)
416
416
case 1 :
417
- _mantissa. 1 = UInt16 ( extendingOrTruncating : mantissa)
417
+ _mantissa. 1 = UInt16 ( truncatingIfNeeded : mantissa)
418
418
case 2 :
419
- _mantissa. 2 = UInt16 ( extendingOrTruncating : mantissa)
419
+ _mantissa. 2 = UInt16 ( truncatingIfNeeded : mantissa)
420
420
case 3 :
421
- _mantissa. 3 = UInt16 ( extendingOrTruncating : mantissa)
421
+ _mantissa. 3 = UInt16 ( truncatingIfNeeded : mantissa)
422
422
case 4 :
423
- _mantissa. 4 = UInt16 ( extendingOrTruncating : mantissa)
423
+ _mantissa. 4 = UInt16 ( truncatingIfNeeded : mantissa)
424
424
case 5 :
425
- _mantissa. 5 = UInt16 ( extendingOrTruncating : mantissa)
425
+ _mantissa. 5 = UInt16 ( truncatingIfNeeded : mantissa)
426
426
case 6 :
427
- _mantissa. 6 = UInt16 ( extendingOrTruncating : mantissa)
427
+ _mantissa. 6 = UInt16 ( truncatingIfNeeded : mantissa)
428
428
case 7 :
429
- _mantissa. 7 = UInt16 ( extendingOrTruncating : mantissa)
429
+ _mantissa. 7 = UInt16 ( truncatingIfNeeded : mantissa)
430
430
default :
431
431
fatalError ( " initialization overflow " )
432
432
}
@@ -592,13 +592,13 @@ fileprivate func multiplyByShort<T:VariableLengthNumber>(_ d: inout T, _ mul:UIn
592
592
for i in 0 ..< d. _length {
593
593
let accumulator : UInt32 = UInt32 ( d [ i] ) * UInt32( mul) + carry
594
594
carry = accumulator >> 16
595
- d [ i] = UInt16 ( extendingOrTruncating : accumulator)
595
+ d [ i] = UInt16 ( truncatingIfNeeded : accumulator)
596
596
}
597
597
if carry != 0 {
598
598
if d. _length >= Decimal . maxSize {
599
599
return . overflow
600
600
}
601
- d [ d. _length] = UInt16 ( extendingOrTruncating : carry)
601
+ d [ d. _length] = UInt16 ( truncatingIfNeeded : carry)
602
602
d. _length += 1
603
603
}
604
604
return . noError
@@ -609,13 +609,13 @@ fileprivate func addShort<T:VariableLengthNumber>(_ d: inout T, _ add:UInt16) ->
609
609
for i in 0 ..< d. _length {
610
610
let accumulator : UInt32 = UInt32 ( d [ i] ) + carry
611
611
carry = accumulator >> 16
612
- d [ i] = UInt16 ( extendingOrTruncating : accumulator)
612
+ d [ i] = UInt16 ( truncatingIfNeeded : accumulator)
613
613
}
614
614
if carry != 0 {
615
615
if d. _length >= Decimal . maxSize {
616
616
return . overflow
617
617
}
618
- d [ d. _length] = UInt16 ( extendingOrTruncating : carry)
618
+ d [ d. _length] = UInt16 ( truncatingIfNeeded : carry)
619
619
d. _length += 1
620
620
}
621
621
return . noError
@@ -763,8 +763,8 @@ fileprivate func integerMultiply<T:VariableLengthNumber>(_ big: inout T,
763
763
if i + j < big. _length {
764
764
let bigij = UInt32 ( big [ i+ j] )
765
765
accumulator = UInt32 ( carry) + bigij + UInt32( right [ j] ) * UInt32( left [ i] )
766
- carry = UInt16 ( extendingOrTruncating : accumulator >> 16 )
767
- big [ i+ j] = UInt16 ( extendingOrTruncating : accumulator)
766
+ carry = UInt16 ( truncatingIfNeeded : accumulator >> 16 )
767
+ big [ i+ j] = UInt16 ( truncatingIfNeeded : accumulator)
768
768
} else if carry != 0 || ( right [ j] == 0 && left [ j] == 0 ) {
769
769
return . overflow
770
770
}
@@ -904,7 +904,7 @@ fileprivate func integerDivide<T:VariableLengthNumber>(_ r: inout T,
904
904
acc = acc & 0xffff ;
905
905
acc = 0xffff + UInt32( u [ ul - vl + i - UInt32( j) - UInt32( 1 ) ] ) - acc + sk; // subtract
906
906
sk = acc >> 16 ;
907
- u [ ul - vl + i - UInt32( j) - UInt32( 1 ) ] = UInt16 ( extendingOrTruncating : acc)
907
+ u [ ul - vl + i - UInt32( j) - UInt32( 1 ) ] = UInt16 ( truncatingIfNeeded : acc)
908
908
}
909
909
910
910
// D5: test remainder
@@ -920,7 +920,7 @@ fileprivate func integerDivide<T:VariableLengthNumber>(_ r: inout T,
920
920
let vl = v. _length
921
921
acc = UInt32 ( v [ i] ) + UInt32( u [ UInt32 ( ul) - UInt32( vl) + UInt32( i) - UInt32( j) - UInt32( 1 ) ] ) + k
922
922
k = acc >> 16 ;
923
- u [ UInt32 ( ul) - UInt32( vl) + UInt32( i) - UInt32( j) - UInt32( 1 ) ] = UInt16 ( extendingOrTruncating : acc)
923
+ u [ UInt32 ( ul) - UInt32( vl) + UInt32( i) - UInt32( j) - UInt32( 1 ) ] = UInt16 ( truncatingIfNeeded : acc)
924
924
}
925
925
// k must be == 1 here
926
926
}
@@ -1173,17 +1173,17 @@ fileprivate func integerAdd(_ result: inout WideDecimal, _ left: inout Decimal,
1173
1173
let li = UInt32 ( left [ i] )
1174
1174
let ri = UInt32 ( right [ i] )
1175
1175
accumulator = li + ri + UInt32( carry)
1176
- carry = UInt16 ( extendingOrTruncating : accumulator >> 16 )
1177
- result [ i] = UInt16 ( extendingOrTruncating : accumulator)
1176
+ carry = UInt16 ( truncatingIfNeeded : accumulator >> 16 )
1177
+ result [ i] = UInt16 ( truncatingIfNeeded : accumulator)
1178
1178
i += 1
1179
1179
}
1180
1180
1181
1181
while i < left. _length {
1182
1182
if carry != 0 {
1183
1183
let li = UInt32 ( left [ i] )
1184
1184
accumulator = li + UInt32( carry)
1185
- carry = UInt16 ( extendingOrTruncating : accumulator >> 16 )
1186
- result [ i] = UInt16 ( extendingOrTruncating : accumulator)
1185
+ carry = UInt16 ( truncatingIfNeeded : accumulator >> 16 )
1186
+ result [ i] = UInt16 ( truncatingIfNeeded : accumulator)
1187
1187
i += 1
1188
1188
} else {
1189
1189
while i < left. _length {
@@ -1197,8 +1197,8 @@ fileprivate func integerAdd(_ result: inout WideDecimal, _ left: inout Decimal,
1197
1197
if carry != 0 {
1198
1198
let ri = UInt32 ( right [ i] )
1199
1199
accumulator = ri + UInt32( carry)
1200
- carry = UInt16 ( extendingOrTruncating : accumulator >> 16 )
1201
- result [ i] = UInt16 ( extendingOrTruncating : accumulator)
1200
+ carry = UInt16 ( truncatingIfNeeded : accumulator >> 16 )
1201
+ result [ i] = UInt16 ( truncatingIfNeeded : accumulator)
1202
1202
i += 1
1203
1203
} else {
1204
1204
while i < right. _length {
@@ -1240,17 +1240,17 @@ fileprivate func integerSubtract(_ result: inout Decimal, _ left: inout Decimal,
1240
1240
let li = UInt32 ( left [ i] )
1241
1241
let ri = UInt32 ( right [ i] )
1242
1242
accumulator = 0xffff + li - ri + UInt32( carry)
1243
- carry = UInt16 ( extendingOrTruncating : accumulator >> 16 )
1244
- result [ i] = UInt16 ( extendingOrTruncating : accumulator)
1243
+ carry = UInt16 ( truncatingIfNeeded : accumulator >> 16 )
1244
+ result [ i] = UInt16 ( truncatingIfNeeded : accumulator)
1245
1245
i += 1
1246
1246
}
1247
1247
1248
1248
while i < left. _length {
1249
1249
if carry != 0 {
1250
1250
let li = UInt32 ( left [ i] )
1251
1251
accumulator = 0xffff + li // + no carry
1252
- carry = UInt16 ( extendingOrTruncating : accumulator >> 16 )
1253
- result [ i] = UInt16 ( extendingOrTruncating : accumulator)
1252
+ carry = UInt16 ( truncatingIfNeeded : accumulator >> 16 )
1253
+ result [ i] = UInt16 ( truncatingIfNeeded : accumulator)
1254
1254
i += 1
1255
1255
} else {
1256
1256
while i < left. _length {
@@ -1263,8 +1263,8 @@ fileprivate func integerSubtract(_ result: inout Decimal, _ left: inout Decimal,
1263
1263
while i < right. _length {
1264
1264
let ri = UInt32 ( right [ i] )
1265
1265
accumulator = 0xffff - ri + UInt32( carry)
1266
- carry = UInt16 ( extendingOrTruncating : accumulator >> 16 )
1267
- result [ i] = UInt16 ( extendingOrTruncating : accumulator)
1266
+ carry = UInt16 ( truncatingIfNeeded : accumulator >> 16 )
1267
+ result [ i] = UInt16 ( truncatingIfNeeded : accumulator)
1268
1268
i += 1
1269
1269
}
1270
1270
0 commit comments