145
|
1 /* e_fmodl.c -- long double version of e_fmod.c.
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 /*
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 * ====================================================
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 *
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 * Developed at SunPro, a Sun Microsystems, Inc. business.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 * Permission to use, copy, modify, and distribute this
|
145
|
10 * software is freely granted, provided that this notice
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 * is preserved.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 * ====================================================
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 /* remainderq(x,p)
|
145
|
16 * Return :
|
|
17 * returns x REM p = x - [x/p]*p as if in infinite
|
|
18 * precise arithmetic, where [x/p] is the (infinite bit)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 * integer nearest x/p (in half way case choose the even one).
|
145
|
20 * Method :
|
|
21 * Based on fmodl() return x-[x/p]chopped*p exactlp.
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 #include "quadmath-imp.h"
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25
|
145
|
26 static const __float128 zero = 0;
|
|
27
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 __float128
|
145
|
30 remainderq(__float128 x, __float128 p)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 {
|
145
|
32 int64_t hx,hp;
|
|
33 uint64_t sx,lx,lp;
|
|
34 __float128 p_half;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35
|
145
|
36 GET_FLT128_WORDS64(hx,lx,x);
|
|
37 GET_FLT128_WORDS64(hp,lp,p);
|
|
38 sx = hx&0x8000000000000000ULL;
|
|
39 hp &= 0x7fffffffffffffffLL;
|
|
40 hx &= 0x7fffffffffffffffLL;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41
|
145
|
42 /* purge off exception values */
|
|
43 if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */
|
|
44 if((hx>=0x7fff000000000000LL)|| /* x not finite */
|
|
45 ((hp>=0x7fff000000000000LL)&& /* p is NaN */
|
|
46 (((hp-0x7fff000000000000LL)|lp)!=0)))
|
|
47 return (x*p)/(x*p);
|
|
48
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49
|
145
|
50 if (hp<=0x7ffdffffffffffffLL) x = fmodq(x,p+p); /* now x < 2p */
|
|
51 if (((hx-hp)|(lx-lp))==0) return zero*x;
|
|
52 x = fabsq(x);
|
|
53 p = fabsq(p);
|
|
54 if (hp<0x0002000000000000LL) {
|
|
55 if(x+x>p) {
|
|
56 x-=p;
|
|
57 if(x+x>=p) x -= p;
|
|
58 }
|
|
59 } else {
|
|
60 p_half = 0.5Q*p;
|
|
61 if(x>p_half) {
|
|
62 x-=p;
|
|
63 if(x>=p_half) x -= p;
|
|
64 }
|
|
65 }
|
|
66 GET_FLT128_MSW64(hx,x);
|
|
67 SET_FLT128_MSW64(x,hx^sx);
|
|
68 return x;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 }
|