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 * ====================================================
15 static char rcsid
[] = "$FreeBSD: src/lib/msun/src/e_remainder.c,v 1.12 2008/03/30 20:47:42 das Exp $";
18 /* __ieee754_remainder(x,p)
20 * returns x REM p = x - [x/p]*p as if in infinite
21 * precise arithmetic, where [x/p] is the (infinite bit)
22 * integer nearest x/p (in half way case choose the even one).
24 * Based on fmod() return x-[x/p]chopped*p exactlp.
29 #include "math_private.h"
31 static const double zero
= 0.0;
35 __ieee754_remainder(double x
, double p
)
41 EXTRACT_WORDS(hx
,lx
,x
);
42 EXTRACT_WORDS(hp
,lp
,p
);
47 /* purge off exception values */
48 if((hp
|lp
)==0) return (x
*p
)/(x
*p
); /* p = 0 */
49 if((hx
>=0x7ff00000)|| /* x not finite */
50 ((hp
>=0x7ff00000)&& /* p is NaN */
51 (((hp
-0x7ff00000)|lp
)!=0)))
52 return ((long double)x
*p
)/((long double)x
*p
);
55 if (hp
<=0x7fdfffff) x
= __ieee754_fmod(x
,p
+p
); /* now x < 2p */
56 if (((hx
-hp
)|(lx
-lp
))==0) return zero
*x
;
72 if ((hx
&0x7fffffff)==0) hx
= 0;
73 SET_HIGH_WORD(x
,hx
^sx
);
77 #if LDBL_MANT_DIG == 53
78 AROS_MAKE_ASM_SYM(typeof(remainderl
), remainderl
, AROS_CSYM_FROM_ASM_NAME(remainderl
), AROS_CSYM_FROM_ASM_NAME(remainder
));
79 AROS_EXPORT_ASM_SYM(AROS_CSYM_FROM_ASM_NAME(remainderl
));