Skip to content

Commit 405aaec

Browse files
committed
Use 'Decimal.ulp' to compute 'nextUp' and 'nextDown'.
1 parent 944987e commit 405aaec

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

Darwin/Foundation-swiftoverlay/Decimal.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,15 +557,11 @@ extension Decimal {
557557
}
558558

559559
public var nextUp: Decimal {
560-
return self + Decimal(
561-
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
562-
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
560+
return self + ulp
563561
}
564562

565563
public var nextDown: Decimal {
566-
return self - Decimal(
567-
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
568-
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
564+
return -(-self).nextUp
569565
}
570566

571567
/// The IEEE 754 "class" of this type.

Sources/Foundation/Decimal.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,15 +725,11 @@ extension Decimal {
725725
}
726726

727727
public var nextUp: Decimal {
728-
return self + Decimal(
729-
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
730-
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
728+
return self + ulp
731729
}
732730

733731
public var nextDown: Decimal {
734-
return self - Decimal(
735-
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
736-
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
732+
return -(-self).nextUp
737733
}
738734

739735
/// The IEEE 754 "class" of this type.

0 commit comments

Comments
 (0)