Skip to content

Commit e585897

Browse files
plokhotnyukAndriy Plokhotnyuk
authored andcommitted
Fix Decimal64Codec to use unbiased (banking) rounding
1 parent 6800372 commit e585897

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

jsoniter-scala-macros/jvm/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMakerDecimal64Spec.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ package com.github.plokhotnyuk.jsoniter_scala.macros
33
import com.epam.deltix.dfp.{Decimal64, Decimal64Utils}
44
import com.github.plokhotnyuk.jsoniter_scala.core._
55
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker._
6+
import java.math.MathContext
67

78
class JsonCodecMakerDecimal64Spec extends VerifyingSpec {
89
import Decimal64Codec._
910

1011
"Decimal64Codec" should {
1112
"deserialize both numeric and string representation of numbers to canonized Decimal64 values" in {
1213
verifyDeser(make[List[Decimal64]],
13-
List(Decimal64.ONE_TENTH, Decimal64.MILLION, Decimal64.fromLong(4503599627370497L), Decimal64.parse("1.23456789e+309"), Decimal64.MAX_VALUE),
14-
"""[0.1,"001000000",4503599627370497,1.23456789e+309,"9999999999999999e+369"]""")
14+
List(Decimal64.ONE_TENTH, Decimal64.MILLION, Decimal64.fromLong(4503599627370497L), Decimal64.parse("1.23456789e+309"), Decimal64.MAX_VALUE, Decimal64.parse("0.12345678901234565")),
15+
"""[0.1,"001000000",4503599627370497,1.23456789e+309,"9999999999999999e+369",0.12345678901234565]""")
1516
}
1617
"serialize Decimal64 values into numeric or string representation depending on number of mantissa bits of canonized in-memory representation" in {
1718
verifySer(make[List[Decimal64]],
18-
List(Decimal64.ONE_TENTH, Decimal64.MILLION, Decimal64.fromLong(4503599627370497L), Decimal64.parse("1.23456789e+309"), Decimal64.MAX_VALUE),
19-
"""[0.1,1E+6,"4503599627370497","1.23456789E+309","9.999999999999999E+384"]""")
19+
List(Decimal64.ONE_TENTH, Decimal64.MILLION, Decimal64.fromLong(4503599627370497L), Decimal64.parse("1.23456789e+309"), Decimal64.MAX_VALUE, Decimal64.parse("0.12345678901234565")),
20+
"""[0.1,1E+6,"4503599627370497","1.23456789E+309","9.999999999999999E+384",0.1234567890123456]""")
2021
}
2122
}
2223
}
@@ -30,7 +31,7 @@ object Decimal64Codec {
3031
} else {
3132
in.rollbackToken()
3233
in.readBigDecimal(null)
33-
}).bigDecimal)))
34+
}).bigDecimal.plus(MathContext.DECIMAL64))))
3435

3536
override def encodeValue(x: Decimal64, out: JsonWriter): Unit = {
3637
val cx = Decimal64Utils.canonize(Decimal64.toUnderlying(x))

0 commit comments

Comments
 (0)