gdtoa-hexnan-fbsd.c [plain text]
#include "gdtoaimp.h"
#include <fpmath.h>
static void
#ifdef KR_headers
L_shift(x, x1, i) ULong *x; ULong *x1; int i;
#else
L_shift(ULong *x, ULong *x1, int i)
#endif
{
int j;
i = 8 - i;
i <<= 2;
j = ULbits - i;
do {
*x |= x[1] << j;
x[1] >>= i;
} while(++x < x1);
}
int
#ifdef KR_headers
hexnan(sp, fpi, x0)
CONST char **sp; FPI *fpi; ULong *x0;
#else
hexnan( CONST char **sp, FPI *fpi, ULong *x0)
#endif
{
int nbits, len;
char *cp;
CONST char *s;
if (sp == NULL || *sp == NULL || **sp != '(')
return STRTOG_NaN;
s = *sp;
if ((cp = strchr(s + 1, ')')) == NULL) {
*sp += strlen(s);
cp = s + 1;
}
else {
len = cp - (s + 1);
cp = alloca(len + 1);
if (!cp)
return STRTOG_NaN;
strlcpy(cp, s + 1, len + 1);
*sp += len + 2;
}
nbits = fpi->nbits;
if (nbits == 52) {
union IEEEd2bits u;
u.d = nan(cp);
x0[1] = u.bits.manh;
x0[0] = u.bits.manl;
}
else if (nbits < 52) {
union IEEEf2bits u;
u.f = nanf(cp);
x0[0] = u.bits.man;
}
else {
union IEEEl2bits u;
u.e = nanl(cp);
#if defined(__ppc__) || defined(__ppc64__)
x0[3] = (ULong)(u.bits.manh >> 44);
x0[2] = (ULong)(u.bits.manh >> 12);
x0[1] = ((ULong)u.bits.manh & 0xfff) << 20 | (ULong)(u.bits.manl >> 32);
x0[0] = (ULong)u.bits.manl;
#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__)
x0[1] = (ULong)u.bits.manh;
x0[0] = (ULong)u.bits.manl;
#else
#error unsupported architecture
#endif
}
return STRTOG_NaNbits;
}