@@ -281,12 +281,12 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
281281 }
282282
283283 func encode( _ data: Decimal ) throws {
284- let significand = ( data. significand as NSNumber ) . intValue // Yes, really.
284+ let significand = ( data. significand. magnitude as NSNumber ) . intValue // Yes, really.
285285 guard let exponent = Int8 ( exactly: data. exponent) else {
286286 throw StructuredHeaderError . invalidIntegerOrDecimal
287287 }
288288
289- let pd = PseudoDecimal ( mantissa: significand, exponent: Int ( exponent) )
289+ let pd = PseudoDecimal ( mantissa: significand * ( data . isSignMinus ? - 1 : 1 ) , exponent: Int ( exponent) )
290290 try self . currentStackEntry. storage. insertBareItem ( . decimal( pd) )
291291 }
292292
@@ -438,12 +438,12 @@ extension _StructuredFieldEncoder {
438438 }
439439
440440 func append( _ value: Decimal ) throws {
441- let significand = ( value. significand as NSNumber ) . intValue // Yes, really.
441+ let significand = ( value. significand. magnitude as NSNumber ) . intValue // Yes, really.
442442 guard let exponent = Int8 ( exactly: value. exponent) else {
443443 throw StructuredHeaderError . invalidIntegerOrDecimal
444444 }
445445
446- let pd = PseudoDecimal ( mantissa: significand, exponent: Int ( exponent) )
446+ let pd = PseudoDecimal ( mantissa: significand * ( value . isSignMinus ? - 1 : 1 ) , exponent: Int ( exponent) )
447447 try self . currentStackEntry. storage. appendBareItem ( . decimal( pd) )
448448 }
449449
@@ -605,12 +605,12 @@ extension _StructuredFieldEncoder {
605605 }
606606
607607 func encode( _ value: Decimal , forKey key: String ) throws {
608- let significand = ( value. significand as NSNumber ) . intValue // Yes, really.
608+ let significand = ( value. significand. magnitude as NSNumber ) . intValue // Yes, really.
609609 guard let exponent = Int8 ( exactly: value. exponent) else {
610610 throw StructuredHeaderError . invalidIntegerOrDecimal
611611 }
612612
613- let pd = PseudoDecimal ( mantissa: significand, exponent: Int ( exponent) )
613+ let pd = PseudoDecimal ( mantissa: significand * ( value . isSignMinus ? - 1 : 1 ) , exponent: Int ( exponent) )
614614 try self . currentStackEntry. storage. insertBareItem ( . decimal( pd) , atKey: key)
615615 }
616616
0 commit comments