ftp.nice.ch/pub/next/developer/hardware/m68k/libjv.1.0.N.s.tar.gz#/libjv/floor.c

This is floor.c in view mode; [Download] [Up]

double floor(x)
double x;
{
/*
	Routine determines the largest integer that is smaller than x.
	The return value is a double again.
	We have to use the IEEE explicitly here.
	Routine made by J.A.M. Vermaseren 20-apr-1992
*/
	double scr, y;
	int n;
	y = x;
	if ( y < 0 ) y = -y;
	scr = y;
	n = *((short *)(&scr));
	if ( n < 0 ) n = -n;
	n -= 0x3FF0;
	n >>= 4;
	if ( n < 0 ) { /* exponent < 0 --> trivial */
		if ( x < 0 ) return(-1.);
		else return(0.);
	}
/*
	There are 53 bits of which 52 after the period. This means that
	if n >= 52 we cannot do anything.
*/
	if ( n >= 52 ) return(x);
	if ( n <= 20 ) {
		((long *)(&scr))[1] = 0;
		n = 20 - n;
		((long *)(&scr))[0] &= (-1) << n;
	}
	else {
		n = 52 - n;
		((long *)(&scr))[1] &= (-1) << n;
	}
	if ( x < 0 ) x = -scr-1;
	else x = scr;
	return(x);
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.