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 * ====================================================
13 #if defined(LIBM_SCCS) && !defined(lint)
14 static char rcsid[] = "$NetBSD: e_remainder.c,v 1.8 1995/05/10 20:46:05 jtc Exp $";
17 /* __ieee754_remainder(x,p)
19 * returns x REM p = x - [x/p]*p as if in infinite
20 * precise arithmetic, where [x/p] is the (infinite bit)
21 * integer nearest x/p (in half way case choose the even one).
23 * Based on fmod() return x-[x/p]chopped*p exactlp.
27 #include "math_private.h"
30 static const double zero = 0.0;
32 static double zero = 0.0;
37 double __ieee754_remainder(double x, double p)
39 double __ieee754_remainder(x,p)
47 EXTRACT_WORDS(hx,lx,x);
48 EXTRACT_WORDS(hp,lp,p);
53 /* purge off exception values */
54 if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */
55 if((hx>=0x7ff00000)|| /* x not finite */
56 ((hp>=0x7ff00000)&& /* p is NaN */
57 (((hp-0x7ff00000)|lp)!=0)))
61 if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */
62 if (((hx-hp)|(lx-lp))==0) return zero*x;
78 SET_HIGH_WORD(x,hx^sx);