mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +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)
|
||||
{
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user