@@ -281,12 +281,12 @@ extension _StructuredFieldEncoder: SingleValueEncodingContainer {
281
281
}
282
282
283
283
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.
285
285
guard let exponent = Int8 ( exactly: data. exponent) else {
286
286
throw StructuredHeaderError . invalidIntegerOrDecimal
287
287
}
288
288
289
- let pd = PseudoDecimal ( mantissa: significand, exponent: Int ( exponent) )
289
+ let pd = PseudoDecimal ( mantissa: significand * ( data . isSignMinus ? - 1 : 1 ) , exponent: Int ( exponent) )
290
290
try self . currentStackEntry. storage. insertBareItem ( . decimal( pd) )
291
291
}
292
292
@@ -438,12 +438,12 @@ extension _StructuredFieldEncoder {
438
438
}
439
439
440
440
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.
442
442
guard let exponent = Int8 ( exactly: value. exponent) else {
443
443
throw StructuredHeaderError . invalidIntegerOrDecimal
444
444
}
445
445
446
- let pd = PseudoDecimal ( mantissa: significand, exponent: Int ( exponent) )
446
+ let pd = PseudoDecimal ( mantissa: significand * ( value . isSignMinus ? - 1 : 1 ) , exponent: Int ( exponent) )
447
447
try self . currentStackEntry. storage. appendBareItem ( . decimal( pd) )
448
448
}
449
449
@@ -605,12 +605,12 @@ extension _StructuredFieldEncoder {
605
605
}
606
606
607
607
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.
609
609
guard let exponent = Int8 ( exactly: value. exponent) else {
610
610
throw StructuredHeaderError . invalidIntegerOrDecimal
611
611
}
612
612
613
- let pd = PseudoDecimal ( mantissa: significand, exponent: Int ( exponent) )
613
+ let pd = PseudoDecimal ( mantissa: significand * ( value . isSignMinus ? - 1 : 1 ) , exponent: Int ( exponent) )
614
614
try self . currentStackEntry. storage. insertBareItem ( . decimal( pd) , atKey: key)
615
615
}
616
616
0 commit comments