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

Packit 6c4009
/* e_remainderf.c -- float version of e_remainder.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
#include <math.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
Packit 6c4009
static const float zero = 0.0;
Packit 6c4009
Packit 6c4009
Packit 6c4009
float
Packit 6c4009
__ieee754_remainderf(float x, float p)
Packit 6c4009
{
Packit 6c4009
	int32_t hx,hp;
Packit 6c4009
	uint32_t sx;
Packit 6c4009
	float p_half;
Packit 6c4009
Packit 6c4009
	GET_FLOAT_WORD(hx,x);
Packit 6c4009
	GET_FLOAT_WORD(hp,p);
Packit 6c4009
	sx = hx&0x80000000;
Packit 6c4009
	hp &= 0x7fffffff;
Packit 6c4009
	hx &= 0x7fffffff;
Packit 6c4009
Packit 6c4009
    /* purge off exception values */
Packit 6c4009
	if(hp==0) return (x*p)/(x*p);		/* p = 0 */
Packit 6c4009
	if((hx>=0x7f800000)||			/* x not finite */
Packit 6c4009
	  ((hp>0x7f800000)))			/* p is NaN */
Packit 6c4009
	    return (x*p)/(x*p);
Packit 6c4009
Packit 6c4009
Packit 6c4009
	if (hp<=0x7effffff) x = __ieee754_fmodf(x,p+p);	/* now x < 2p */
Packit 6c4009
	if ((hx-hp)==0) return zero*x;
Packit 6c4009
	x  = fabsf(x);
Packit 6c4009
	p  = fabsf(p);
Packit 6c4009
	if (hp<0x01000000) {
Packit 6c4009
	    if(x+x>p) {
Packit 6c4009
		x-=p;
Packit 6c4009
		if(x+x>=p) x -= p;
Packit 6c4009
	    }
Packit 6c4009
	} else {
Packit 6c4009
	    p_half = (float)0.5*p;
Packit 6c4009
	    if(x>p_half) {
Packit 6c4009
		x-=p;
Packit 6c4009
		if(x>=p_half) x -= p;
Packit 6c4009
	    }
Packit 6c4009
	}
Packit 6c4009
	GET_FLOAT_WORD(hx,x);
Packit 6c4009
	SET_FLOAT_WORD(x,hx^sx);
Packit 6c4009
	return x;
Packit 6c4009
}
Packit 6c4009
strong_alias (__ieee754_remainderf, __remainderf_finite)