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 | |
5 | /* |
6 | * ==================================================== |
7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
8 | * |
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 | * ==================================================== |
14 | */ |
15 | |
16 | #include <math.h> |
17 | #include <math_private.h> |
18 | #include <libm-alias-finite.h> |
19 | |
20 | static const float zero = 0.0; |
21 | |
22 | |
23 | float |
24 | __ieee754_remainderf(float x, float p) |
25 | { |
26 | int32_t hx,hp; |
27 | uint32_t sx; |
28 | float p_half; |
29 | |
30 | GET_FLOAT_WORD(hx,x); |
31 | GET_FLOAT_WORD(hp,p); |
32 | sx = hx&0x80000000; |
33 | hp &= 0x7fffffff; |
34 | hx &= 0x7fffffff; |
35 | |
36 | /* purge off exception values */ |
37 | if(hp==0) return (x*p)/(x*p); /* p = 0 */ |
38 | if((hx>=0x7f800000)|| /* x not finite */ |
39 | ((hp>0x7f800000))) /* p is NaN */ |
40 | return (x*p)/(x*p); |
41 | |
42 | |
43 | if (hp<=0x7effffff) x = __ieee754_fmodf(x,p+p); /* now x < 2p */ |
44 | if ((hx-hp)==0) return zero*x; |
45 | x = fabsf(x); |
46 | p = fabsf(p); |
47 | if (hp<0x01000000) { |
48 | if(x+x>p) { |
49 | x-=p; |
50 | if(x+x>=p) x -= p; |
51 | } |
52 | } else { |
53 | p_half = (float)0.5*p; |
54 | if(x>p_half) { |
55 | x-=p; |
56 | if(x>=p_half) x -= p; |
57 | } |
58 | } |
59 | GET_FLOAT_WORD(hx,x); |
60 | SET_FLOAT_WORD(x,hx^sx); |
61 | return x; |
62 | } |
63 | libm_alias_finite (__ieee754_remainderf, __remainderf) |
64 | |