1 /* @(#)e_remainder.c 5.1 93/09/24 */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
12 * $FreeBSD: src/lib/msun/src/e_remainder.c,v 1.6 1999/08/28 00:06:38 peter Exp $
13 * $DragonFly: src/lib/msun/src/Attic/e_remainder.c,v 1.3 2004/12/29 15:22:57 asmodai Exp $
16 /* __ieee754_remainder(x,p)
18 * returns x REM p = x - [x/p]*p as if in infinite
19 * precise arithmetic, where [x/p] is the (infinite bit)
20 * integer nearest x/p (in half way case choose the even one).
22 * Based on fmod() return x-[x/p]chopped*p exactlp.
26 #include "math_private.h"
28 static const double zero = 0.0;
32 __generic___ieee754_remainder(double x, double p)
38 EXTRACT_WORDS(hx,lx,x);
39 EXTRACT_WORDS(hp,lp,p);
44 /* purge off exception values */
45 if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */
46 if((hx>=0x7ff00000)|| /* x not finite */
47 ((hp>=0x7ff00000)&& /* p is NaN */
48 (((hp-0x7ff00000)|lp)!=0)))
52 if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */
53 if (((hx-hp)|(lx-lp))==0) return zero*x;
69 SET_HIGH_WORD(x,hx^sx);