Blame sysdeps/ieee754/flt-32/s_floorf.c

Packit 6c4009
/* s_floorf.c -- float version of s_floor.c.
Packit 6c4009
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * ====================================================
Packit 6c4009
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
Packit 6c4009
 *
Packit 6c4009
 * Developed at SunPro, a Sun Microsystems, Inc. business.
Packit 6c4009
 * Permission to use, copy, modify, and distribute this
Packit 6c4009
 * software is freely granted, provided that this notice
Packit 6c4009
 * is preserved.
Packit 6c4009
 * ====================================================
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * floorf(x)
Packit 6c4009
 * Return x rounded toward -inf to integral value
Packit 6c4009
 * Method:
Packit 6c4009
 *	Bit twiddling.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <math.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
#include <libm-alias-float.h>
Packit Service 51ad8b
#include <math-use-builtins.h>
Packit 6c4009
Packit 6c4009
float
Packit Service 3b0880
__floorf(float x)
Packit 6c4009
{
Packit Service 51ad8b
#if USE_FLOORF_BUILTIN
Packit Service 51ad8b
  return __builtin_floorf (x);
Packit Service 51ad8b
#else
Packit Service 51ad8b
  /* Use generic implementation.  */
Packit Service 3b0880
	int32_t i0,j0;
Packit Service 3b0880
	uint32_t i;
Packit Service 3b0880
	GET_FLOAT_WORD(i0,x);
Packit Service 3b0880
	j0 = ((i0>>23)&0xff)-0x7f;
Packit Service 3b0880
	if(j0<23) {
Packit Service 3b0880
	    if(j0<0) {
Packit Service 3b0880
		/* return 0*sign(x) if |x|<1 */
Packit Service 3b0880
		if(i0>=0) {i0=0;}
Packit Service 3b0880
		else if((i0&0x7fffffff)!=0)
Packit Service 3b0880
		  { i0=0xbf800000;}
Packit Service 3b0880
	    } else {
Packit Service 3b0880
		i = (0x007fffff)>>j0;
Packit Service 3b0880
		if((i0&i)==0) return x; /* x is integral */
Packit Service 3b0880
		if(i0<0) i0 += (0x00800000)>>j0;
Packit Service 3b0880
		i0 &= (~i);
Packit Service 3b0880
	    }
Packit Service 3b0880
	} else {
Packit Service 3b0880
	    if(__builtin_expect(j0==0x80, 0)) return x+x; /* inf or NaN */
Packit Service 3b0880
	    else return x;		/* x is integral */
Packit 6c4009
	}
Packit Service 3b0880
	SET_FLOAT_WORD(x,i0);
Packit Service 3b0880
	return x;
Packit Service 51ad8b
#endif /* ! USE_FLOORF_BUILTIN  */
Packit 6c4009
}
Packit 6c4009
#ifndef __floorf
Packit 6c4009
libm_alias_float (__floor, floor)
Packit 6c4009
#endif