2 /* @(#)e_remainder.c 1.3 95/01/18 */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunSoft, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
14 /* __ieee754_remainder(x,p)
16 * returns x REM p = x - [x/p]*p as if in infinite
17 * precise arithmetic, where [x/p] is the (infinite bit)
18 * integer nearest x/p (in half way case choose the even one).
20 * Based on fmod() return x-[x/p]chopped*p exactlp.
25 #ifndef _DOUBLE_IS_32BITS
28 static const double zero = 0.0;
30 static double zero = 0.0;
35 double __ieee754_remainder(double x, double p)
37 double __ieee754_remainder(x,p)
45 EXTRACT_WORDS(hx,lx,x);
46 EXTRACT_WORDS(hp,lp,p);
51 /* purge off exception values */
52 if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */
53 if((hx>=0x7ff00000)|| /* x not finite */
54 ((hp>=0x7ff00000)&& /* p is NaN */
55 (((hp-0x7ff00000)|lp)!=0)))
59 if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */
60 if (((hx-hp)|(lx-lp))==0) return zero*x;
76 SET_HIGH_WORD(x,hx ^ sx);
79 #endif /* defined(_DOUBLE_IS_32BITS) */