Avoid using fpclassify() to detect infinity and nan.

It's not supported in C++98. Instead, use isnan() and isinf(), which
seem to work? If nothing else, they are used elsewhere in Wren, so if
we're not going to use them here, we should fix the other places too.
This commit is contained in:
Bob Nystrom
2017-01-12 21:34:11 -08:00
parent e8dfb1bf10
commit 33a73ef1d5

View File

@ -739,18 +739,20 @@ Value wrenNewStringFromRange(WrenVM* vm, ObjString* source, int start,
Value wrenNumToString(WrenVM* vm, double value)
{
// Corner case: If the value is NaN, different versions of libc produce
// different outputs (some will format it signed and some won't). To get
// reliable output, handle that ourselves.
switch (fpclassify(value))
// Edge case: If the value is NaN or infinity, different versions of libc
// produce different outputs (some will format it signed and some won't). To
// get reliable output, handle it ourselves.
if (isnan(value)) return CONST_STRING(vm, "nan");
if (isinf(value))
{
case FP_INFINITE:
if (signbit(value))
return CONST_STRING(vm, "-infinity");
else
if (value > 0.0)
{
return CONST_STRING(vm, "infinity");
case FP_NAN:
return CONST_STRING(vm, "nan");
}
else
{
return CONST_STRING(vm, "-infinity");
}
}
// This is large enough to hold any double converted to a string using