Skip to content

Commit 7b1fad5

Browse files
committed
---
yaml --- r: 323375 b: refs/heads/tensorflow-next c: 1f7ffb1 h: refs/heads/master i: 323373: e64d7cc 323371: a8eeb80 323367: 5b804d2 323359: dc1d878
1 parent bf28b19 commit 7b1fad5

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,4 +1461,4 @@ refs/heads/master-rebranch: 86e95c23aa0d37f24ec138b7853146c1cead2e40
14611461
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14621462
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14631463
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec
1464-
refs/heads/tensorflow-next: 96b21ef468c504d6159ca1bc76a53b8839b8b877
1464+
refs/heads/tensorflow-next: 1f7ffb10ce8f76115894bf8fc06b68f478b07dad

branches/tensorflow-next/stdlib/public/Darwin/Foundation/Decimal.swift

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,32 @@ public func pow(_ x: Decimal, _ y: Int) -> Decimal {
150150
}
151151

152152
extension Decimal : Hashable, Comparable {
153-
internal var doubleValue : Double {
153+
private subscript(index: UInt32) -> UInt16 {
154+
get {
155+
switch index {
156+
case 0: return _mantissa.0
157+
case 1: return _mantissa.1
158+
case 2: return _mantissa.2
159+
case 3: return _mantissa.3
160+
case 4: return _mantissa.4
161+
case 5: return _mantissa.5
162+
case 6: return _mantissa.6
163+
case 7: return _mantissa.7
164+
default: fatalError("Invalid index \(index) for _mantissa")
165+
}
166+
}
167+
}
168+
169+
internal var doubleValue: Double {
170+
if _length == 0 {
171+
return _isNegative == 1 ? Double.nan : 0
172+
}
173+
154174
var d = 0.0
155-
if _length == 0 && _isNegative == 0 {
156-
return Double.nan
175+
for idx in (0..<min(_length, 8)).reversed() {
176+
d = d * 65536 + Double(self[idx])
157177
}
158178

159-
d = d * 65536 + Double(_mantissa.7)
160-
d = d * 65536 + Double(_mantissa.6)
161-
d = d * 65536 + Double(_mantissa.5)
162-
d = d * 65536 + Double(_mantissa.4)
163-
d = d * 65536 + Double(_mantissa.3)
164-
d = d * 65536 + Double(_mantissa.2)
165-
d = d * 65536 + Double(_mantissa.1)
166-
d = d * 65536 + Double(_mantissa.0)
167-
168179
if _exponent < 0 {
169180
for _ in _exponent..<0 {
170181
d /= 10.0
@@ -212,6 +223,7 @@ extension Decimal : ExpressibleByIntegerLiteral {
212223

213224
extension Decimal : SignedNumeric {
214225
public var magnitude: Decimal {
226+
guard _length != 0 else { return self }
215227
return Decimal(
216228
_exponent: self._exponent, _length: self._length,
217229
_isNegative: 0, _isCompact: self._isCompact,

branches/tensorflow-next/test/stdlib/TestDecimal.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ class TestDecimal : TestDecimalSuper {
303303
expectEqual(Decimal(68040), Decimal(386).advanced(by: Decimal(67654)))
304304
expectEqual(Decimal(1.234), abs(Decimal(1.234)))
305305
expectEqual(Decimal(1.234), abs(Decimal(-1.234)))
306+
expectTrue(Decimal.nan.magnitude.isNaN)
306307
var a = Decimal(1234)
307308
var r = a
308309
expectEqual(.noError, NSDecimalMultiplyByPowerOf10(&r, &a, 1, .plain))

0 commit comments

Comments
 (0)