Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / mathfp / ef_remainder.c
blob92958efc4d6c8ca8f35f534ad1bb1bbbb1b4483f
1 /* ef_remainder.c -- float version of e_remainder.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
5 /*
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
12 * is preserved.
13 * ====================================================
16 #include "fdlibm.h"
18 #ifdef __STDC__
19 static const float zero = 0.0;
20 #else
21 static float zero = 0.0;
22 #endif
25 #ifdef __STDC__
26 float remainderf(float x, float p)
27 #else
28 float remainderf(x,p)
29 float x,p;
30 #endif
32 __int32_t hx,hp;
33 __uint32_t sx;
34 float p_half;
36 GET_FLOAT_WORD(hx,x);
37 GET_FLOAT_WORD(hp,p);
38 sx = hx&0x80000000;
39 hp &= 0x7fffffff;
40 hx &= 0x7fffffff;
42 /* purge off exception values */
43 if(hp==0) return (x*p)/(x*p); /* p = 0 */
44 if((hx>=0x7f800000)|| /* x not finite */
45 ((hp>0x7f800000))) /* p is NaN */
46 return (x*p)/(x*p);
49 if (hp<=0x7effffff) x = fmodf(x,p+p); /* now x < 2p */
50 if ((hx-hp)==0) return zero*x;
51 x = fabsf(x);
52 p = fabsf(p);
53 if (hp<0x01000000) {
54 if(x+x>p) {
55 x-=p;
56 if(x+x>=p) x -= p;
58 } else {
59 p_half = (float)0.5*p;
60 if(x>p_half) {
61 x-=p;
62 if(x>=p_half) x -= p;
65 GET_FLOAT_WORD(hx,x);
66 SET_FLOAT_WORD(x,hx^sx);
67 return x;