Skip to content

Commit ffd52e5

Browse files
committed
Work around NaN signbit bug on Solaris 11.4 (re: 3dfab7f)
On Solaris 11.4, when ksh is compiled with Solaris Studio cc (but not with gcc), signbit(NAN) returns true and signbit(-NAN) returns false! Which is of course precisely backward. This was showing up as some regression test failures in arith.sh, as of the referenced commit. src/lib/libast/features/float: - Add a test for this bug. src/lib/libast/sfio/sfcvt.c: - This is the function where float values are converted to strings for printf and the arithmetic subsystem. Compile in a workaround (just invert the sign again) if the bug is detected.
1 parent c57dc7a commit ffd52e5

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/lib/libast/features/float

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,3 +1082,13 @@ elif tst need_ast_pow_funs -lm note{ are IEEE pow function replacements needed }
10821082
#endif
10831083
}
10841084
endif
1085+
1086+
# this bug was found on Solaris 11.4 Studio cc
1087+
tst nan_signbit_inverted note{ NaN signbit inverted }end execute{
1088+
#include <math.h>
1089+
int main(void)
1090+
{
1091+
double p = NAN, n = -NAN;
1092+
return !signbit(p) && signbit(n);
1093+
}
1094+
}end

src/lib/libast/sfio/sfcvt.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ char* _sfcvt(void* vp, /* pointer to value to convert */
102102

103103
if (isnan(f))
104104
{
105-
#if _lib_signbit
105+
#if _lib_signbit && _nan_signbit_inverted
106+
if (!signbit(f))
107+
#elif _lib_signbit
106108
if (signbit(f))
107109
#else
108110
if (f < 0)
@@ -250,7 +252,9 @@ char* _sfcvt(void* vp, /* pointer to value to convert */
250252

251253
if(isnan(f))
252254
{
253-
#if _lib_signbit
255+
#if _lib_signbit && _nan_signbit_inverted
256+
if (!signbit(f))
257+
#elif _lib_signbit
254258
if (signbit(f))
255259
#else
256260
if (f < 0)

0 commit comments

Comments
 (0)