2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
9 * ====================================================
12 /* __ieee754_remainder(x,p)
14 * returns x REM p = x - [x/p]*p as if in infinite
15 * precise arithmetic, where [x/p] is the (infinite bit)
16 * integer nearest x/p (in half way case choose the even one).
18 * Based on fmod() return x-[x/p]chopped*p exactlp.
22 #include "math_private.h"
24 static const double zero = 0.0;
26 double attribute_hidden __ieee754_remainder(double x, double p)
32 EXTRACT_WORDS(hx,lx,x);
33 EXTRACT_WORDS(hp,lp,p);
38 /* purge off exception values */
39 if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */
40 if((hx>=0x7ff00000)|| /* x not finite */
41 ((hp>=0x7ff00000)&& /* p is NaN */
42 (((hp-0x7ff00000)|lp)!=0)))
46 if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */
47 if (((hx-hp)|(lx-lp))==0) return zero*x;
63 SET_HIGH_WORD(x,hx^sx);
68 * wrapper remainder(x,p)
71 double remainder(double x, double y)
73 double z = __ieee754_remainder(x, y);
74 if (_LIB_VERSION == _IEEE_ || isnan(y))
77 return __kernel_standard(x, y, 28); /* remainder(x,0) */
81 strong_alias(__ieee754_remainder, remainder)
83 libm_hidden_def(remainder)