Skip to content

Commit cf00df2

Browse files
xwudrexin
authored andcommitted
Partially fix Decimal.ulp to return a valid representation.
1 parent 8c439c5 commit cf00df2

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

Darwin/Foundation-swiftoverlay-Tests/TestDecimal.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class TestDecimal : XCTestCase {
209209

210210
let ulp = explicit.ulp
211211
XCTAssertEqual(0x7f, ulp.exponent)
212-
XCTAssertEqual(8, ulp._length)
212+
XCTAssertEqual(1, ulp._length)
213213
XCTAssertEqual(0, ulp._isNegative)
214214
XCTAssertEqual(1, ulp._isCompact)
215215
XCTAssertEqual(0, ulp._reserved)
@@ -588,6 +588,11 @@ class TestDecimal : XCTestCase {
588588
}
589589
}
590590
}
591+
592+
func test_ULP() {
593+
let x = 0.1 as Decimal
594+
XCTAssertFalse(x.ulp > x)
595+
}
591596

592597
func test_unconditionallyBridgeFromObjectiveC() {
593598
XCTAssertEqual(Decimal(), Decimal._unconditionallyBridgeFromObjectiveC(nil))

Darwin/Foundation-swiftoverlay/Decimal.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ extension Decimal {
503503
public var ulp: Decimal {
504504
if !self.isFinite { return Decimal.nan }
505505
return Decimal(
506-
_exponent: _exponent, _length: 8, _isNegative: 0, _isCompact: 1,
506+
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
507507
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
508508
}
509509

Sources/Foundation/Decimal.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ extension Decimal {
731731
public var ulp: Decimal {
732732
if !self.isFinite { return Decimal.nan }
733733
return Decimal(
734-
_exponent: _exponent, _length: 8, _isNegative: 0, _isCompact: 1,
734+
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
735735
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
736736
}
737737

Tests/Foundation/Tests/TestDecimal.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class TestDecimal: XCTestCase {
271271

272272
let ulp = explicit.ulp
273273
XCTAssertEqual(0x7f, ulp.exponent)
274-
XCTAssertEqual(8, ulp._length)
274+
XCTAssertEqual(1, ulp._length)
275275
XCTAssertEqual(0, ulp._isNegative)
276276
XCTAssertEqual(1, ulp._isCompact)
277277
XCTAssertEqual(0, ulp._reserved)
@@ -824,6 +824,11 @@ class TestDecimal: XCTestCase {
824824

825825
XCTAssertEqual(100,number.objCType.pointee, "ObjC type for NSDecimalNumber is 'd'")
826826
}
827+
828+
func test_ULP() {
829+
let x = 0.1 as Decimal
830+
XCTAssertFalse(x.ulp > x)
831+
}
827832

828833
func test_ZeroPower() {
829834
let six = NSDecimalNumber(integerLiteral: 6)
@@ -1430,6 +1435,7 @@ class TestDecimal: XCTestCase {
14301435
("test_ScanDecimal", test_ScanDecimal),
14311436
("test_SimpleMultiplication", test_SimpleMultiplication),
14321437
("test_SmallerNumbers", test_SmallerNumbers),
1438+
("test_ULP", test_ULP),
14331439
("test_ZeroPower", test_ZeroPower),
14341440
("test_parseDouble", test_parseDouble),
14351441
("test_doubleValue", test_doubleValue),

0 commit comments

Comments
 (0)