/*
 *      f l o o r
 */

#define __LIBRARY__

#include <math.h>

double floor  _LIB_F1_(double, x)
{
#if 0
    double fract;
    double ipart;

    if ((fract = modf(x, &ipart)) < 0.0) {
        return ipart - 1.0;
    }

    return ipart;
#else

#define MIEEE 1
#ifdef MIEEE
#define EXPMSK 0x800f
#define MEXP 0x7ff
#define NBITS 53
#endif

/* Bit clearing masks: */

static unsigned short bmask[] = {
0xffff,
0xfffe,
0xfffc,
0xfff8,
0xfff0,
0xffe0,
0xffc0,
0xff80,
0xff00,
0xfe00,
0xfc00,
0xf800,
0xf000,
0xe000,
0xc000,
0x8000,
0x0000,
};


unsigned short *p;
double y;
int e;

#ifdef UNK
mtherr( "floor", DOMAIN );
return(0.0);
#endif

y = x;
/* find the exponent (power of 2) */
#ifdef DEC
p = (unsigned short *)&y;
e = (( *p  >> 7) & 0377) - 0201;
p += 3;
#endif

#ifdef IBMPC
p = (unsigned short *)&y + 3;
e = (( *p >> 4) & 0x7ff) - 0x3ff;
p -= 3;
#endif

#ifdef MIEEE
p = (unsigned short *)&y;
e = (( *p >> 4) & 0x7ff) - 0x3ff;
p += 3;
#endif

if( e < 0 )
        {
        if( y < 0.0 )
                return( -1.0 );
        else
                return( 0.0 );
        }
e = (NBITS -1) - e;
/* clean out 16 bits at a time */
while( e >= 16 )
        {
#ifdef IBMPC
        *p++ = 0;
#endif

#ifdef DEC
        *p-- = 0;
#endif

#ifdef MIEEE
        *p-- = 0;
#endif
        e -= 16;
        }

/* clear the remaining bits */
if( e > 0 )
        *p &= bmask[e];

if( (x < 0) && (y != x) )
        y -= 1.0;

return(y);

#endif
}

