mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
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:
@ -739,18 +739,20 @@ Value wrenNewStringFromRange(WrenVM* vm, ObjString* source, int start,
|
|||||||
|
|
||||||
Value wrenNumToString(WrenVM* vm, double value)
|
Value wrenNumToString(WrenVM* vm, double value)
|
||||||
{
|
{
|
||||||
// Corner case: If the value is NaN, different versions of libc produce
|
// Edge case: If the value is NaN or infinity, different versions of libc
|
||||||
// different outputs (some will format it signed and some won't). To get
|
// produce different outputs (some will format it signed and some won't). To
|
||||||
// reliable output, handle that ourselves.
|
// get reliable output, handle it ourselves.
|
||||||
switch (fpclassify(value))
|
if (isnan(value)) return CONST_STRING(vm, "nan");
|
||||||
|
if (isinf(value))
|
||||||
{
|
{
|
||||||
case FP_INFINITE:
|
if (value > 0.0)
|
||||||
if (signbit(value))
|
{
|
||||||
return CONST_STRING(vm, "-infinity");
|
|
||||||
else
|
|
||||||
return CONST_STRING(vm, "infinity");
|
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
|
// This is large enough to hold any double converted to a string using
|
||||||
|
|||||||
Reference in New Issue
Block a user