conterm/libc/nan64.c

56 lines
921 B
C
Raw Normal View History

2005-08-08 16:50:13 +04: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.
*/
#include <u.h>
#include <libc.h>
#include "nan.h"
// typedef unsigned long long uvlong;
// typedef unsigned long ulong;
static uvlong uvnan = 0x7FF0000000000001ULL;
static uvlong uvinf = 0x7FF0000000000000ULL;
static uvlong uvneginf = 0xFFF0000000000000ULL;
2005-08-08 16:50:13 +04:00
double
__NaN(void)
{
2005-11-08 04:35:49 +03:00
return *(double*)(void*)&uvnan;
2005-08-08 16:50:13 +04:00
}
int
__isNaN(double d)
{
2005-11-08 04:35:49 +03:00
uvlong x = *(uvlong*)(void*)&d;
2005-08-08 16:50:13 +04:00
return (ulong)(x>>32)==0x7FF00000 && !__isInf(d, 0);
}
double
__Inf(int sign)
{
if(sign < 0)
2005-11-08 04:35:49 +03:00
return *(double*)(void*)&uvinf;
2005-08-08 16:50:13 +04:00
else
2005-11-08 04:35:49 +03:00
return *(double*)(void*)&uvneginf;
2005-08-08 16:50:13 +04:00
}
int
__isInf(double d, int sign)
{
uvlong x;
2005-11-08 04:35:49 +03:00
x = *(uvlong*)(void*)&d;
2005-08-08 16:50:13 +04:00
if(sign == 0)
return x==uvinf || x==uvneginf;
else if(sign > 0)
return x==uvinf;
else
return x==uvneginf;
}