1 /* e_fmodf.c -- float version of e_fmod.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
13 * ====================================================
17 static char rcsid
[] = "$FreeBSD: src/lib/msun/src/e_fmodf.c,v 1.7 2008/02/22 02:30:34 das Exp $";
21 * __ieee754_fmodf(x,y)
22 * Return x mod y in exact arithmetic
23 * Method: shift and subtract
27 #include "math_private.h"
29 static const float one
= 1.0, Zero
[] = {0.0, -0.0,};
32 __ieee754_fmodf(float x
, float y
)
34 int32_t n
,hx
,hy
,hz
,ix
,iy
,sx
,i
;
38 sx
= hx
&0x80000000; /* sign of x */
40 hy
&= 0x7fffffff; /* |y| */
42 /* purge off exception values */
43 if(hy
==0||(hx
>=0x7f800000)|| /* y=0,or x not finite */
44 (hy
>0x7f800000)) /* or y is NaN */
46 if(hx
<hy
) return x
; /* |x|<|y| return x */
48 return Zero
[(uint32_t)sx
>>31]; /* |x|=|y| return x*0*/
50 /* determine ix = ilogb(x) */
51 if(hx
<0x00800000) { /* subnormal x */
52 for (ix
= -126,i
=(hx
<<8); i
>0; i
<<=1) ix
-=1;
53 } else ix
= (hx
>>23)-127;
55 /* determine iy = ilogb(y) */
56 if(hy
<0x00800000) { /* subnormal y */
57 for (iy
= -126,i
=(hy
<<8); i
>=0; i
<<=1) iy
-=1;
58 } else iy
= (hy
>>23)-127;
60 /* set up {hx,lx}, {hy,ly} and align y to x */
62 hx
= 0x00800000|(0x007fffff&hx
);
63 else { /* subnormal x, shift x to normal */
68 hy
= 0x00800000|(0x007fffff&hy
);
69 else { /* subnormal y, shift y to normal */
80 if(hz
==0) /* return sign(x)*0 */
81 return Zero
[(uint32_t)sx
>>31];
88 /* convert back to floating value and restore the sign */
89 if(hx
==0) /* return sign(x)*0 */
90 return Zero
[(uint32_t)sx
>>31];
91 while(hx
<0x00800000) { /* normalize x */
95 if(iy
>= -126) { /* normalize output */
96 hx
= ((hx
-0x00800000)|((iy
+127)<<23));
97 SET_FLOAT_WORD(x
,hx
|sx
);
98 } else { /* subnormal output */
101 SET_FLOAT_WORD(x
,hx
|sx
);
102 x
*= one
; /* create necessary signal */
104 return x
; /* exact output */