1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
10 */
11
12 #include "bsd_privatef.h"
13
bsd__ieee754_remainderf(float x,float p)14 float bsd__ieee754_remainderf(float x, float p)
15 {
16 int32_t hx,hp;
17 u_int32_t sx;
18 float p_half;
19
20 GET_FLOAT_WORD(hx,x);
21 GET_FLOAT_WORD(hp,p);
22 sx = hx&0x80000000;
23 hp &= 0x7fffffff;
24 hx &= 0x7fffffff;
25
26 /* purge off exception values */
27 if(hp==0) return (x*p)/(x*p); /* p = 0 */
28 if((hx>=0x7f800000)|| /* x not finite */
29 ((hp>0x7f800000))) /* p is NaN */
30 return ((long double)x*p)/((long double)x*p);
31
32
33 if (hp<=0x7effffff) x = bsd__ieee754_fmodf(x,p+p); /* now x < 2p */
34 if ((hx-hp)==0) return zero*x;
35 x = fabsf(x);
36 p = fabsf(p);
37 if (hp<0x01000000) {
38 if(x+x>p) {
39 x-=p;
40 if(x+x>=p) x -= p;
41 }
42 } else {
43 p_half = (float)0.5*p;
44 if(x>p_half) {
45 x-=p;
46 if(x>=p_half) x -= p;
47 }
48 }
49 GET_FLOAT_WORD(hx,x);
50 if ((hx&0x7fffffff)==0) hx = 0;
51 SET_FLOAT_WORD(x,hx^sx);
52 return x;
53 }
54