support for Real.isInfitite and isNan

This commit is contained in:
sergeych committed 2026-03-31 19:08:11 +03:00
1 parent 850efedb72
commit a976702caf
4 files changed
+134

No files matched your search

@@ -155,6 +155,22 @@ data class ObjReal(val value: Double) : Obj(), Numeric {
) {
ObjInt.of(thisAs<ObjReal>().value.toLong())
}
addFnDoc(
name = "isInfinite",
doc = "Return true if this real number is positive or negative infinity.",
returns = type("lyng.Bool"),
moduleName = "lyng.stdlib"
) {
ObjBool(thisAs<ObjReal>().value.isInfinite())
}
addFnDoc(
name = "isNaN",
doc = "Return true if this real number is NaN (not a number).",
returns = type("lyng.Bool"),
moduleName = "lyng.stdlib"
) {
ObjBool(thisAs<ObjReal>().value.isNaN())
}
}
}
}
@@ -5271,6 +5271,19 @@ class ScriptTest {
)
}
@Test
fun testRealIsInfiniteAndIsNaN() = runTest {
eval(
"""
assertEquals(false, 1.0.isInfinite())
assertEquals(true, (1.0 / 0.0).isInfinite())
assertEquals(true, (-1.0 / 0.0).isInfinite())
assertEquals(false, 1.0.isNaN())
assertEquals(true, (0.0 / 0.0).isNaN())
""".trimIndent()
)
}
@Test
fun testEmptySpreadList() = runTest {
eval(