Readd ypresp_allfn, now correctly typed.
[dragonfly.git] / lib / msun / src / e_remainderf.c
1 /* e_remainderf.c -- float version of e_remainder.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  *
4  * $FreeBSD: src/lib/msun/src/e_remainderf.c,v 1.5 1999/08/28 00:06:38 peter Exp $
5  * $DragonFly: src/lib/msun/src/Attic/e_remainderf.c,v 1.4 2004/12/29 17:48:27 asmodai Exp $
6  */
7
8 /*
9  * ====================================================
10  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11  *
12  * Developed at SunPro, a Sun Microsystems, Inc. business.
13  * Permission to use, copy, modify, and distribute this
14  * software is freely granted, provided that this notice
15  * is preserved.
16  * ====================================================
17  */
18
19 #include "math.h"
20 #include "math_private.h"
21
22 static const float zero = 0.0;
23
24
25 float
26 __generic___ieee754_remainderf(float x, float p)
27 {
28         int32_t hx,hp;
29         u_int32_t sx;
30         float p_half;
31
32         GET_FLOAT_WORD(hx,x);
33         GET_FLOAT_WORD(hp,p);
34         sx = hx&0x80000000;
35         hp &= 0x7fffffff;
36         hx &= 0x7fffffff;
37
38     /* purge off exception values */
39         if(hp==0) return (x*p)/(x*p);           /* p = 0 */
40         if((hx>=0x7f800000)||                   /* x not finite */
41           ((hp>0x7f800000)))                    /* p is NaN */
42             return (x*p)/(x*p);
43
44
45         if (hp<=0x7effffff) x = __ieee754_fmodf(x,p+p); /* now x < 2p */
46         if ((hx-hp)==0) return zero*x;
47         x  = fabsf(x);
48         p  = fabsf(p);
49         if (hp<0x01000000) {
50             if(x+x>p) {
51                 x-=p;
52                 if(x+x>=p) x -= p;
53             }
54         } else {
55             p_half = (float)0.5*p;
56             if(x>p_half) {
57                 x-=p;
58                 if(x>=p_half) x -= p;
59             }
60         }
61         GET_FLOAT_WORD(hx,x);
62         SET_FLOAT_WORD(x,hx^sx);
63         return x;
64 }