#include <9pm/u.h>
#include <9pm/libc.h>

#define	NANEXP	(2047<<20)
#define	NANMASK	(2047<<20)
#define	NANSIGN	(1<<31)

static uvlong uvnan    = 0x7FF0000000000001;
static uvlong uvinf    = 0x7FF0000000000000;
static uvlong uvneginf = 0xFFF0000000000000;

double
NaN(void)
{
	return *(double*)&uvnan;
}

int
isNaN(double d)
{
	uvlong x = *(uvlong*)&d;
	return ((ulong)x>>32)==0x7FF00000 && !isInf(d, 0);
}

double
Inf(int sign)
{
	if(sign < 0)
		return *(double*)&uvinf;
	else
		return *(double*)&uvneginf;
}

int
isInf(double d, int sign)
{
	uvlong x;

	x = *(uvlong*)&d;
	if(sign == 0)
		return x==uvinf || x==uvneginf;
	else if(sign > 0)
		return x==uvinf;
	else
		return x==uvneginf;
}
