1: 2: 3:
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: 17: 18: 19: 20:
21:
22: #include "math.h"
23: #include "math_private.h"
24:
25: static const float one = 1.0, Zero[] = {0.0, -0.0,};
26:
27: float
28: fmodf(float x, float y)
29: {
30: int32_t n,hx,hy,hz,ix,iy,sx,i;
31:
32: GET_FLOAT_WORD(hx,x);
33: GET_FLOAT_WORD(hy,y);
34: sx = hx&0x80000000;
35: hx ^=sx;
36: hy &= 0x7fffffff;
37:
38:
39: if(hy==0||(hx>=0x7f800000)||
40: (hy>0x7f800000))
41: return (x*y)/(x*y);
42: if(hx<hy) return x;
43: if(hx==hy)
44: return Zero[(u_int32_t)sx>>31];
45:
46:
47: if(hx<0x00800000) {
48: for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1;
49: } else ix = (hx>>23)-127;
50:
51:
52: if(hy<0x00800000) {
53: for (iy = -126,i=(hy<<8); i>=0; i<<=1) iy -=1;
54: } else iy = (hy>>23)-127;
55:
56:
57: if(ix >= -126)
58: hx = 0x00800000|(0x007fffff&hx);
59: else {
60: n = -126-ix;
61: hx = hx<<n;
62: }
63: if(iy >= -126)
64: hy = 0x00800000|(0x007fffff&hy);
65: else {
66: n = -126-iy;
67: hy = hy<<n;
68: }
69:
70:
71: n = ix - iy;
72: while(n--) {
73: hz=hx-hy;
74: if(hz<0){hx = hx+hx;}
75: else {
76: if(hz==0)
77: return Zero[(u_int32_t)sx>>31];
78: hx = hz+hz;
79: }
80: }
81: hz=hx-hy;
82: if(hz>=0) {hx=hz;}
83:
84:
85: if(hx==0)
86: return Zero[(u_int32_t)sx>>31];
87: while(hx<0x00800000) {
88: hx = hx+hx;
89: iy -= 1;
90: }
91: if(iy>= -126) {
92: hx = ((hx-0x00800000)|((iy+127)<<23));
93: SET_FLOAT_WORD(x,hx|sx);
94: } else {
95: n = -126 - iy;
96: hx >>= n;
97: SET_FLOAT_WORD(x,hx|sx);
98: x *= one;
99: }
100: return x;
101: }