@@ -132,6 +132,7 @@ class TestDecimal: XCTestCase {
132
132
XCTAssertEqual ( d1. _exponent, 0 )
133
133
XCTAssertEqual ( d1. _length, 4 )
134
134
}
135
+
135
136
func test_Constants( ) {
136
137
XCTAssertEqual ( 8 , NSDecimalMaxSize)
137
138
XCTAssertEqual ( 32767 , NSDecimalNoScale)
@@ -217,8 +218,8 @@ class TestDecimal: XCTestCase {
217
218
let reserved : UInt32 = ( 1 <<18 as UInt32 ) + ( 1 <<17 as UInt32 ) + 1
218
219
let mantissa : ( UInt16 , UInt16 , UInt16 , UInt16 , UInt16 , UInt16 , UInt16 , UInt16 ) = ( 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 )
219
220
var explicit = Decimal (
220
- _exponent: 0x17f ,
221
- _length: 0xff ,
221
+ _exponent: 0x7f ,
222
+ _length: 0x0f ,
222
223
_isNegative: 3 ,
223
224
_isCompact: 4 ,
224
225
_reserved: reserved,
@@ -501,6 +502,11 @@ class TestDecimal: XCTestCase {
501
502
XCTAssertTrue ( NSDecimalIsNotANumber ( & result) , " NaN e5 " )
502
503
503
504
XCTAssertFalse ( Double ( truncating: NSDecimalNumber ( decimal: Decimal ( 0 ) ) ) . isNaN)
505
+ XCTAssertTrue ( Decimal ( Double . leastNonzeroMagnitude) . isNaN)
506
+ XCTAssertTrue ( Decimal ( Double . leastNormalMagnitude) . isNaN)
507
+ XCTAssertTrue ( Decimal ( Double . greatestFiniteMagnitude) . isNaN)
508
+ XCTAssertTrue ( Decimal ( Double ( " 1e-129 " ) !) . isNaN)
509
+ XCTAssertTrue ( Decimal ( Double ( " 0.1e-128 " ) !) . isNaN)
504
510
}
505
511
506
512
func test_NegativeAndZeroMultiplication( ) {
@@ -827,6 +833,52 @@ class TestDecimal: XCTestCase {
827
833
XCTAssertEqual ( 1 , negativeSix. raising ( toPower: 0 ) )
828
834
}
829
835
836
+ func test_parseDouble( ) throws {
837
+ XCTAssertEqual ( Decimal ( Double ( 0.0 ) ) , Decimal ( Int . zero) )
838
+ XCTAssertEqual ( Decimal ( Double ( - 0.0 ) ) , Decimal ( Int . zero) )
839
+
840
+ // These values can only be represented as Decimal.nan
841
+ XCTAssertEqual ( Decimal ( Double . nan) , Decimal . nan)
842
+ XCTAssertEqual ( Decimal ( Double . signalingNaN) , Decimal . nan)
843
+
844
+ // These values are out out range for Decimal
845
+ XCTAssertEqual ( Decimal ( - Double. leastNonzeroMagnitude) , Decimal . nan)
846
+ XCTAssertEqual ( Decimal ( Double . leastNonzeroMagnitude) , Decimal . nan)
847
+ XCTAssertEqual ( Decimal ( - Double. leastNormalMagnitude) , Decimal . nan)
848
+ XCTAssertEqual ( Decimal ( Double . leastNormalMagnitude) , Decimal . nan)
849
+ XCTAssertEqual ( Decimal ( - Double. greatestFiniteMagnitude) , Decimal . nan)
850
+ XCTAssertEqual ( Decimal ( Double . greatestFiniteMagnitude) , Decimal . nan)
851
+
852
+ // SR-13837
853
+ let testDoubles : [ ( Double , String ) ] = [
854
+ ( 1.8446744073709550E18 , " 1844674407370954752 " ) ,
855
+ ( 1.8446744073709551E18 , " 1844674407370954752 " ) ,
856
+ ( 1.8446744073709552E18 , " 1844674407370955264 " ) ,
857
+ ( 1.8446744073709553E18 , " 1844674407370955264 " ) ,
858
+ ( 1.8446744073709554E18 , " 1844674407370955520 " ) ,
859
+ ( 1.8446744073709555E18 , " 1844674407370955520 " ) ,
860
+
861
+ ( 1.8446744073709550E19 , " 18446744073709547520 " ) ,
862
+ ( 1.8446744073709551E19 , " 18446744073709552640 " ) ,
863
+ ( 1.8446744073709552E19 , " 18446744073709552640 " ) ,
864
+ ( 1.8446744073709553E19 , " 18446744073709552640 " ) ,
865
+ ( 1.8446744073709554E19 , " 18446744073709555200 " ) ,
866
+ ( 1.8446744073709555E19 , " 18446744073709555200 " ) ,
867
+
868
+ ( 1.8446744073709550E20 , " 184467440737095526400 " ) ,
869
+ ( 1.8446744073709551E20 , " 184467440737095526400 " ) ,
870
+ ( 1.8446744073709552E20 , " 184467440737095526400 " ) ,
871
+ ( 1.8446744073709553E20 , " 184467440737095526400 " ) ,
872
+ ( 1.8446744073709554E20 , " 184467440737095552000 " ) ,
873
+ ( 1.8446744073709555E20 , " 184467440737095552000 " ) ,
874
+ ]
875
+
876
+ for (d, s) in testDoubles {
877
+ XCTAssertEqual ( Decimal ( d) , Decimal ( string: s) )
878
+ XCTAssertEqual ( Decimal ( d) . description, try XCTUnwrap ( Decimal ( string: s) ) . description)
879
+ }
880
+ }
881
+
830
882
func test_doubleValue( ) {
831
883
XCTAssertEqual ( NSDecimalNumber ( decimal: Decimal ( 0 ) ) . doubleValue, 0 )
832
884
XCTAssertEqual ( NSDecimalNumber ( decimal: Decimal ( 1 ) ) . doubleValue, 1 )
@@ -1379,6 +1431,7 @@ class TestDecimal: XCTestCase {
1379
1431
( " test_SimpleMultiplication " , test_SimpleMultiplication) ,
1380
1432
( " test_SmallerNumbers " , test_SmallerNumbers) ,
1381
1433
( " test_ZeroPower " , test_ZeroPower) ,
1434
+ ( " test_parseDouble " , test_parseDouble) ,
1382
1435
( " test_doubleValue " , test_doubleValue) ,
1383
1436
( " test_NSDecimalNumberValues " , test_NSDecimalNumberValues) ,
1384
1437
( " test_bridging " , test_bridging) ,
0 commit comments