From 33a73ef1d50c32db0cf31559dd3e1cdc46f21ffd Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Thu, 12 Jan 2017 21:34:11 -0800 Subject: [PATCH] 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. --- src/vm/wren_value.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/vm/wren_value.c b/src/vm/wren_value.c index fcdecf04..d76dc86f 100644 --- a/src/vm/wren_value.c +++ b/src/vm/wren_value.c @@ -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