2005-08-08 14:50:13 +02:00
|
|
|
/*
|
|
|
|
* 64-bit IEEE not-a-number routines.
|
|
|
|
* This is big/little-endian portable assuming that
|
|
|
|
* the 64-bit doubles and 64-bit integers have the
|
|
|
|
* same byte ordering.
|
|
|
|
*/
|
|
|
|
|
2006-01-17 14:55:02 +01:00
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
2006-01-17 13:37:52 +01:00
|
|
|
#include "fmtdef.h"
|
2005-08-08 14:50:13 +02:00
|
|
|
|
2006-01-17 13:37:52 +01:00
|
|
|
#if defined (__APPLE__) || (__powerpc__)
|
|
|
|
#define _NEEDLL
|
|
|
|
#endif
|
2005-08-08 14:50:13 +02:00
|
|
|
|
2006-01-17 13:37:52 +01:00
|
|
|
static uvlong uvnan = ((uvlong)0x7FF00000<<32)|0x00000001;
|
|
|
|
static uvlong uvinf = ((uvlong)0x7FF00000<<32)|0x00000000;
|
|
|
|
static uvlong uvneginf = ((uvlong)0xFFF00000<<32)|0x00000000;
|
2005-08-08 14:50:13 +02:00
|
|
|
|
|
|
|
double
|
|
|
|
__NaN(void)
|
|
|
|
{
|
2006-01-17 13:37:52 +01:00
|
|
|
uvlong *p;
|
|
|
|
|
|
|
|
/* gcc complains about "return *(double*)&uvnan;" */
|
|
|
|
p = &uvnan;
|
|
|
|
return *(double*)p;
|
2005-08-08 14:50:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
__isNaN(double d)
|
|
|
|
{
|
2006-01-17 13:37:52 +01:00
|
|
|
uvlong x;
|
|
|
|
double *p;
|
|
|
|
|
|
|
|
p = &d;
|
|
|
|
x = *(uvlong*)p;
|
2005-08-08 14:50:13 +02:00
|
|
|
return (ulong)(x>>32)==0x7FF00000 && !__isInf(d, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
__Inf(int sign)
|
|
|
|
{
|
2006-01-17 13:37:52 +01:00
|
|
|
uvlong *p;
|
|
|
|
|
2005-08-08 14:50:13 +02:00
|
|
|
if(sign < 0)
|
2006-01-17 13:37:52 +01:00
|
|
|
p = &uvinf;
|
2005-08-08 14:50:13 +02:00
|
|
|
else
|
2006-01-17 13:37:52 +01:00
|
|
|
p = &uvneginf;
|
|
|
|
return *(double*)p;
|
2005-08-08 14:50:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
__isInf(double d, int sign)
|
|
|
|
{
|
|
|
|
uvlong x;
|
2006-01-17 13:37:52 +01:00
|
|
|
double *p;
|
2005-08-08 14:50:13 +02:00
|
|
|
|
2006-01-17 13:37:52 +01:00
|
|
|
p = &d;
|
|
|
|
x = *(uvlong*)p;
|
2005-08-08 14:50:13 +02:00
|
|
|
if(sign == 0)
|
|
|
|
return x==uvinf || x==uvneginf;
|
|
|
|
else if(sign > 0)
|
|
|
|
return x==uvinf;
|
|
|
|
else
|
|
|
|
return x==uvneginf;
|
|
|
|
}
|