diff --git a/src/wren_core.c b/src/wren_core.c index 865c550c..74f959ae 100644 --- a/src/wren_core.c +++ b/src/wren_core.c @@ -960,6 +960,8 @@ DEF_PRIMITIVE(num_toString) // different outputs (some will format it signed and some won't). To get // reliable output, handle that ourselves. if (value != value) RETURN_VAL(wrenNewString(vm, "nan", 3)); + if (value == INFINITY) RETURN_VAL(wrenNewString(vm, "infinity", 8)); + if (value == -INFINITY) RETURN_VAL(wrenNewString(vm, "-infinity", 9)); // This is large enough to hold any double converted to a string using // "%.14g". Example: diff --git a/test/number/divide.wren b/test/number/divide.wren index eec03f66..85aef751 100644 --- a/test/number/divide.wren +++ b/test/number/divide.wren @@ -2,11 +2,11 @@ IO.print(8 / 2) // expect: 4 IO.print(12.34 / -0.4) // expect: -30.85 // Divide by zero. -IO.print(3 / 0) // expect: inf -IO.print(-3 / 0) // expect: -inf +IO.print(3 / 0) // expect: infinity +IO.print(-3 / 0) // expect: -infinity IO.print(0 / 0) // expect: nan IO.print(-0 / 0) // expect: nan -IO.print(3 / -0) // expect: -inf -IO.print(-3 / -0) // expect: inf +IO.print(3 / -0) // expect: -infinity +IO.print(-3 / -0) // expect: infinity IO.print(0 / -0) // expect: nan IO.print(-0 / -0) // expect: nan