Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially fix Decimal.ulp to return a valid representation. #3014

Merged
merged 1 commit into from Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion Darwin/Foundation-swiftoverlay-Tests/TestDecimal.swift
Expand Up @@ -209,7 +209,7 @@ class TestDecimal : XCTestCase {

let ulp = explicit.ulp
XCTAssertEqual(0x7f, ulp.exponent)
XCTAssertEqual(8, ulp._length)
XCTAssertEqual(1, ulp._length)
XCTAssertEqual(0, ulp._isNegative)
XCTAssertEqual(1, ulp._isCompact)
XCTAssertEqual(0, ulp._reserved)
Expand Down Expand Up @@ -588,6 +588,11 @@ class TestDecimal : XCTestCase {
}
}
}

func test_ULP() {
let x = 0.1 as Decimal
XCTAssertFalse(x.ulp > x)
}

func test_unconditionallyBridgeFromObjectiveC() {
XCTAssertEqual(Decimal(), Decimal._unconditionallyBridgeFromObjectiveC(nil))
Expand Down
2 changes: 1 addition & 1 deletion Darwin/Foundation-swiftoverlay/Decimal.swift
Expand Up @@ -503,7 +503,7 @@ extension Decimal {
public var ulp: Decimal {
if !self.isFinite { return Decimal.nan }
return Decimal(
_exponent: _exponent, _length: 8, _isNegative: 0, _isCompact: 1,
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Foundation/Decimal.swift
Expand Up @@ -731,7 +731,7 @@ extension Decimal {
public var ulp: Decimal {
if !self.isFinite { return Decimal.nan }
return Decimal(
_exponent: _exponent, _length: 8, _isNegative: 0, _isCompact: 1,
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
}

Expand Down
8 changes: 7 additions & 1 deletion Tests/Foundation/Tests/TestDecimal.swift
Expand Up @@ -271,7 +271,7 @@ class TestDecimal: XCTestCase {

let ulp = explicit.ulp
XCTAssertEqual(0x7f, ulp.exponent)
XCTAssertEqual(8, ulp._length)
XCTAssertEqual(1, ulp._length)
XCTAssertEqual(0, ulp._isNegative)
XCTAssertEqual(1, ulp._isCompact)
XCTAssertEqual(0, ulp._reserved)
Expand Down Expand Up @@ -851,6 +851,11 @@ class TestDecimal: XCTestCase {

XCTAssertEqual(100,number.objCType.pointee, "ObjC type for NSDecimalNumber is 'd'")
}

func test_ULP() {
let x = 0.1 as Decimal
XCTAssertFalse(x.ulp > x)
}

func test_ZeroPower() {
let six = NSDecimalNumber(integerLiteral: 6)
Expand Down Expand Up @@ -1457,6 +1462,7 @@ class TestDecimal: XCTestCase {
("test_ScanDecimal", test_ScanDecimal),
("test_SimpleMultiplication", test_SimpleMultiplication),
("test_SmallerNumbers", test_SmallerNumbers),
("test_ULP", test_ULP),
("test_ZeroPower", test_ZeroPower),
("test_parseDouble", test_parseDouble),
("test_doubleValue", test_doubleValue),
Expand Down