Skip to content

Commit f369d31

Browse files
committed
NSDecimalValue: Dont use .doubleValue for integer properties.
- Decimal: Add an internal .int64Value and .uint64Value. - NSDecimalValue: For the .int*Value and .uint*Value properties use a truncated value from .int64Value and .uint64Value. - Using .doubleValue lost information when returning large numbers > 2e53 due to Double to Int conversion. - The returned values mostly match Darwin, moreso than just returning 0 when an exact conversion cannot be made.
1 parent f033eaa commit f369d31

File tree

3 files changed

+283
-17
lines changed

3 files changed

+283
-17
lines changed

Foundation/Decimal.swift

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// This source file is part of the Swift.org open source project
22
//
3-
// Copyright (c) 2016 Apple Inc. and the Swift project authors
3+
// Copyright (c) 2016 - 2019 Apple Inc. and the Swift project authors
44
// Licensed under Apache License v2.0 with Runtime Library Exception
55
//
6-
// See http://swift.org/LICENSE.txt for license information
7-
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
6+
// See https://swift.org/LICENSE.txt for license information
7+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

1010
import CoreFoundation
@@ -226,6 +226,66 @@ extension Decimal : Hashable, Comparable {
226226
return _isNegative != 0 ? -d : d
227227
}
228228

229+
// Return the low 64bits of the integer part
230+
private var _unsignedInt64Value: UInt64 {
231+
if _exponent < -20 || _exponent > 20 {
232+
return 0
233+
}
234+
235+
if _length == 0 || isZero || magnitude < Decimal(0) {
236+
return 0
237+
}
238+
239+
var copy = self.significand
240+
241+
if _exponent < 0 {
242+
for _ in _exponent..<0 {
243+
_ = divideByShort(&copy, 10)
244+
}
245+
} else if _exponent > 0 {
246+
for _ in 0..<_exponent {
247+
_ = multiplyByShort(&copy, 10)
248+
}
249+
}
250+
let uint64 = UInt64(copy._mantissa.3) << 48 | UInt64(copy._mantissa.2) << 32 | UInt64(copy._mantissa.1) << 16 | UInt64(copy._mantissa.0)
251+
return uint64
252+
}
253+
254+
// Perform a best effort conversion of the integer value, trying to match Darwin for
255+
// values outside of UInt64.min .. UInt64.max. Used by NSDecimalNumber.
256+
internal var uint64Value: UInt64 {
257+
let value = _unsignedInt64Value
258+
if !self.isNegative {
259+
return value
260+
}
261+
262+
if value == Int64.max.magnitude + 1 {
263+
return UInt64(bitPattern: Int64.min)
264+
} else if value <= Int64.max.magnitude {
265+
var value = Int64(value)
266+
value.negate()
267+
return UInt64(bitPattern: value)
268+
} else {
269+
return value
270+
}
271+
}
272+
273+
// Perform a best effort conversion of the integer value, trying to match Darwin for
274+
// values outside of Int64.min .. Int64.max. Used by NSDecimalNumber.
275+
internal var int64Value: Int64 {
276+
let uint64Value = _unsignedInt64Value
277+
if self.isNegative {
278+
if uint64Value == Int64.max.magnitude + 1 {
279+
return Int64.min
280+
} else if uint64Value <= Int64.max.magnitude {
281+
var value = Int64(uint64Value)
282+
value.negate()
283+
return value
284+
}
285+
}
286+
return Int64(bitPattern: uint64Value)
287+
}
288+
229289
public var hashValue: Int {
230290
return Int(bitPattern: __CFHashDouble(doubleValue))
231291
}
@@ -250,6 +310,7 @@ extension Decimal : Hashable, Comparable {
250310
var rhsVal = rhs
251311
return NSDecimalCompare(&lhsVal, &rhsVal) == .orderedSame
252312
}
313+
253314
public static func <(lhs: Decimal, rhs: Decimal) -> Bool {
254315
var lhsVal = lhs
255316
var rhsVal = rhs

Foundation/NSDecimalNumber.swift

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// This source file is part of the Swift.org open source project
22
//
3-
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
3+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
44
// Licensed under Apache License v2.0 with Runtime Library Exception
55
//
6-
// See http://swift.org/LICENSE.txt for license information
7-
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
6+
// See https://swift.org/LICENSE.txt for license information
7+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

1010
/*************** Exceptions ***********/
@@ -358,43 +358,55 @@ open class NSDecimalNumber : NSNumber {
358358
// return 'd' for double
359359

360360
open override var int8Value: Int8 {
361-
return Int8(exactly: decimal.doubleValue) ?? 0 as Int8
361+
return Int8(truncatingIfNeeded: decimal.int64Value)
362362
}
363+
363364
open override var uint8Value: UInt8 {
364-
return UInt8(exactly: decimal.doubleValue) ?? 0 as UInt8
365+
return UInt8(truncatingIfNeeded: decimal.uint64Value)
365366
}
367+
366368
open override var int16Value: Int16 {
367-
return Int16(exactly: decimal.doubleValue) ?? 0 as Int16
369+
return Int16(truncatingIfNeeded: decimal.int64Value)
368370
}
371+
369372
open override var uint16Value: UInt16 {
370-
return UInt16(exactly: decimal.doubleValue) ?? 0 as UInt16
373+
return UInt16(truncatingIfNeeded: decimal.uint64Value)
371374
}
375+
372376
open override var int32Value: Int32 {
373-
return Int32(exactly: decimal.doubleValue) ?? 0 as Int32
377+
return Int32(truncatingIfNeeded: decimal.int64Value)
374378
}
379+
375380
open override var uint32Value: UInt32 {
376-
return UInt32(exactly: decimal.doubleValue) ?? 0 as UInt32
381+
return UInt32(truncatingIfNeeded: decimal.uint64Value)
377382
}
383+
378384
open override var int64Value: Int64 {
379-
return Int64(exactly: decimal.doubleValue) ?? 0 as Int64
385+
return decimal.int64Value
380386
}
387+
381388
open override var uint64Value: UInt64 {
382-
return UInt64(exactly: decimal.doubleValue) ?? 0 as UInt64
389+
return decimal.uint64Value
383390
}
391+
384392
open override var floatValue: Float {
385393
return Float(decimal.doubleValue)
386394
}
395+
387396
open override var doubleValue: Double {
388397
return decimal.doubleValue
389398
}
399+
390400
open override var boolValue: Bool {
391401
return !decimal.isZero
392402
}
403+
393404
open override var intValue: Int {
394-
return Int(exactly: decimal.doubleValue) ?? 0 as Int
405+
return Int(truncatingIfNeeded: decimal.int64Value)
395406
}
407+
396408
open override var uintValue: UInt {
397-
return UInt(exactly: decimal.doubleValue) ?? 0 as UInt
409+
return UInt(truncatingIfNeeded: decimal.uint64Value)
398410
}
399411

400412
open override func isEqual(_ value: Any?) -> Bool {

TestFoundation/TestDecimal.swift

Lines changed: 194 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class TestDecimal: XCTestCase {
3131
("test_SimpleMultiplication", test_SimpleMultiplication),
3232
("test_SmallerNumbers", test_SmallerNumbers),
3333
("test_ZeroPower", test_ZeroPower),
34-
("test_doubleValue", test_doubleValue)
34+
("test_doubleValue", test_doubleValue),
35+
("test_NSDecimalNumberValues", test_NSDecimalNumberValues),
3536
]
3637
}
3738

@@ -822,4 +823,196 @@ class TestDecimal: XCTestCase {
822823
XCTAssertEqual(nf.string(from: NSDecimalNumber(decimal: a)), "0.00")
823824
XCTAssertEqual(nf.string(from: NSDecimalNumber(decimal: b)), "0.00")
824825
}
826+
827+
func test_NSDecimalNumberValues() {
828+
let uint64MaxDecimal = Decimal(string: UInt64.max.description)!
829+
830+
// int8Value
831+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(0)).int8Value, 0)
832+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-1)).int8Value, -1)
833+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(1)).int8Value, 1)
834+
835+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-129)).int8Value, 127)
836+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(128)).int8Value, -128)
837+
838+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.min)).int8Value, Int8.min)
839+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.min)).int8Value, 0)
840+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.min)).int8Value, 0)
841+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.min)).int8Value, 0)
842+
843+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.max)).int8Value, Int8.max)
844+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.max)).int8Value, -1)
845+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.max)).int8Value, -1)
846+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.max)).int8Value, -1)
847+
848+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.max)).int8Value, -1)
849+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.max)).int8Value, -1)
850+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.max)).int8Value, -1)
851+
XCTAssertEqual(NSDecimalNumber(decimal: uint64MaxDecimal).int8Value, -1)
852+
853+
// uint8Value
854+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(0)).uint8Value, 0)
855+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-1)).uint8Value, UInt8.max)
856+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(1)).uint8Value, 1)
857+
858+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-129)).uint8Value, 127)
859+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(128)).uint8Value, 128)
860+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(256)).uint8Value, 0)
861+
862+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.min)).uint8Value, 128)
863+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.min)).uint8Value, 0)
864+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.min)).uint8Value, 0)
865+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.min)).uint8Value, 0)
866+
867+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.max)).uint8Value, 127)
868+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.max)).uint8Value, UInt8.max)
869+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.max)).uint8Value, UInt8.max)
870+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.max)).uint8Value, UInt8.max)
871+
872+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.max)).uint8Value, UInt8.max)
873+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.max)).uint8Value, UInt8.max)
874+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.max)).uint8Value, UInt8.max)
875+
XCTAssertEqual(NSDecimalNumber(decimal: uint64MaxDecimal).uint8Value, UInt8.max)
876+
877+
// int16Value
878+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(0)).int16Value, 0)
879+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-1)).int16Value, -1)
880+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(1)).int16Value, 1)
881+
882+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-32769)).int16Value, 32767)
883+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(32768)).int16Value, -32768)
884+
885+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.min)).int16Value, -128)
886+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.min)).int16Value, Int16.min)
887+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.min)).int16Value, 0)
888+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.min)).int16Value, 0)
889+
890+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.max)).int16Value, 127)
891+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.max)).int16Value, Int16.max)
892+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.max)).int16Value, -1)
893+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.max)).int16Value, -1)
894+
895+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.max)).int16Value, 255)
896+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.max)).int16Value, -1)
897+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.max)).int16Value, -1)
898+
XCTAssertEqual(NSDecimalNumber(decimal: uint64MaxDecimal).int16Value, -1)
899+
900+
// uint16Value
901+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(0)).uint16Value, 0)
902+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-1)).uint16Value, UInt16.max)
903+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(1)).uint16Value, 1)
904+
905+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-32769)).uint16Value, 32767)
906+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(32768)).uint16Value, 32768)
907+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(65536)).uint16Value, 0)
908+
909+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.min)).uint16Value, 65408)
910+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.min)).uint16Value, 32768)
911+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.min)).uint16Value, 0)
912+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.min)).uint16Value, 0)
913+
914+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.max)).uint16Value, 127)
915+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.max)).uint16Value, 32767)
916+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.max)).uint16Value, UInt16.max)
917+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.max)).uint16Value, UInt16.max)
918+
919+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.max)).uint16Value, 255)
920+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.max)).uint16Value, UInt16.max)
921+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.max)).uint16Value, UInt16.max)
922+
XCTAssertEqual(NSDecimalNumber(decimal: uint64MaxDecimal).uint16Value, UInt16.max)
923+
924+
// int32Value
925+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(0)).int32Value, 0)
926+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-1)).int32Value, -1)
927+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(1)).int32Value, 1)
928+
929+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-32769)).int32Value, -32769)
930+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(32768)).int32Value, 32768)
931+
932+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.min)).int32Value, -128)
933+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.min)).int32Value, -32768)
934+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.min)).int32Value, Int32.min)
935+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.min)).int32Value, 0)
936+
937+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.max)).int32Value, 127)
938+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.max)).int32Value, 32767)
939+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.max)).int32Value, Int32.max)
940+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.max)).int32Value, -1)
941+
942+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.max)).int32Value, 255)
943+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.max)).int32Value, 65535)
944+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.max)).int32Value, -1)
945+
XCTAssertEqual(NSDecimalNumber(decimal: uint64MaxDecimal).int32Value, -1)
946+
947+
// uint32Value
948+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(0)).uint32Value, 0)
949+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-1)).uint32Value, UInt32.max)
950+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(1)).uint32Value, 1)
951+
952+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-32769)).uint32Value, 4294934527)
953+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(32768)).uint32Value, 32768)
954+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(65536)).uint32Value, 65536)
955+
956+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.min)).uint32Value, 4294967168)
957+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.min)).uint32Value, 4294934528)
958+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.min)).uint32Value, 2147483648)
959+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.min)).uint32Value, 0)
960+
961+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.max)).uint32Value, 127)
962+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.max)).uint32Value, 32767)
963+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.max)).uint32Value, UInt32(Int32.max))
964+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.max)).uint32Value, UInt32.max)
965+
966+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.max)).uint32Value, 255)
967+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.max)).uint32Value, 65535)
968+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.max)).uint32Value, UInt32.max)
969+
XCTAssertEqual(NSDecimalNumber(decimal: uint64MaxDecimal).uint32Value, UInt32.max)
970+
971+
// int64Value
972+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(0)).int64Value, 0)
973+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-1)).int64Value, -1)
974+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(1)).int64Value, 1)
975+
976+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-32769)).int64Value, -32769)
977+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(32768)).int64Value, 32768)
978+
979+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.min)).int64Value, -128)
980+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.min)).int64Value, -32768)
981+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.min)).int64Value, -2147483648)
982+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.min)).int64Value, Int64.min)
983+
984+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.max)).int64Value, 127)
985+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.max)).int64Value, 32767)
986+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.max)).int64Value, 2147483647)
987+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.max)).int64Value, Int64.max)
988+
989+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.max)).int64Value, 255)
990+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.max)).int64Value, 65535)
991+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.max)).int64Value, 4294967295)
992+
XCTAssertEqual(NSDecimalNumber(decimal: uint64MaxDecimal).int64Value, -1)
993+
994+
// uint64Value
995+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(0)).uint64Value, 0)
996+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-1)).uint64Value, UInt64.max)
997+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(1)).uint64Value, 1)
998+
999+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(-32769)).uint64Value, 18446744073709518847)
1000+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(32768)).uint64Value, 32768)
1001+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(65536)).uint64Value, 65536)
1002+
1003+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.min)).uint64Value, 18446744073709551488)
1004+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.min)).uint64Value, 18446744073709518848)
1005+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.min)).uint64Value, 18446744071562067968)
1006+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.min)).uint64Value, 9223372036854775808)
1007+
1008+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int8.max)).uint64Value, 127)
1009+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int16.max)).uint64Value, 32767)
1010+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int32.max)).uint64Value, UInt64(Int32.max))
1011+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(Int64.max)).uint64Value, UInt64(Int64.max))
1012+
1013+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt8.max)).uint64Value, 255)
1014+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt16.max)).uint64Value, 65535)
1015+
XCTAssertEqual(NSDecimalNumber(decimal: Decimal(UInt32.max)).uint64Value, 4294967295)
1016+
XCTAssertEqual(NSDecimalNumber(decimal: uint64MaxDecimal).uint64Value, UInt64.max)
1017+
}
8251018
}

0 commit comments

Comments
 (0)