Skip to content

Commit 662217d

Browse files
committed
Use 'Decimal.ulp' to compute 'nextUp' and 'nextDown'.
1 parent bb8e7d2 commit 662217d

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

Darwin/Foundation-swiftoverlay/Decimal.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -508,15 +508,11 @@ extension Decimal {
508508
}
509509

510510
public var nextUp: Decimal {
511-
return self + Decimal(
512-
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
513-
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
511+
return self + ulp
514512
}
515513

516514
public var nextDown: Decimal {
517-
return self - Decimal(
518-
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
519-
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
515+
return -(-self).nextUp
520516
}
521517

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

Sources/Foundation/Decimal.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -736,15 +736,11 @@ extension Decimal {
736736
}
737737

738738
public var nextUp: Decimal {
739-
return self + Decimal(
740-
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
741-
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
739+
return self + ulp
742740
}
743741

744742
public var nextDown: Decimal {
745-
return self - Decimal(
746-
_exponent: _exponent, _length: 1, _isNegative: 0, _isCompact: 1,
747-
_reserved: 0, _mantissa: (0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000))
743+
return -(-self).nextUp
748744
}
749745

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

0 commit comments

Comments
 (0)