Merge remote-tracking branch 'origin/master' into swift-4.0-branch
diff --git a/Foundation/NSDecimal.swift b/Foundation/NSDecimal.swift
index 753b3fd..74eb4be 100644
--- a/Foundation/NSDecimal.swift
+++ b/Foundation/NSDecimal.swift
@@ -327,6 +327,7 @@
     }
 
     public mutating func negate() {
+        guard _length != 0 else { return }
         _isNegative = _isNegative == 0 ? 1 : 0
     }
 }
@@ -1282,9 +1283,7 @@
 
 public func NSDecimalSubtract(_ result: UnsafeMutablePointer<Decimal>, _ leftOperand: UnsafePointer<Decimal>, _ rightOperand: UnsafePointer<Decimal>, _ roundingMode: NSDecimalNumber.RoundingMode) -> NSDecimalNumber.CalculationError {
     var r = rightOperand.pointee
-    if r._length != 0 {
-        r.negate()
-    }
+    r.negate()
     return NSDecimalAdd(result, leftOperand, &r, roundingMode)
 }
 // Exact operations. result may be a pointer to same space as leftOperand or rightOperand
diff --git a/TestFoundation/TestNSDecimal.swift b/TestFoundation/TestNSDecimal.swift
index 6599281..b6d70b1 100644
--- a/TestFoundation/TestNSDecimal.swift
+++ b/TestFoundation/TestNSDecimal.swift
@@ -289,6 +289,9 @@
         XCTAssertEqual(.minus, d.sign)
         d.negate()
         XCTAssertEqual(.plus, d.sign)
+        var e = Decimal(0)
+        e.negate()
+        XCTAssertEqual(e, 0)
         XCTAssertTrue(Decimal(3.5).isEqual(to: Decimal(3.5)))
         XCTAssertTrue(Decimal.nan.isEqual(to: Decimal.nan))
         XCTAssertTrue(Decimal(1.28).isLess(than: Decimal(2.24)))