support for Decimal.isInfitite and isNan
This commit is contained in:
1 parent
a976702caf
commit
6e9333844e
4 files changed
+36
No files matched your search
@@ -94,6 +94,12 @@ object ObjDecimalSupport {
|
||||
decimalClass.addFn("toReal") {
|
||||
ObjReal.of(valueOf(thisObj).doubleValue(false))
|
||||
}
|
||||
decimalClass.addFn("isInfinite") {
|
||||
ObjFalse
|
||||
}
|
||||
decimalClass.addFn("isNaN") {
|
||||
ObjFalse
|
||||
}
|
||||
decimalClass.addFn("toString") {
|
||||
ObjString(valueOf(thisObj).toStringExpanded())
|
||||
}
|
||||
|
||||
@@ -161,6 +161,10 @@ extern class Decimal() {
|
||||
extern fun toInt(): Int
|
||||
/** Convert to `Real`. */
|
||||
extern fun toReal(): Real
|
||||
/** Return true if this decimal is positive or negative infinity. Always false for Decimal. */
|
||||
extern fun isInfinite(): Bool
|
||||
/** Return true if this decimal is NaN (not a number). Always false for Decimal. */
|
||||
extern fun isNaN(): Bool
|
||||
/**
|
||||
* Convert to a plain decimal string without scientific notation.
|
||||
*
|
||||
|
||||
@@ -51,6 +51,21 @@ class DecimalModuleTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDecimalIsInfiniteAndIsNaN() = runTest {
|
||||
val scope = Script.newScope()
|
||||
scope.eval(
|
||||
"""
|
||||
import lyng.decimal
|
||||
|
||||
assertEquals(false, 0.d.isInfinite())
|
||||
assertEquals(false, "12.34".d.isInfinite())
|
||||
assertEquals(false, 0.d.isNaN())
|
||||
assertEquals(false, "12.34".d.isNaN())
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDecimalModuleMixedIntOperators() = runTest {
|
||||
val scope = Script.newScope()
|
||||
|
||||
Reference in new issue
Block a user