fixed Decimal conversion bug

This commit is contained in:
sergeych committed 2026-03-29 03:35:53 +03:00
1 parent aa9565b40b
commit c3c0a3292b
3 files changed
+109 -8

No files matched your search

@@ -88,7 +88,7 @@ object ObjDecimalSupport {
}
decimalClass.addClassFn("fromInt") {
val value = requiredArg<ObjInt>(0).value
newInstance(decimalClass, IonBigDecimal.fromLongAsSignificand(value))
newInstance(decimalClass, IonBigDecimal.fromLong(value))
}
decimalClass.addClassFn("fromReal") {
val value = requiredArg<ObjReal>(0).value
@@ -204,7 +204,7 @@ object ObjDecimalSupport {
}
private fun coerceArg(scope: Scope, value: Obj): IonBigDecimal = when (value) {
is ObjInt -> IonBigDecimal.fromLongAsSignificand(value.value)
is ObjInt -> IonBigDecimal.fromLong(value.value)
is ObjReal -> IonBigDecimal.fromDouble(value.value, realConversionMode)
is ObjInstance -> {
if (value.objClass.className != "Decimal") {
@@ -303,7 +303,7 @@ object ObjDecimalSupport {
doc = "Convert this integer to a Decimal.",
type = type("lyng.decimal.Decimal"),
moduleName = "lyng.decimal",
getter = { newInstance(decimalClass, IonBigDecimal.fromLongAsSignificand(thisAs<ObjInt>().value)) }
getter = { newInstance(decimalClass, IonBigDecimal.fromLong(thisAs<ObjInt>().value)) }
)
ObjInt.type.members["d"] = ObjInt.type.members.getValue("d").copy(typeDecl = decimalTypeDecl)
ObjReal.type.addPropertyDoc(
@@ -347,7 +347,7 @@ object ObjDecimalSupport {
),
leftToCommon = ObjExternCallable.fromBridge {
val value = requiredArg<ObjInt>(0).value
newInstance(decimalClass, IonBigDecimal.fromLongAsSignificand(value))
newInstance(decimalClass, IonBigDecimal.fromLong(value))
},
rightToCommon = ObjExternCallable.fromBridge {
requiredArg<Obj>(0)