mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-24 04:37:50 +00:00
Update for open-source Decimal fixes (#16)
* Update to future-proof usage of Decimal.significand * Update all remaining uses of Decimal.significand * Update usage of `Decimal(sign:exponent:significand:)` * Apply suggestions from code review Co-authored-by: Cory Benfield <lukasa@apple.com> Co-authored-by: Cory Benfield <lukasa@apple.com>
This commit is contained in:
1 parent
e31cbd3120
commit
8c5c9aa00d
2 files changed
+7
-7
No files matched your search
@@ -281,12 +281,12 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
|
||||
}
|
||||
|
||||
func encode(_ data: Decimal) throws {
|
||||
let significand = (data.significand as NSNumber).intValue // Yes, really.
|
||||
let significand = (data.significand.magnitude as NSNumber).intValue // Yes, really.
|
||||
guard let exponent = Int8(exactly: data.exponent) else {
|
||||
throw StructuredHeaderError.invalidIntegerOrDecimal
|
||||
}
|
||||
|
||||
let pd = PseudoDecimal(mantissa: significand, exponent: Int(exponent))
|
||||
let pd = PseudoDecimal(mantissa: significand * (data.isSignMinus ? -1 : 1), exponent: Int(exponent))
|
||||
try self.currentStackEntry.storage.insertBareItem(.decimal(pd))
|
||||
}
|
||||
|
||||
@@ -438,12 +438,12 @@ extension _StructuredFieldEncoder {
|
||||
}
|
||||
|
||||
func append(_ value: Decimal) throws {
|
||||
let significand = (value.significand as NSNumber).intValue // Yes, really.
|
||||
let significand = (value.significand.magnitude as NSNumber).intValue // Yes, really.
|
||||
guard let exponent = Int8(exactly: value.exponent) else {
|
||||
throw StructuredHeaderError.invalidIntegerOrDecimal
|
||||
}
|
||||
|
||||
let pd = PseudoDecimal(mantissa: significand, exponent: Int(exponent))
|
||||
let pd = PseudoDecimal(mantissa: significand * (value.isSignMinus ? -1 : 1), exponent: Int(exponent))
|
||||
try self.currentStackEntry.storage.appendBareItem(.decimal(pd))
|
||||
}
|
||||
|
||||
@@ -605,12 +605,12 @@ extension _StructuredFieldEncoder {
|
||||
}
|
||||
|
||||
func encode(_ value: Decimal, forKey key: String) throws {
|
||||
let significand = (value.significand as NSNumber).intValue // Yes, really.
|
||||
let significand = (value.significand.magnitude as NSNumber).intValue // Yes, really.
|
||||
guard let exponent = Int8(exactly: value.exponent) else {
|
||||
throw StructuredHeaderError.invalidIntegerOrDecimal
|
||||
}
|
||||
|
||||
let pd = PseudoDecimal(mantissa: significand, exponent: Int(exponent))
|
||||
let pd = PseudoDecimal(mantissa: significand * (value.isSignMinus ? -1 : 1), exponent: Int(exponent))
|
||||
try self.currentStackEntry.storage.insertBareItem(.decimal(pd), atKey: key)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user