Skip to content

Commit 09a995a

Browse files
committed
[NFC] Reorder members in Decimal SignedNumeric conformance to parallel Darwin overlay
1 parent 25dd336 commit 09a995a

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed

Foundation/Decimal.swift

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,37 @@ extension Decimal {
196196
}
197197

198198
extension Decimal : Hashable, Comparable {
199+
// (Used by VariableLengthNumber and doubleValue.)
200+
fileprivate subscript(index: UInt32) -> UInt16 {
201+
get {
202+
switch index {
203+
case 0: return _mantissa.0
204+
case 1: return _mantissa.1
205+
case 2: return _mantissa.2
206+
case 3: return _mantissa.3
207+
case 4: return _mantissa.4
208+
case 5: return _mantissa.5
209+
case 6: return _mantissa.6
210+
case 7: return _mantissa.7
211+
default: fatalError("Invalid index \(index) for _mantissa")
212+
}
213+
}
214+
set {
215+
switch index {
216+
case 0: _mantissa.0 = newValue
217+
case 1: _mantissa.1 = newValue
218+
case 2: _mantissa.2 = newValue
219+
case 3: _mantissa.3 = newValue
220+
case 4: _mantissa.4 = newValue
221+
case 5: _mantissa.5 = newValue
222+
case 6: _mantissa.6 = newValue
223+
case 7: _mantissa.7 = newValue
224+
default: fatalError("Invalid index \(index) for _mantissa")
225+
}
226+
}
227+
}
228+
229+
// (Used by NSDecimalNumber and hash(into:).)
199230
internal var doubleValue: Double {
200231
if _length == 0 {
201232
return _isNegative == 1 ? Double.nan : 0
@@ -218,13 +249,12 @@ extension Decimal : Hashable, Comparable {
218249
return _isNegative != 0 ? -d : d
219250
}
220251

221-
// Return the low 64bits of the integer part
252+
// The low 64 bits of the integer part. (Used by uint64Value and int64Value.)
222253
private var _unsignedInt64Value: UInt64 {
223254
if _exponent < -20 || _exponent > 20 {
224255
return 0
225256
}
226-
227-
if _length == 0 || isZero || magnitude < Decimal(0) {
257+
if _length == 0 || isZero || magnitude < (0 as Decimal) {
228258
return 0
229259
}
230260

@@ -243,33 +273,33 @@ extension Decimal : Hashable, Comparable {
243273
return uint64
244274
}
245275

246-
// Perform a best effort conversion of the integer value, trying to match Darwin for
247-
// values outside of UInt64.min .. UInt64.max. Used by NSDecimalNumber.
276+
// A best-effort conversion of the integer value, trying to match Darwin for
277+
// values outside of UInt64.min...UInt64.max. (Used by NSDecimalNumber.)
248278
internal var uint64Value: UInt64 {
249279
let value = _unsignedInt64Value
250280
if !self.isNegative {
251281
return value
252282
}
253-
254283
if value == Int64.max.magnitude + 1 {
255284
return UInt64(bitPattern: Int64.min)
256-
} else if value <= Int64.max.magnitude {
285+
}
286+
if value <= Int64.max.magnitude {
257287
var value = Int64(value)
258288
value.negate()
259289
return UInt64(bitPattern: value)
260-
} else {
261-
return value
262290
}
291+
return value
263292
}
264293

265-
// Perform a best effort conversion of the integer value, trying to match Darwin for
266-
// values outside of Int64.min .. Int64.max. Used by NSDecimalNumber.
294+
// A best-effort conversion of the integer value, trying to match Darwin for
295+
// values outside of Int64.min...Int64.max. (Used by NSDecimalNumber.)
267296
internal var int64Value: Int64 {
268297
let uint64Value = _unsignedInt64Value
269298
if self.isNegative {
270299
if uint64Value == Int64.max.magnitude + 1 {
271300
return Int64.min
272-
} else if uint64Value <= Int64.max.magnitude {
301+
}
302+
if uint64Value <= Int64.max.magnitude {
273303
var value = Int64(uint64Value)
274304
value.negate()
275305
return value
@@ -1900,34 +1930,7 @@ extension Decimal {
19001930
}
19011931
return comparison
19021932
}
1903-
fileprivate subscript(index:UInt32) -> UInt16 {
1904-
get {
1905-
switch index {
1906-
case 0: return _mantissa.0
1907-
case 1: return _mantissa.1
1908-
case 2: return _mantissa.2
1909-
case 3: return _mantissa.3
1910-
case 4: return _mantissa.4
1911-
case 5: return _mantissa.5
1912-
case 6: return _mantissa.6
1913-
case 7: return _mantissa.7
1914-
default: fatalError("Invalid index \(index) for _mantissa")
1915-
}
1916-
}
1917-
set {
1918-
switch index {
1919-
case 0: _mantissa.0 = newValue
1920-
case 1: _mantissa.1 = newValue
1921-
case 2: _mantissa.2 = newValue
1922-
case 3: _mantissa.3 = newValue
1923-
case 4: _mantissa.4 = newValue
1924-
case 5: _mantissa.5 = newValue
1925-
case 6: _mantissa.6 = newValue
1926-
case 7: _mantissa.7 = newValue
1927-
default: fatalError("Invalid index \(index) for _mantissa")
1928-
}
1929-
}
1930-
}
1933+
19311934
fileprivate mutating func setNaN() {
19321935
_length = 0
19331936
_isNegative = 1

0 commit comments

Comments
 (0)