Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[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.2 2003/06/17 04:26:53 dillon 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 #ifdef __STDC__
23 static const float zero = 0.0;
24 #else
25 static float zero = 0.0;
26 #endif
27
28
29 #ifdef __STDC__
30         float __ieee754_remainderf(float x, float p)
31 #else
32         float __ieee754_remainderf(x,p)
33         float x,p;
34 #endif
35 {
36         int32_t hx,hp;
37         u_int32_t sx;
38         float p_half;
39
40         GET_FLOAT_WORD(hx,x);
41         GET_FLOAT_WORD(hp,p);
42         sx = hx&0x80000000;
43         hp &= 0x7fffffff;
44         hx &= 0x7fffffff;
45
46     /* purge off exception values */
47         if(hp==0) return (x*p)/(x*p);           /* p = 0 */
48         if((hx>=0x7f800000)||                   /* x not finite */
49           ((hp>0x7f800000)))                    /* p is NaN */
50             return (x*p)/(x*p);
51
52
53         if (hp<=0x7effffff) x = __ieee754_fmodf(x,p+p); /* now x < 2p */
54         if ((hx-hp)==0) return zero*x;
55         x  = fabsf(x);
56         p  = fabsf(p);
57         if (hp<0x01000000) {
58             if(x+x>p) {
59                 x-=p;
60                 if(x+x>=p) x -= p;
61             }
62         } else {
63             p_half = (float)0.5*p;
64             if(x>p_half) {
65                 x-=p;
66                 if(x>=p_half) x -= p;
67             }
68         }
69         GET_FLOAT_WORD(hx,x);
70         SET_FLOAT_WORD(x,hx^sx);
71         return x;
72 }