QFP.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: package xeij;
21:
22: import java.lang.*;
23:
24: public class QFP {
25:
26:
27:
28: public static final int QFP_P = 0x00000000;
29: public static final int QFP_M = 0x08000000;
30: public static final int QFP_Z = 0x04000000;
31: public static final int QFP_I = 0x02000000;
32: public static final int QFP_N = 0x01000000;
33: public static final int QFP_ZIN = QFP_Z | QFP_I | QFP_N;
34: public static final int QFP_MZIN = QFP_M | QFP_Z | QFP_I | QFP_N;
35:
36: public static final int QFP_BS = 0x00008000;
37: public static final int QFP_SN = 0x00004000;
38: public static final int QFP_OE = 0x00002000;
39: public static final int QFP_OF = 0x00001000;
40: public static final int QFP_UF = 0x00000800;
41: public static final int QFP_DZ = 0x00000400;
42: public static final int QFP_X2 = 0x00000200;
43: public static final int QFP_X1 = 0x00000100;
44: public static final int QFP_EXC = 0x0000ff00;
45:
46:
47:
48: private static final int QFP_GETA_SIZE = 512;
49: private static final int QFP_GETA_BASE = -QFP_GETA_SIZE >> 1;
50:
51:
52: public static final QFP QFP_ONE = new QFP (QFP_P, 0, 0x1.0p0, 0.0);
53:
54: public static final QFP QFP_TEN = new QFP (QFP_P, 0, 0x1.4p3, 0.0);
55:
56: public static final QFP QFP_TENTO4 = new QFP (QFP_P, 0, 0x1.388p13, 0.0);
57:
58: public static final QFP QFP_PI = new QFP (QFP_P, 0, 0x1.921fb54442d18p1, 0x1.1a62633145c07p-53);
59:
60: public static final QFP QFP_LN_2_2 = new QFP (QFP_P, 0, 0x1.62e42fefa39efp-2, 0x1.abc9e3b39803fp-57);
61:
62:
63: public static int fpsr;
64:
65:
66: public int flg;
67: public int epp;
68: public double dvl;
69: public double cvl;
70:
71:
72: public QFP () {
73: this.set0 ();
74: }
75: public QFP (double d) {
76: this.setd (d);
77: }
78: public QFP (float f) {
79: this.setf (f);
80: }
81: public QFP (int i) {
82: this.seti (i);
83: }
84: public QFP (long l) {
85: this.setl (l);
86: }
87: public QFP (QFP x) {
88: this.flg = x.flg;
89: this.epp = x.epp;
90: this.dvl = x.dvl;
91: this.cvl = x.cvl;
92: }
93:
94:
95: private QFP (int f, int e, double d, double c) {
96: this.flg = f;
97: this.epp = e;
98: this.dvl = d;
99: this.cvl = c;
100: }
101:
102:
103:
104:
105: public QFP abs () {
106: if ((this.flg & QFP_M) != 0) {
107: this.flg ^= QFP_M;
108: this.dvl = -this.dvl;
109: this.cvl = -this.cvl;
110: }
111: return this;
112: }
113: public QFP abs (QFP x) {
114: if ((x.flg & QFP_M) != 0) {
115: this.flg = x.flg ^ QFP_M;
116: this.epp = x.epp;
117: this.dvl = -x.dvl;
118: this.cvl = -x.cvl;
119: } else {
120: this.flg = x.flg;
121: this.epp = x.epp;
122: this.dvl = x.dvl;
123: this.cvl = x.cvl;
124: }
125: return this;
126: }
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157: private static final int[] QFP_ADD_FLG = {
158:
159: 0x00000000,0x01000000,0x02000000,0x01000000,0x80000000,0x01000000,0x01000000,0x01000000,
160: 0x00000000,0x01000000,0x0a000000,0x01000000,0x80000000,0x01000000,0x01000000,0x01000000,
161: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
162: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
163: 0x02000000,0x01000000,0x02000000,0x01000000,0x02000000,0x01000000,0x01000000,0x01000000,
164: 0x02000000,0x01000000,0x01002000,0x01000000,0x02000000,0x01000000,0x01000000,0x01000000,
165: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
166: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
167: 0xc0000000,0x01000000,0x02000000,0x01000000,0x04000000,0x01000000,0x01000000,0x01000000,
168: 0xc0000000,0x01000000,0x0a000000,0x01000000,0x04000000,0x01000000,0x01000000,0x01000000,
169: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
170: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
171: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
172: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
173: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
174: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
175: 0x00000000,0x01000000,0x02000000,0x01000000,0x80000000,0x01000000,0x01000000,0x01000000,
176: 0x00000000,0x01000000,0x0a000000,0x01000000,0x80000000,0x01000000,0x01000000,0x01000000,
177: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
178: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
179: 0x0a000000,0x01000000,0x01002000,0x01000000,0x0a000000,0x01000000,0x01000000,0x01000000,
180: 0x0a000000,0x01000000,0x0a000000,0x01000000,0x0a000000,0x01000000,0x01000000,0x01000000,
181: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
182: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
183: 0xc0000000,0x01000000,0x02000000,0x01000000,0x04000000,0x01000000,0x01000000,0x01000000,
184: 0xc0000000,0x01000000,0x0a000000,0x01000000,0x0c000000,0x01000000,0x01000000,0x01000000,
185: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
186: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
187: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
188: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
189: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
190: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
191: };
192: public QFP add (QFP y) {
193: int xf = this.flg;
194: int xe = this.epp;
195: double xd = this.dvl;
196: double xc = this.cvl;
197: int yf = y.flg;
198: int ye = y.epp;
199: double yd = y.dvl;
200: double yc = y.cvl;
201:
202: int zf = QFP_ADD_FLG[xf >>> 24 - 4 | yf >>> 24];
203: if ((zf & (0xc0000000 | QFP_ZIN)) != 0) {
204: if (0 <= zf) {
205: QFP.fpsr |= zf & QFP_EXC;
206: this.flg = zf & QFP_MZIN;
207: } else if (zf << 1 < 0) {
208: this.flg = yf;
209: this.epp = ye;
210: this.dvl = yd;
211: this.cvl = yc;
212:
213:
214:
215:
216:
217: }
218: return this;
219: }
220:
221:
222: if (xe != ye) {
223: if (xe + 128 == ye) {
224: yd = Math.scalb (yd, 128);
225: yc = Math.scalb (yc, 128);
226: } else if (xe - 128 == ye) {
227: yd = Math.scalb (yd, -128);
228: yc = Math.scalb (yc, -128);
229: } else {
230: if (xe < ye) {
231: this.flg = yf;
232: this.epp = ye;
233: this.dvl = yd;
234: this.cvl = yc;
235:
236:
237:
238:
239:
240: }
241: return this;
242: }
243: }
244:
245: {
246: double t1 = xd + yd;
247: double t2 = xd - t1;
248: t2 = (((xd - (t1 + t2)) + (t2 + yd)) + xc) + yc;
249: xd = t1 + t2;
250: xc = (t1 - xd) + t2;
251: }
252:
253:
254:
255: if (xd == 0.0) {
256: this.flg = QFP_P | QFP_Z;
257: return this;
258: }
259: this.flg = (int) (Double.doubleToLongBits (xd) >>> 36) & QFP_M;
260:
261: int e = Math.getExponent (xd) - QFP_GETA_BASE & -QFP_GETA_SIZE;
262: if (e != 0) {
263: xe += e;
264: xd = Math.scalb (xd, -e);
265: xc = Math.scalb (xc, -e);
266: }
267:
268: this.epp = xe;
269: this.dvl = xd;
270: this.cvl = xc;
271: return this;
272: }
273: public QFP add (QFP x, QFP y) {
274: int xf = x.flg;
275: int xe = x.epp;
276: double xd = x.dvl;
277: double xc = x.cvl;
278: int yf = y.flg;
279: int ye = y.epp;
280: double yd = y.dvl;
281: double yc = y.cvl;
282:
283: int zf = QFP_ADD_FLG[xf >>> 24 - 4 | yf >>> 24];
284: if ((zf & (0xc0000000 | QFP_ZIN)) != 0) {
285: if (0 <= zf) {
286: QFP.fpsr |= zf & QFP_EXC;
287: this.flg = zf & QFP_MZIN;
288: } else if (zf << 1 < 0) {
289: this.flg = yf;
290: this.epp = ye;
291: this.dvl = yd;
292: this.cvl = yc;
293: } else {
294: this.flg = xf;
295: this.epp = xe;
296: this.dvl = xd;
297: this.cvl = xc;
298: }
299: return this;
300: }
301:
302:
303: if (xe != ye) {
304: if (xe + 128 == ye) {
305: yd = Math.scalb (yd, 128);
306: yc = Math.scalb (yc, 128);
307: } else if (xe - 128 == ye) {
308: yd = Math.scalb (yd, -128);
309: yc = Math.scalb (yc, -128);
310: } else {
311: if (xe < ye) {
312: this.flg = yf;
313: this.epp = ye;
314: this.dvl = yd;
315: this.cvl = yc;
316: } else {
317: this.flg = xf;
318: this.epp = xe;
319: this.dvl = xd;
320: this.cvl = xc;
321: }
322: return this;
323: }
324: }
325:
326: {
327: double t1 = xd + yd;
328: double t2 = xd - t1;
329: t2 = (((xd - (t1 + t2)) + (t2 + yd)) + xc) + yc;
330: xd = t1 + t2;
331: xc = (t1 - xd) + t2;
332: }
333:
334:
335:
336: if (xd == 0.0) {
337: this.flg = QFP_P | QFP_Z;
338: return this;
339: }
340: this.flg = (int) (Double.doubleToLongBits (xd) >>> 36) & QFP_M;
341:
342: int e = Math.getExponent (xd) - QFP_GETA_BASE & -QFP_GETA_SIZE;
343: if (e != 0) {
344: xe += e;
345: xd = Math.scalb (xd, -e);
346: xc = Math.scalb (xc, -e);
347: }
348:
349: this.epp = xe;
350: this.dvl = xd;
351: this.cvl = xc;
352: return this;
353: }
354:
355:
356: private static final QFP[] QFP_ATH_T = {
357:
358:
359: new QFP (QFP_P, 0, 0x1.5f619980c4337p-3, -0x1.165f626cdd52bp-60),
360: new QFP (QFP_P, 0, 0x1.e90df15b89be3p-2, 0x1.1f99b9abc530dp-56),
361: new QFP (QFP_P, 0, 0x1.662c704e79f12p-1, 0x1.282af86097e1cp-55),
362: new QFP (QFP_P, 0, 0x1.acd734cfa2558p-1, -0x1.d43396def4576p-55),
363: new QFP (QFP_P, 0, 0x1.d4a917bee0f8ep-1, 0x1.a848f4c92e287p-56),
364: new QFP (QFP_P, 0, 0x1.e9dc9d2d2669p-1, 0x1.1f0d824ddcde5p-58),
365: new QFP (QFP_P, 0, 0x1.f4cf57477a9dfp-1, -0x1.58d05e5b8e13cp-57),
366: new QFP (QFP_P, 0, 0x1.fa5fcd25fa7dp-1, 0x1.d5e0dfd5720f4p-57),
367: new QFP (QFP_P, 0, 0x1.fd2deaca257dap-1, -0x1.b4d133e623a68p-55),
368: new QFP (QFP_P, 0, 0x1.fe9675ec66c9dp-1, 0x1.0314f0b167a78p-61),
369: new QFP (QFP_P, 0, 0x1.ff4b1b0724de6p-1, -0x1.4f6460da8573bp-55),
370: new QFP (QFP_P, 0, 0x1.ffa58585b10e2p-1, -0x1.e812fa2f88614p-56),
371: new QFP (QFP_P, 0, 0x1.ffd2c0c31c61fp-1, -0x1.82bc0859369f6p-55),
372: new QFP (QFP_P, 0, 0x1.ffe95fe196accp-1, 0x1.991433745dacbp-59),
373: new QFP (QFP_P, 0, 0x1.fff4afd0cc65ep-1, 0x1.4035d2da50783p-58),
374: new QFP (QFP_P, 0, 0x1.fffa57e06654ep-1, 0x1.9b510deb5e06ep-58),
375: new QFP (QFP_P, 0, 0x1.fffd2bee332ebp-1, -0x1.82787a0eb7631p-57),
376: new QFP (QFP_P, 0, 0x1.fffe95f69997ep-1, -0x1.fbebab6e35a44p-58),
377: new QFP (QFP_P, 0, 0x1.ffff4afb2cccp-1, 0x1.e5d3881a1907dp-59),
378: new QFP (QFP_P, 0, 0x1.ffffa57d8e66p-1, 0x1.2de46d4fa2f96p-56),
379: new QFP (QFP_P, 0, 0x1.ffffd2bec533p-1, 0x1.71c6418321567p-57),
380: new QFP (QFP_P, 0, 0x1.ffffe95f62198p-1, 0x1.82beb77000cdfp-58),
381: new QFP (QFP_P, 0, 0x1.fffff4afb0eccp-1, 0x1.86fcd50738a9dp-59),
382: new QFP (QFP_P, 0, 0x1.fffffa57d86e6p-1, 0x1.880c5c7086a0ap-60),
383: new QFP (QFP_P, 0, 0x1.fffffd2bec353p-1, 0x1.88503e4b4a1e5p-61),
384: new QFP (QFP_P, 0, 0x1.fffffe95f61a2p-1, -0x1.fcef3d927beep-55),
385: new QFP (QFP_P, 0, 0x1.ffffff4afb0cfp-1, -0x1.fcef3516408b1p-56),
386: new QFP (QFP_P, 0, 0x1.ffffffa57d867p-1, -0x1.fcef32f731b1fp-57),
387: new QFP (QFP_P, 0, 0x1.ffffffd2bec33p-1, 0x1.406219b212409p-55),
388: new QFP (QFP_P, 0, 0x1.ffffffe95f61ap-1, -0x1.7fcef324d7d0ep-55),
389: new QFP (QFP_P, 0, 0x1.fffffff4afb0dp-1, -0x1.8fcef324500d3p-56),
390: new QFP (QFP_P, 0, 0x1.fffffffa57d86p-1, 0x1.9a0c4336f478fp-55),
391: new QFP (QFP_P, 0, 0x1.fffffffd2bec3p-1, 0x1.990c4336f698p-56),
392: new QFP (QFP_P, 0, 0x1.fffffffe95f62p-1, -0x1.99dcef3242381p-55),
393: new QFP (QFP_P, 0, 0x1.ffffffff4afb1p-1, -0x1.99ecef32422f9p-56),
394: new QFP (QFP_P, 0, 0x1.ffffffffa57d8p-1, 0x1.9982c4336f74ap-55),
395: new QFP (QFP_P, 0, 0x1.ffffffffd2becp-1, 0x1.9981c4336f74cp-56),
396: new QFP (QFP_P, 0, 0x1.ffffffffe95f6p-1, 0x1.998144336f74dp-57),
397: new QFP (QFP_P, 0, 0x1.fffffffff4afbp-1, 0x1.998104336f74dp-58),
398: new QFP (QFP_P, 0, 0x1.fffffffffa57ep-1, -0x1.e667f1bcc908bp-55),
399: new QFP (QFP_P, 0, 0x1.fffffffffd2bfp-1, -0x1.e667f2bcc908bp-56),
400: new QFP (QFP_P, 0, 0x1.fffffffffe95fp-1, 0x1.86660330cdbddp-55),
401: new QFP (QFP_P, 0, 0x1.ffffffffff4bp-1, -0x1.3cccfe6f99211p-55),
402: new QFP (QFP_P, 0, 0x1.ffffffffffa58p-1, -0x1.3cccfe7399211p-56),
403: new QFP (QFP_P, 0, 0x1.ffffffffffd2cp-1, -0x1.3cccfe7599211p-57),
404: new QFP (QFP_P, 0, 0x1.ffffffffffe96p-1, -0x1.3cccfe7699211p-58),
405: new QFP (QFP_P, 0, 0x1.fffffffffff4bp-1, -0x1.3cccfe7719211p-59),
406: new QFP (QFP_P, 0, 0x1.fffffffffffa5p-1, 0x1.f619980c4536fp-55),
407: new QFP (QFP_P, 0, 0x1.fffffffffffd3p-1, -0x1.04f333f9dde48p-55),
408: new QFP (QFP_P, 0, 0x1.fffffffffffe9p-1, 0x1.7d86660310edcp-55),
409: new QFP (QFP_P, 0, 0x1.ffffffffffff5p-1, -0x1.413cccfe77912p-55),
410: new QFP (QFP_P, 0, 0x1.ffffffffffffap-1, 0x1.5f619980c4357p-55),
411: new QFP (QFP_P, 0, 0x1.ffffffffffffdp-1, 0x1.5f619980c4347p-56),
412: new QFP (QFP_P, 0, 0x1.fffffffffffffp-1, -0x1.a827999fcef3p-55),
413: new QFP (QFP_P, 0, 0x1.fffffffffffffp-1, 0x1.2bec333018867p-55),
414: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bccp-55),
415: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-56),
416: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-57),
417: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-58),
418: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-59),
419: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-60),
420: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-61),
421: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-62),
422: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-63),
423: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-64),
424: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-65),
425: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-66),
426: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-67),
427: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-68),
428: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-69),
429: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-70),
430: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-71),
431: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-72),
432: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-73),
433: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-74),
434: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-75),
435: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-76),
436: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-77),
437: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-78),
438: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-79),
439: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-80),
440: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-81),
441: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-82),
442: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-83),
443: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-84),
444: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-85),
445: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-86),
446: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-87),
447: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-88),
448: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-89),
449: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-90),
450: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-91),
451: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-92),
452: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-93),
453: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-94),
454: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-95),
455: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-96),
456: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-97),
457: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-98),
458: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-99),
459: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-100),
460: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-101),
461: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-102),
462: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-103),
463: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-104),
464: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-105),
465: new QFP (QFP_P, 0, 0x1.0p0, -0x1.6a09e667f3bcdp-106),
466: };
467:
468: private static final QFP QFP_ATH_C1 = new QFP (QFP_P, 0, 0x1.0p0, -0x1.f36f641e20d72p-114);
469: private static final QFP QFP_ATH_C3 = new QFP (QFP_P, 0, 0x1.5555555555555p-2, 0x1.5555555555611p-56);
470: private static final QFP QFP_ATH_C5 = new QFP (QFP_P, 0, 0x1.999999999999ap-3, -0x1.9999999a4175dp-57);
471: private static final QFP QFP_ATH_C7 = new QFP (QFP_P, 0, 0x1.2492492492492p-3, 0x1.24924b582faeep-57);
472: private static final QFP QFP_ATH_C9 = new QFP (QFP_P, 0, 0x1.c71c71c71c71cp-4, 0x1.c7140426f0f4ap-58);
473: private static final QFP QFP_ATH_C11 = new QFP (QFP_P, 0, 0x1.745d1745d1746p-4, -0x1.5fe638aeacf12p-59);
474: private static final QFP QFP_ATH_C13 = new QFP (QFP_P, 0, 0x1.3b13b13b13b12p-4, -0x1.a3d69d8be81fp-58);
475: private static final QFP QFP_ATH_C15 = new QFP (QFP_P, 0, 0x1.1111111111249p-4, 0x1.d1d90451b5d3fp-59);
476: private static final QFP QFP_ATH_C17 = new QFP (QFP_P, 0, 0x1.e1e1e1e1d17b1p-5, -0x1.464b242b5513p-59);
477: private static final QFP QFP_ATH_C19 = new QFP (QFP_P, 0, 0x1.af286bcf2dc59p-5, -0x1.87a381950827p-61);
478: private static final QFP QFP_ATH_C21 = new QFP (QFP_P, 0, 0x1.8618605cae00ep-5, -0x1.338aeff0d76ebp-59);
479: private static final QFP QFP_ATH_C23 = new QFP (QFP_P, 0, 0x1.642cb7cf14af4p-5, 0x1.e3d44dca87f29p-59);
480: private static final QFP QFP_ATH_C25 = new QFP (QFP_P, 0, 0x1.47a7e890f5ccdp-5, 0x1.31e1771122396p-59);
481: private static final QFP QFP_ATH_C27 = new QFP (QFP_P, 0, 0x1.2ff12aaefe92p-5, -0x1.6898bb0e3245dp-60);
482: private static final QFP QFP_ATH_C29 = new QFP (QFP_P, 0, 0x1.129828d81e45cp-5, -0x1.e5836f6efc4bcp-62);
483: private static final QFP QFP_ATH_C31 = new QFP (QFP_P, 0, 0x1.4cd3eb19356dep-5, -0x1.9b438b675ceacp-60);
484:
485:
486: public QFP atanh () {
487: return this.atanh (this);
488: }
489: public QFP atanh (QFP x) {
490: int xf = x.flg;
491: if ((xf & QFP_ZIN) != 0) {
492: if ((xf & QFP_I) != 0) {
493: QFP.fpsr |= QFP_OE;
494: this.flg = QFP_N;
495: } else {
496: this.flg = xf;
497: }
498: return this;
499: }
500:
501: x = new QFP ().abs (x);
502: {
503: int t = x.cmp1 ();
504: if (0 <= t) {
505: if (t == 0) {
506: QFP.fpsr |= QFP_DZ;
507: this.flg = xf | QFP_I;
508: } else {
509: QFP.fpsr |= QFP_OE;
510: this.flg = QFP_N;
511: }
512: return this;
513: }
514: }
515:
516: int n = 0;
517: if (QFP_ATH_T[0].lt (x)) {
518: QFP t1 = new QFP ().negdec (x);
519: n = -Math.getExponent (t1.dvl);
520: if (QFP_ATH_T[n].lt (x)) {
521: n++;
522: }
523: t1.shl (n);
524: x.inc ();
525: QFP t2 = new QFP ().add (x, t1);
526: x.sub (t1)
527: .div (t2);
528: }
529: QFP x2 = new QFP ().squ (x);
530: this.mul (QFP_ATH_C31, x2)
531: .add (QFP_ATH_C29).mul (x2)
532: .add (QFP_ATH_C27).mul (x2)
533: .add (QFP_ATH_C25).mul (x2)
534: .add (QFP_ATH_C23).mul (x2)
535: .add (QFP_ATH_C21).mul (x2)
536: .add (QFP_ATH_C19).mul (x2)
537: .add (QFP_ATH_C17).mul (x2)
538: .add (QFP_ATH_C15).mul (x2)
539: .add (QFP_ATH_C13).mul (x2)
540: .add (QFP_ATH_C11).mul (x2)
541: .add (QFP_ATH_C9).mul (x2)
542: .add (QFP_ATH_C7).mul (x2)
543: .add (QFP_ATH_C5).mul (x2)
544: .add (QFP_ATH_C3).mul (x2)
545: .add (QFP_ATH_C1).mul (x);
546: if (n != 0) {
547: this.add (new QFP (n).mul (QFP_LN_2_2));
548: }
549: return this.neg ((xf & QFP_M) != 0);
550: }
551:
552:
553: public int cmp (QFP y) {
554: int xf = this.flg;
555: int yf = y.flg;
556: if (((xf | yf) & QFP_ZIN) != 0) {
557: return EFPBox.EFP_CMP_TABLE[xf >>> 24] << (yf >>> 24 - 1) >> 30;
558: }
559:
560: int s = (xf & QFP_M) != 0 ? -1 : 1;
561: return (xf != yf ? s :
562: this.epp != y.epp ? this.epp < y.epp ? -s : s :
563: this.dvl != y.dvl ? this.dvl < y.dvl ? -s : s :
564: this.cvl != y.cvl ? this.cvl < y.cvl ? -s : s :
565: 0);
566: }
567:
568:
569:
570:
571: public int cmp1 () {
572: return ((this.flg & QFP_MZIN) != 0 ?
573: (this.flg & QFP_N) != 0 ? 0 :
574: (this.flg & (QFP_M | QFP_Z)) != 0 ? -1 :
575: 1
576: :
577: this.epp != 0 ? this.epp < 0 ? -1 : 1 :
578: this.dvl != 1.0 ? this.dvl < 1.0 ? -1 : 1 :
579: this.cvl < 0.0 ? -1 : 0.0 < this.cvl ? 1 : 0);
580: }
581:
582:
583:
584:
585:
586: public QFP dec () {
587: return this.sub (QFP_ONE);
588: }
589: public QFP dec (QFP x) {
590: return this.sub (x, QFP_ONE);
591: }
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631: private static final int[] QFP_DIV_FLG = {
632:
633: 0x00000000,0x01000000,0x04000000,0x01000000,0x00000000,0x01000000,0x01000000,0x01000000,
634: 0x08000000,0x01000000,0x0c000000,0x01000000,0x08000000,0x01000000,0x01000000,0x01000000,
635: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
636: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
637: 0x02000000,0x01000000,0x01002000,0x01000000,0x02000400,0x01000000,0x01000000,0x01000000,
638: 0x0a000000,0x01000000,0x01002000,0x01000000,0x0a000400,0x01000000,0x01000000,0x01000000,
639: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
640: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
641: 0x04000000,0x01000000,0x04000000,0x01000000,0x01002000,0x01000000,0x01000000,0x01000000,
642: 0x0c000000,0x01000000,0x0c000000,0x01000000,0x01002000,0x01000000,0x01000000,0x01000000,
643: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
644: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
645: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
646: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
647: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
648: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
649: 0x08000000,0x01000000,0x0c000000,0x01000000,0x08000000,0x01000000,0x01000000,0x01000000,
650: 0x00000000,0x01000000,0x04000000,0x01000000,0x00000000,0x01000000,0x01000000,0x01000000,
651: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
652: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
653: 0x0a000000,0x01000000,0x01002000,0x01000000,0x0a000400,0x01000000,0x01000000,0x01000000,
654: 0x02000000,0x01000000,0x01002000,0x01000000,0x02000400,0x01000000,0x01000000,0x01000000,
655: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
656: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
657: 0x0c000000,0x01000000,0x0c000000,0x01000000,0x01002000,0x01000000,0x01000000,0x01000000,
658: 0x04000000,0x01000000,0x04000000,0x01000000,0x01002000,0x01000000,0x01000000,0x01000000,
659: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
660: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
661: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
662: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
663: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
664: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
665: };
666: public QFP div (QFP y) {
667: int zf = QFP_DIV_FLG[this.flg >>> 24 - 4 | y.flg >>> 24];
668: if ((zf & QFP_ZIN) != 0) {
669: QFP.fpsr |= zf & QFP_EXC;
670: this.flg = zf & QFP_MZIN;
671: return this;
672: }
673: return this.mul (new QFP ().rcp (y));
674: }
675: public QFP div (QFP x, QFP y) {
676: int zf = QFP_DIV_FLG[x.flg >>> 24 - 4 | y.flg >>> 24];
677: if ((zf & QFP_ZIN) != 0) {
678: QFP.fpsr |= zf & QFP_EXC;
679: this.flg = zf & QFP_MZIN;
680: return this;
681: }
682: return this.mul (x, new QFP ().rcp (y));
683: }
684:
685:
686:
687:
688: public QFP div2 () {
689: if ((this.flg & QFP_ZIN) != 0) {
690: return this;
691: }
692:
693:
694: this.dvl *= 0.5;
695: this.cvl *= 0.5;
696:
697: int e = Math.getExponent (this.dvl) - QFP_GETA_BASE & -QFP_GETA_SIZE;
698: if (e != 0) {
699: this.epp += e;
700: this.dvl = Math.scalb (this.dvl, -e);
701: this.cvl = Math.scalb (this.cvl, -e);
702: }
703: return this;
704: }
705: public QFP div2 (QFP x) {
706: this.flg = x.flg;
707: if ((this.flg & QFP_ZIN) != 0) {
708: return this;
709: }
710:
711:
712: this.epp = x.epp;
713: this.dvl = x.dvl * 0.5;
714: this.cvl = x.cvl * 0.5;
715:
716: int e = Math.getExponent (this.dvl) - QFP_GETA_BASE & -QFP_GETA_SIZE;
717: if (e != 0) {
718: this.epp += e;
719: this.dvl = Math.scalb (this.dvl, -e);
720: this.cvl = Math.scalb (this.cvl, -e);
721: }
722: return this;
723: }
724:
725:
726:
727:
728: public void dump () {
729: this.dump (null, false);
730: }
731: public void dump (String name) {
732: this.dump (name, false);
733: }
734: public void dump (boolean value) {
735: this.dump (null, value);
736: }
737: public void dump (String name, boolean value) {
738: if (name != null) {
739: System.out.printf ("%s=", name);
740: }
741: if ((this.flg & QFP_ZIN) != 0) {
742: System.out.printf ("QFP{flg:0x%08x", this.flg);
743: if (value) {
744: System.out.printf (",val:%s", this.toString ());
745: }
746: System.out.println ("}");
747: } else {
748: System.out.printf ("QFP{flg:0x%08x,epp:%d,dvl:%.16g=0x%016x,cvl:%.16g=0x%016x",
749: this.flg,
750: this.epp,
751: this.dvl, Double.doubleToLongBits (this.dvl),
752: this.cvl, Double.doubleToLongBits (this.cvl));
753: if (value) {
754: System.out.printf (",val:%s", this.toString ());
755: }
756: System.out.println ("}");
757: }
758: }
759:
760:
761:
762: public double getd () {
763: int xf = this.flg;
764: if ((xf & QFP_ZIN) != 0) {
765: return ((xf & QFP_Z) != 0 ? (xf & QFP_M) == 0 ? 0.0 : -0.0 :
766: (xf & QFP_I) != 0 ? (xf & QFP_M) == 0 ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY :
767: Double.NaN);
768: }
769:
770: double xd = this.dvl;
771: if (this.epp != 0) {
772: xd = Math.scalb (xd, this.epp);
773: if (Double.isInfinite (xd)) {
774: QFP.fpsr |= QFP_OF;
775: } else if (xd == 0.0) {
776: QFP.fpsr |= QFP_UF;
777: }
778: }
779: return xd;
780: }
781:
782:
783:
784: public float getf () {
785: int xf = this.flg;
786: if ((xf & QFP_ZIN) != 0) {
787: return ((xf & QFP_Z) != 0 ? (xf & QFP_M) == 0 ? 0.0F : -0.0F :
788: (xf & QFP_I) != 0 ? (xf & QFP_M) == 0 ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY :
789: Float.NaN);
790: }
791:
792: return (float) this.dvl;
793: }
794:
795:
796:
797: public int geti () {
798: int xf = this.flg;
799: if ((xf & QFP_ZIN) != 0) {
800: if ((xf & QFP_Z) != 0) {
801: return 0;
802: }
803: QFP.fpsr |= QFP_OE;
804: return ((xf & QFP_I) != 0 ? (xf & QFP_M) == 0 ? 0x7fffffff : 0x80000000 :
805: 0);
806: }
807:
808: if (this.epp != 0) {
809: if (this.epp < 0) {
810: return 0;
811: }
812: QFP.fpsr |= QFP_OE;
813: return (xf & QFP_M) == 0 ? 0x7fffffff : 0x80000000;
814: }
815: double xd = this.dvl;
816: double xc = this.cvl;
817:
818: if (xd * xc < 0.0) {
819: double u = Math.ulp (xd) * Math.signum (xc);
820: xd += u;
821: xc -= u;
822: }
823: if (xd <= (double) Integer.MIN_VALUE - 1.0 || (double) Integer.MAX_VALUE + 1.0 <= xd) {
824: QFP.fpsr |= QFP_OE;
825: return 0.0 <= xd ? 0x7fffffff : 0x80000000;
826: }
827: return (int) xd;
828: }
829:
830:
831:
832: public long getl () {
833: int xf = this.flg;
834: if ((xf & QFP_ZIN) != 0) {
835: if ((xf & QFP_Z) != 0) {
836: return 0L;
837: }
838: QFP.fpsr |= QFP_OE;
839: return ((xf & QFP_I) != 0 ? (xf & QFP_M) == 0 ? 0x7fffffffffffffffL : 0x8000000000000000L :
840: 0L);
841: }
842:
843: if (this.epp != 0) {
844: if (this.epp < 0) {
845: return 0;
846: }
847: QFP.fpsr |= QFP_OE;
848: return (xf & QFP_M) == 0 ? 0x7fffffffffffffffL : 0x8000000000000000L;
849: }
850: double xd = this.dvl;
851: double xc = this.cvl;
852:
853: if (xd * xc < 0.0) {
854: double u = Math.ulp (xd) * Math.signum (xc);
855: xd += u;
856: xc -= u;
857: }
858: if (xd <= (double) Long.MIN_VALUE - 1.0 || (double) Long.MAX_VALUE + 1.0 <= xd) {
859: QFP.fpsr |= QFP_OE;
860: return 0.0 <= xd ? 0x7fffffffffffffffL : 0x8000000000000000L;
861: }
862: return (long) xd + (long) xc;
863: }
864:
865:
866:
867: public QFP inc () {
868: return this.add (QFP_ONE);
869: }
870:
871:
872: public boolean lt (QFP y) {
873: int xf = this.flg;
874: int yf = y.flg;
875: if (((xf | yf) & QFP_ZIN) != 0) {
876: return EFPBox.EFP_LT_TABLE[xf >>> 24] << (yf >>> 24 - 1) < 0;
877: }
878:
879: int s = (xf & QFP_M) != 0 ? -1 : 1;
880: return (xf != yf ? s :
881: this.epp != y.epp ? this.epp < y.epp ? -s : s :
882: this.dvl != y.dvl ? this.dvl < y.dvl ? -s : s :
883: this.cvl != y.cvl ? this.cvl < y.cvl ? -s : s :
884: 0) < 0;
885: }
886:
887:
888:
889:
890:
891:
892:
893:
894:
895:
896:
897:
898:
899:
900:
901:
902:
903:
904:
905:
906:
907:
908:
909:
910:
911:
912:
913:
914:
915:
916:
917:
918:
919:
920:
921:
922:
923:
924:
925: private static final int[] QFP_MUL_FLG = {
926:
927: 0x00000000,0x01000000,0x02000000,0x01000000,0x04000000,0x01000000,0x01000000,0x01000000,
928: 0x08000000,0x01000000,0x0a000000,0x01000000,0x0c000000,0x01000000,0x01000000,0x01000000,
929: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
930: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
931: 0x02000000,0x01000000,0x02000000,0x01000000,0x01002000,0x01000000,0x01000000,0x01000000,
932: 0x0a000000,0x01000000,0x0a000000,0x01000000,0x01002000,0x01000000,0x01000000,0x01000000,
933: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
934: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
935: 0x04000000,0x01000000,0x01002000,0x01000000,0x04000000,0x01000000,0x01000000,0x01000000,
936: 0x0c000000,0x01000000,0x01002000,0x01000000,0x0c000000,0x01000000,0x01000000,0x01000000,
937: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
938: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
939: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
940: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
941: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
942: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
943: 0x08000000,0x01000000,0x0a000000,0x01000000,0x0c000000,0x01000000,0x01000000,0x01000000,
944: 0x00000000,0x01000000,0x02000000,0x01000000,0x04000000,0x01000000,0x01000000,0x01000000,
945: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
946: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
947: 0x0a000000,0x01000000,0x0a000000,0x01000000,0x01002000,0x01000000,0x01000000,0x01000000,
948: 0x02000000,0x01000000,0x02000000,0x01000000,0x01002000,0x01000000,0x01000000,0x01000000,
949: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
950: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
951: 0x0c000000,0x01000000,0x01002000,0x01000000,0x0c000000,0x01000000,0x01000000,0x01000000,
952: 0x04000000,0x01000000,0x01002000,0x01000000,0x04000000,0x01000000,0x01000000,0x01000000,
953: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
954: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
955: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
956: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
957: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
958: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
959: };
960: public QFP mul (QFP y) {
961:
962: int zf = QFP_MUL_FLG[this.flg >>> 24 - 4 | y.flg >>> 24];
963: if ((zf & QFP_ZIN) != 0) {
964: QFP.fpsr |= zf & QFP_EXC;
965: this.flg = zf & QFP_MZIN;
966: return this;
967: }
968:
969: int ze = this.epp + y.epp;
970: double xd = this.dvl;
971: double xc = this.cvl;
972: double yd = y.dvl;
973: double yc = y.cvl;
974: {
975: double t1 = xd * yd;
976: double t2 = 0x1.0000002p27 * xd;
977: double t3 = 0x1.0000002p27 * yd;
978: double t4 = (xd - t2) + t2;
979: double t5 = (yd - t3) + t3;
980: t2 = xd - t4;
981: t3 = yd - t5;
982: t2 = ((xd + xc) * yc + xc * yd) + ((((t4 * t5 - t1) + t3 * t4) + t2 * t5) + t2 * t3);
983: xd = t1 + t2;
984: xc = (t1 - xd) + t2;
985: }
986:
987: int e = Math.getExponent (xd) - QFP_GETA_BASE & -QFP_GETA_SIZE;
988: if (e != 0) {
989: ze += e;
990: xd = Math.scalb (xd, -e);
991: xc = Math.scalb (xc, -e);
992: }
993:
994: this.flg = zf;
995: this.epp = ze;
996: this.dvl = xd;
997: this.cvl = xc;
998: return this;
999: }
1000: public QFP mul (QFP x, QFP y) {
1001:
1002: int zf = QFP_MUL_FLG[x.flg >>> 24 - 4 | y.flg >>> 24];
1003: if ((zf & QFP_ZIN) != 0) {
1004: QFP.fpsr |= zf & QFP_EXC;
1005: this.flg = zf & QFP_MZIN;
1006: return this;
1007: }
1008:
1009: int ze = x.epp + y.epp;
1010: double xd = x.dvl;
1011: double xc = x.cvl;
1012: double yd = y.dvl;
1013: double yc = y.cvl;
1014: {
1015: double t1 = xd * yd;
1016: double t2 = 0x1.0000002p27 * xd;
1017: double t3 = 0x1.0000002p27 * yd;
1018: double t4 = (xd - t2) + t2;
1019: double t5 = (yd - t3) + t3;
1020: t2 = xd - t4;
1021: t3 = yd - t5;
1022: t2 = ((xd + xc) * yc + xc * yd) + ((((t4 * t5 - t1) + t3 * t4) + t2 * t5) + t2 * t3);
1023: xd = t1 + t2;
1024: xc = (t1 - xd) + t2;
1025: }
1026:
1027: int e = Math.getExponent (xd) - QFP_GETA_BASE & -QFP_GETA_SIZE;
1028: if (e != 0) {
1029: ze += e;
1030: xd = Math.scalb (xd, -e);
1031: xc = Math.scalb (xc, -e);
1032: }
1033:
1034: this.flg = zf;
1035: this.epp = ze;
1036: this.dvl = xd;
1037: this.cvl = xc;
1038: return this;
1039: }
1040:
1041:
1042:
1043:
1044: public QFP mul2 () {
1045: if ((this.flg & QFP_ZIN) != 0) {
1046: return this;
1047: }
1048:
1049:
1050: this.dvl *= 2.0;
1051: this.cvl *= 2.0;
1052:
1053: int e = Math.getExponent (this.dvl) - QFP_GETA_BASE & -QFP_GETA_SIZE;
1054: if (e != 0) {
1055: this.epp += e;
1056: this.dvl = Math.scalb (this.dvl, -e);
1057: this.cvl = Math.scalb (this.cvl, -e);
1058: }
1059: return this;
1060: }
1061: public QFP mul2 (QFP x) {
1062: this.flg = x.flg;
1063: if ((this.flg & QFP_ZIN) != 0) {
1064: return this;
1065: }
1066:
1067:
1068: this.epp = x.epp;
1069: this.dvl = x.dvl * 2.0;
1070: this.cvl = x.cvl * 2.0;
1071:
1072: int e = Math.getExponent (this.dvl) - QFP_GETA_BASE & -QFP_GETA_SIZE;
1073: if (e != 0) {
1074: this.epp += e;
1075: this.dvl = Math.scalb (this.dvl, -e);
1076: this.cvl = Math.scalb (this.cvl, -e);
1077: }
1078: return this;
1079: }
1080:
1081:
1082:
1083:
1084:
1085:
1086: public QFP neg () {
1087: int xf = this.flg;
1088: if ((xf & QFP_ZIN) != 0) {
1089: if ((xf & (QFP_Z | QFP_I)) != 0) {
1090: this.flg = xf ^ QFP_M;
1091: }
1092: return this;
1093: }
1094:
1095: this.flg = xf ^ QFP_M;
1096: this.dvl = -this.dvl;
1097: this.cvl = -this.cvl;
1098: return this;
1099: }
1100: public QFP neg (QFP x) {
1101: int xf = x.flg;
1102: if ((xf & QFP_ZIN) != 0) {
1103: if ((xf & (QFP_Z | QFP_I)) != 0) {
1104: xf ^= QFP_M;
1105: }
1106: this.flg = xf;
1107: return this;
1108: }
1109:
1110: this.flg = xf ^ QFP_M;
1111: this.dvl = -this.dvl;
1112: this.cvl = -this.cvl;
1113: return this;
1114: }
1115: public QFP neg (boolean b) {
1116: return b ? this.neg () : this;
1117: }
1118: public QFP neg (boolean b, QFP x) {
1119: return b ? this.neg (x) : this.setq (x);
1120: }
1121:
1122:
1123:
1124:
1125: public QFP negdec () {
1126: return this.sub (QFP_ONE, this);
1127: }
1128: public QFP negdec (QFP x) {
1129: return this.sub (QFP_ONE, x);
1130: }
1131:
1132:
1133:
1134:
1135:
1136: public QFP rcp () {
1137: int xf = this.flg;
1138: if ((xf & QFP_ZIN) != 0) {
1139: if ((xf & QFP_Z) != 0) {
1140: QFP.fpsr |= QFP_DZ;
1141: xf ^= QFP_Z | QFP_I;
1142: } else if ((xf & QFP_I) != 0) {
1143: xf ^= QFP_Z | QFP_I;
1144: }
1145: this.flg = xf;
1146: return this;
1147: }
1148: QFP t1 = new QFP (xf, -this.epp, 1.0 / this.dvl, 0.0);
1149: QFP t2 = new QFP ().squ (t1).mul (this);
1150: return this.mul2 (t1).sub (t2);
1151: }
1152: public QFP rcp (QFP x) {
1153: int xf = x.flg;
1154: if ((xf & QFP_ZIN) != 0) {
1155: if ((xf & QFP_Z) != 0) {
1156: QFP.fpsr |= QFP_DZ;
1157: xf ^= QFP_Z | QFP_I;
1158: } else if ((xf & QFP_I) != 0) {
1159: xf ^= QFP_Z | QFP_I;
1160: }
1161: this.flg = xf;
1162: return this;
1163: }
1164: QFP t1 = new QFP (xf, -x.epp, 1.0 / x.dvl, 0.0);
1165: QFP t2 = new QFP ().squ (t1).mul (x);
1166: return this.mul2 (t1).sub (t2);
1167: }
1168:
1169:
1170:
1171: public final QFP set0 () {
1172: this.flg = QFP_P | QFP_Z;
1173: return this;
1174: }
1175:
1176:
1177:
1178: public final QFP setd (double d) {
1179: int xf = (int) (Double.doubleToLongBits (d) >>> 36) & QFP_M;
1180: if (d == 0.0) {
1181: this.flg = xf | QFP_Z;
1182: return this;
1183: }
1184: if (Double.isInfinite (d)) {
1185: this.flg = xf | QFP_I;
1186: return this;
1187: }
1188: if (Double.isNaN (d)) {
1189: this.flg = QFP_N;
1190: return this;
1191: }
1192:
1193: this.flg = xf;
1194: this.epp = Math.getExponent (d) - QFP_GETA_BASE & -QFP_GETA_SIZE;
1195: this.dvl = Math.scalb (d, -this.epp);
1196: this.cvl = 0.0;
1197: return this;
1198: }
1199:
1200:
1201:
1202: public final QFP setf (float f) {
1203: int xf = Float.floatToIntBits (f) >>> 4 & QFP_M;
1204: if (f == 0.0) {
1205: this.flg = xf | QFP_Z;
1206: return this;
1207: }
1208: if (Float.isInfinite (f)) {
1209: this.flg = xf | QFP_I;
1210: return this;
1211: }
1212: if (Float.isNaN (f)) {
1213: this.flg = QFP_N;
1214: return this;
1215: }
1216:
1217: this.flg = xf;
1218: this.epp = 0;
1219: this.dvl = (double) f;
1220: this.cvl = 0.0;
1221: return this;
1222: }
1223:
1224:
1225:
1226: public final QFP seti (int i) {
1227: if (i == 0) {
1228: this.flg = QFP_P | QFP_Z;
1229: return this;
1230: }
1231: this.flg = i >>> 4 & QFP_M;
1232: this.epp = 0;
1233: this.dvl = (double) i;
1234: this.cvl = 0.0;
1235: return this;
1236: }
1237:
1238:
1239:
1240: public final QFP setl (long l) {
1241: if (l == 0L) {
1242: this.flg = QFP_P | QFP_Z;
1243: return this;
1244: }
1245: this.flg = (int) (l >>> 36) & QFP_M;
1246: this.epp = 0;
1247:
1248:
1249:
1250:
1251: this.dvl = (double) l;
1252: this.cvl = (double) (l - (this.dvl == 0x1p63 ? 0x8000000000000000L : (long) this.dvl));
1253: return this;
1254: }
1255:
1256:
1257:
1258: public final QFP setq (QFP x) {
1259: this.flg = x.flg;
1260: this.epp = x.epp;
1261: this.dvl = x.dvl;
1262: this.cvl = x.cvl;
1263: return this;
1264: }
1265:
1266:
1267:
1268: public QFP shl (int n) {
1269: if ((this.flg & QFP_ZIN) != 0) {
1270: return this;
1271: }
1272:
1273:
1274: int e = Math.getExponent (this.dvl);
1275: n += this.epp + e;
1276: this.epp = n - QFP_GETA_BASE & -QFP_GETA_SIZE;
1277: n -= this.epp + e;
1278: this.dvl = Math.scalb (this.dvl, n);
1279: this.cvl = Math.scalb (this.cvl, n);
1280: return this;
1281: }
1282:
1283:
1284:
1285: public QFP shr (int n) {
1286: if ((this.flg & QFP_ZIN) != 0) {
1287: return this;
1288: }
1289:
1290:
1291: n = -n;
1292: int e = Math.getExponent (this.dvl);
1293: n += this.epp + e;
1294: this.epp = n - QFP_GETA_BASE & -QFP_GETA_SIZE;
1295: n -= this.epp + e;
1296: this.dvl = Math.scalb (this.dvl, n);
1297: this.cvl = Math.scalb (this.cvl, n);
1298: return this;
1299: }
1300:
1301:
1302:
1303:
1304:
1305: public QFP sqrt () {
1306: int xf = this.flg;
1307: if ((xf & QFP_MZIN) != 0) {
1308: if (xf == QFP_M || xf == (QFP_M | QFP_I)) {
1309: QFP.fpsr |= QFP_OE;
1310: this.flg = QFP_N;
1311: } else {
1312: this.flg = xf;
1313: }
1314: return this;
1315: }
1316:
1317: QFP t = new QFP (Math.sqrt (this.dvl)).shl (this.epp >> 1);
1318: return this.div (this, t).add (t).div2 ();
1319: }
1320: public QFP sqrt (QFP x) {
1321: int xf = x.flg;
1322: if ((xf & QFP_MZIN) != 0) {
1323: if (xf == QFP_M || xf == (QFP_M | QFP_I)) {
1324: QFP.fpsr |= QFP_OE;
1325: this.flg = QFP_N;
1326: } else {
1327: this.flg = xf;
1328: }
1329: return this;
1330: }
1331:
1332: QFP t = new QFP (Math.sqrt (x.dvl)).shl (x.epp >> 1);
1333: return this.div (x, t).add (t).div2 ();
1334: }
1335:
1336:
1337:
1338:
1339: public QFP squ () {
1340: return this.mul (this, this);
1341: }
1342: public QFP squ (QFP x) {
1343: return this.mul (x, x);
1344: }
1345:
1346:
1347:
1348:
1349:
1350:
1351:
1352:
1353:
1354:
1355:
1356:
1357:
1358:
1359:
1360:
1361:
1362:
1363:
1364:
1365:
1366:
1367:
1368:
1369:
1370:
1371:
1372:
1373:
1374:
1375: private static final int[] QFP_SUB_FLG = {
1376:
1377: 0x00000000,0x01000000,0x0a000000,0x01000000,0x80000000,0x01000000,0x01000000,0x01000000,
1378: 0x00000000,0x01000000,0x02000000,0x01000000,0x80000000,0x01000000,0x01000000,0x01000000,
1379: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1380: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1381: 0x02000000,0x01000000,0x01002000,0x01000000,0x02000000,0x01000000,0x01000000,0x01000000,
1382: 0x02000000,0x01000000,0x02000000,0x01000000,0x02000000,0x01000000,0x01000000,0x01000000,
1383: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1384: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1385: 0xc0000000,0x01000000,0x0a000000,0x01000000,0x04000000,0x01000000,0x01000000,0x01000000,
1386: 0xc0000000,0x01000000,0x02000000,0x01000000,0x04000000,0x01000000,0x01000000,0x01000000,
1387: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1388: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1389: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1390: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1391: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1392: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1393: 0x00000000,0x01000000,0x0a000000,0x01000000,0x80000000,0x01000000,0x01000000,0x01000000,
1394: 0x00000000,0x01000000,0x02000000,0x01000000,0x80000000,0x01000000,0x01000000,0x01000000,
1395: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1396: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1397: 0x0a000000,0x01000000,0x0a000000,0x01000000,0x0a000000,0x01000000,0x01000000,0x01000000,
1398: 0x0a000000,0x01000000,0x01002000,0x01000000,0x0a000000,0x01000000,0x01000000,0x01000000,
1399: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1400: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1401: 0xc0000000,0x01000000,0x0a000000,0x01000000,0x0c000000,0x01000000,0x01000000,0x01000000,
1402: 0xc0000000,0x01000000,0x02000000,0x01000000,0x04000000,0x01000000,0x01000000,0x01000000,
1403: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1404: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1405: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1406: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1407: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1408: 0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,0x01000000,
1409: };
1410: public QFP sub (QFP y) {
1411: int xf = this.flg;
1412: int xe = this.epp;
1413: double xd = this.dvl;
1414: double xc = this.cvl;
1415: int yf = y.flg;
1416: int ye = y.epp;
1417: double yd = y.dvl;
1418: double yc = y.cvl;
1419:
1420: int zf = QFP_SUB_FLG[xf >>> 24 - 4 | yf >>> 24];
1421: if ((zf & (0xc0000000 | QFP_ZIN)) != 0) {
1422: if (0 <= zf) {
1423: QFP.fpsr |= zf & QFP_EXC;
1424: this.flg = zf & QFP_MZIN;
1425: } else if (zf << 1 < 0) {
1426: this.flg = yf ^ QFP_M;
1427: this.epp = ye;
1428: this.dvl = yd;
1429: this.cvl = yc;
1430:
1431:
1432:
1433:
1434:
1435: }
1436: return this;
1437: }
1438:
1439:
1440: if (xe != ye) {
1441: if (xe + 128 == ye) {
1442: yd = Math.scalb (yd, 128);
1443: yc = Math.scalb (yc, 128);
1444: } else if (xe - 128 == ye) {
1445: yd = Math.scalb (yd, -128);
1446: yc = Math.scalb (yc, -128);
1447: } else {
1448: if (xe < ye) {
1449: this.flg = yf ^ QFP_M;
1450: this.epp = ye;
1451: this.dvl = yd;
1452: this.cvl = yc;
1453:
1454:
1455:
1456:
1457:
1458: }
1459: return this;
1460: }
1461: }
1462:
1463: {
1464: double t1 = xd - yd;
1465: double t2 = xd - t1;
1466: t2 = (((xd - (t1 + t2)) + (t2 - yd)) + xc) - yc;
1467: xd = t1 + t2;
1468: xc = (t1 - xd) + t2;
1469: }
1470:
1471:
1472:
1473: if (xd == 0.0) {
1474: this.flg = QFP_P | QFP_Z;
1475: return this;
1476: }
1477: this.flg = (int) (Double.doubleToLongBits (xd) >>> 36) & QFP_M;
1478:
1479: int e = Math.getExponent (xd) - QFP_GETA_BASE & -QFP_GETA_SIZE;
1480: if (e != 0) {
1481: xe += e;
1482: xd = Math.scalb (xd, -e);
1483: xc = Math.scalb (xc, -e);
1484: }
1485:
1486: this.epp = xe;
1487: this.dvl = xd;
1488: this.cvl = xc;
1489: return this;
1490: }
1491: public QFP sub (QFP x, QFP y) {
1492: int xf = x.flg;
1493: int xe = x.epp;
1494: double xd = x.dvl;
1495: double xc = x.cvl;
1496: int yf = y.flg;
1497: int ye = y.epp;
1498: double yd = y.dvl;
1499: double yc = y.cvl;
1500:
1501: int zf = QFP_SUB_FLG[xf >>> 24 - 4 | yf >>> 24];
1502: if ((zf & (0xc0000000 | QFP_ZIN)) != 0) {
1503: if (0 <= zf) {
1504: QFP.fpsr |= zf & QFP_EXC;
1505: this.flg = zf & QFP_MZIN;
1506: } else if (zf << 1 < 0) {
1507: this.flg = yf ^ QFP_M;
1508: this.epp = ye;
1509: this.dvl = yd;
1510: this.cvl = yc;
1511: } else {
1512: this.flg = xf;
1513: this.epp = xe;
1514: this.dvl = xd;
1515: this.cvl = xc;
1516: }
1517: return this;
1518: }
1519:
1520:
1521: if (xe != ye) {
1522: if (xe + 128 == ye) {
1523: yd = Math.scalb (yd, 128);
1524: yc = Math.scalb (yc, 128);
1525: } else if (xe - 128 == ye) {
1526: yd = Math.scalb (yd, -128);
1527: yc = Math.scalb (yc, -128);
1528: } else {
1529: if (xe < ye) {
1530: this.flg = yf ^ QFP_M;
1531: this.epp = ye;
1532: this.dvl = yd;
1533: this.cvl = yc;
1534: } else {
1535: this.flg = xf;
1536: this.epp = xe;
1537: this.dvl = xd;
1538: this.cvl = xc;
1539: }
1540: return this;
1541: }
1542: }
1543:
1544: {
1545: double t1 = xd - yd;
1546: double t2 = xd - t1;
1547: t2 = (((xd - (t1 + t2)) + (t2 - yd)) + xc) - yc;
1548: xd = t1 + t2;
1549: xc = (t1 - xd) + t2;
1550: }
1551:
1552:
1553:
1554: if (xd == 0.0) {
1555: this.flg = QFP_P | QFP_Z;
1556: return this;
1557: }
1558: this.flg = (int) (Double.doubleToLongBits (xd) >>> 36) & QFP_M;
1559:
1560: int e = Math.getExponent (xd) - QFP_GETA_BASE & -QFP_GETA_SIZE;
1561: if (e != 0) {
1562: xe += e;
1563: xd = Math.scalb (xd, -e);
1564: xc = Math.scalb (xc, -e);
1565: }
1566:
1567: this.epp = xe;
1568: this.dvl = xd;
1569: this.cvl = xc;
1570: return this;
1571: }
1572:
1573:
1574:
1575: public static final QFP[] QFP_TEN_P16QR = {
1576:
1577: new QFP (QFP_P, 0, 0x1.0p0, 0.0),
1578: new QFP (QFP_P, 0, 0x1.4p3, 0.0),
1579: new QFP (QFP_P, 0, 0x1.9p6, 0.0),
1580: new QFP (QFP_P, 0, 0x1.f4p9, 0.0),
1581: new QFP (QFP_P, 0, 0x1.388p13, 0.0),
1582: new QFP (QFP_P, 0, 0x1.86ap16, 0.0),
1583: new QFP (QFP_P, 0, 0x1.e848p19, 0.0),
1584: new QFP (QFP_P, 0, 0x1.312dp23, 0.0),
1585: new QFP (QFP_P, 0, 0x1.7d784p26, 0.0),
1586: new QFP (QFP_P, 0, 0x1.dcd65p29, 0.0),
1587: new QFP (QFP_P, 0, 0x1.2a05f2p33, 0.0),
1588: new QFP (QFP_P, 0, 0x1.74876e8p36, 0.0),
1589: new QFP (QFP_P, 0, 0x1.d1a94a2p39, 0.0),
1590: new QFP (QFP_P, 0, 0x1.2309ce54p43, 0.0),
1591: new QFP (QFP_P, 0, 0x1.6bcc41e9p46, 0.0),
1592: new QFP (QFP_P, 0, 0x1.c6bf52634p49, 0.0),
1593: new QFP (QFP_P, 0, 0x1.0p0, 0.0),
1594: new QFP (QFP_P, 0, 0x1.1c37937e08p53, 0.0),
1595: new QFP (QFP_P, 0, 0x1.3b8b5b5056e17p106, -0x1.3107fp52),
1596: new QFP (QFP_P, 0, 0x1.5e531a0a1c873p159, -0x1.14b4c7a76a406p105),
1597: new QFP (QFP_P, 0, 0x1.84f03e93ff9f5p212, -0x1.2ac340948e389p157),
1598: new QFP (QFP_P, 512, 0x1.afcef51f0fb5fp-247, -0x1.08f322e84da1p-308),
1599: new QFP (QFP_P, 512, 0x1.df67562d8b363p-194, -0x1.ae9d180b58861p-248),
1600: new QFP (QFP_P, 512, 0x1.0a1f5b8132466p-140, 0x1.4f01f167b5e3p-194),
1601: new QFP (QFP_P, 512, 0x1.27748f9301d32p-87, -0x1.901cc86649e4ap-141),
1602: new QFP (QFP_P, 512, 0x1.4805738b51a75p-34, -0x1.18a0e9df9363ap-89),
1603: new QFP (QFP_P, 512, 0x1.6c2d4256ffcc3p19, -0x1.56a2119e533adp-38),
1604: new QFP (QFP_P, 512, 0x1.945145230b378p72, -0x1.b20a11c22bf0cp15),
1605: new QFP (QFP_P, 512, 0x1.c0e1ef1a724ebp125, -0x1.4abd220ed605cp71),
1606: new QFP (QFP_P, 512, 0x1.f25c186a6f04cp178, 0x1.45a7709a56ccep123),
1607: new QFP (QFP_P, 512, 0x1.14a52dffc6799p232, 0x1.2f82bd6b70d9ap177),
1608: new QFP (QFP_P, 1024, 0x1.33234de7ad7e3p-227, -0x1.34a66b24bc3ebp-283),
1609: new QFP (QFP_P, 0, 0x1.0p0, 0.0),
1610: new QFP (QFP_P, 1024, 0x1.54fdd7f73bf3cp-174, -0x1.7222446fe467p-229),
1611: new QFP (QFP_P, 1536, 0x1.c633415d4c1d2p164, 0x1.c6cc655c54bc5p109),
1612: new QFP (QFP_P, 2560, 0x1.2e7f39519a015p-9, -0x1.739372c035fd3p-64),
1613: new QFP (QFP_P, 3584, 0x1.92eceb0d02ea2p-183, -0x1.f44d79616b874p-237),
1614: new QFP (QFP_P, 4096, 0x1.0c59181dd70aep156, -0x1.34f7a4332a3fap101),
1615: new QFP (QFP_P, 5120, 0x1.65706a7673275p-18, -0x1.bbda853c4b3e3p-77),
1616: new QFP (QFP_P, 6144, 0x1.dc1bbb0924957p-192, 0x1.185a80e1e6764p-248),
1617: new QFP (QFP_P, 6656, 0x1.3d1676bb8a7acp147, -0x1.0dac596b98e6bp93),
1618: new QFP (QFP_P, 7680, 0x1.a65c406483e9p-27, 0x1.bcfd432008104p-84),
1619: new QFP (QFP_P, 8704, 0x1.194aa9804143ep-200, 0x1.4cbbfda13244dp-256),
1620: new QFP (QFP_P, 9216, 0x1.76ae153537b2fp138, -0x1.9d9bfbc56226fp80),
1621: new QFP (QFP_P, 10240, 0x1.f312ba4bb116bp-36, 0x1.457ee84626d0ap-90),
1622: new QFP (QFP_P, 11264, 0x1.4c61defaad34p-209, -0x1.baaf1c99fdcacp-264),
1623: new QFP (QFP_P, 11776, 0x1.babb91457e4fep129, 0x1.fbcad508c760fp75),
1624: new QFP (QFP_P, 12800, 0x1.26dc0ee6fb8cap-44, -0x1.24e7716893ec1p-100),
1625: new QFP (QFP_P, 0, 0x1.0p0, 0.0),
1626: new QFP (QFP_P, 13824, 0x1.88c0a40514413p-218, -0x1.94dacfab01fedp-275),
1627: new QFP (QFP_P, 27136, 0x1.2d4743a2ff5e4p77, 0x1.1a0c7c2892306p22),
1628: };
1629: public static final QFP[] QFP_TEN_M16QR = {
1630:
1631: new QFP (QFP_P, 0, 0x1.0p0, 0.0),
1632: new QFP (QFP_P, 0, 0x1.999999999999ap-4, -0x1.999999999999ap-58),
1633: new QFP (QFP_P, 0, 0x1.47ae147ae147bp-7, -0x1.eb851eb851eb8p-63),
1634: new QFP (QFP_P, 0, 0x1.0624dd2f1a9fcp-10, -0x1.89374bc6a7efap-66),
1635: new QFP (QFP_P, 0, 0x1.a36e2eb1c432dp-14, -0x1.6a161e4f765fep-68),
1636: new QFP (QFP_P, 0, 0x1.4f8b588e368f1p-17, -0x1.ee78183f91e64p-71),
1637: new QFP (QFP_P, 0, 0x1.0c6f7a0b5ed8dp-20, 0x1.b5a63f9a49c2cp-75),
1638: new QFP (QFP_P, 0, 0x1.ad7f29abcaf48p-24, 0x1.5e1e99483b023p-78),
1639: new QFP (QFP_P, 0, 0x1.5798ee2308c3ap-27, -0x1.03023df2d4c94p-82),
1640: new QFP (QFP_P, 0, 0x1.12e0be826d695p-30, -0x1.34674bfabb83bp-84),
1641: new QFP (QFP_P, 0, 0x1.b7cdfd9d7bdbbp-34, -0x1.20a5465df8d2cp-88),
1642: new QFP (QFP_P, 0, 0x1.5fd7fe1796495p-37, 0x1.7f7bc7b4d28aap-91),
1643: new QFP (QFP_P, 0, 0x1.19799812dea11p-40, 0x1.97f27f0f6e886p-96),
1644: new QFP (QFP_P, 0, 0x1.c25c268497682p-44, -0x1.ecd79a5a0df95p-99),
1645: new QFP (QFP_P, 0, 0x1.6849b86a12b9bp-47, 0x1.ea70909833de7p-107),
1646: new QFP (QFP_P, 0, 0x1.203af9ee75616p-50, -0x1.937831647f5ap-104),
1647: new QFP (QFP_P, 0, 0x1.0p0, 0.0),
1648: new QFP (QFP_P, 0, 0x1.cd2b297d889bcp-54, 0x1.5b4c2ebe68799p-109),
1649: new QFP (QFP_P, 0, 0x1.9f623d5a8a733p-107, -0x1.a2cc10f3892d4p-161),
1650: new QFP (QFP_P, 0, 0x1.7624f8a762fd8p-160, 0x1.595560c018581p-215),
1651: new QFP (QFP_P, 0, 0x1.50ffd44f4a73dp-213, 0x1.a53f2398d747bp-268),
1652: new QFP (QFP_P, -512, 0x1.2f8ac174d6123p246, 0x1.a5dccd879fc96p191),
1653: new QFP (QFP_P, -512, 0x1.116805effaeaap193, 0x1.cd88ede5810c7p139),
1654: new QFP (QFP_P, -512, 0x1.ec866b79e0cbap139, 0x1.bea6a30bdaffap85),
1655: new QFP (QFP_P, -512, 0x1.bba08cf8c979dp86, -0x1.afa9c1a60497dp32),
1656: new QFP (QFP_P, -512, 0x1.8f9574dcf8a7p33, 0x1.647f32529774bp-21),
1657: new QFP (QFP_P, -512, 0x1.67e9c127b6e74p-20, 0x1.26b3da42cecadp-76),
1658: new QFP (QFP_P, -512, 0x1.442e4fb67196p-73, 0x1.7dc56d0072d28p-131),
1659: new QFP (QFP_P, -512, 0x1.23ff06eea847ap-126, -0x1.fcc24e7cae5cfp-180),
1660: new QFP (QFP_P, -512, 0x1.0701bd527b498p-179, -0x1.cfdedc1a30d3p-233),
1661: new QFP (QFP_P, -512, 0x1.d9ca79d89462ap-233, -0x1.425b0740a9caep-288),
1662: new QFP (QFP_P, -1024, 0x1.aac0bf9b9e65cp226, 0x1.d6fb1e4a9a909p171),
1663: new QFP (QFP_P, 0, 0x1.0p0, 0.0),
1664: new QFP (QFP_P, -1024, 0x1.8062864ac6f43p173, 0x1.39fa911155ffp118),
1665: new QFP (QFP_P, -1536, 0x1.2093dc65b647ap-165, 0x1.0e3899699972p-219),
1666: new QFP (QFP_P, -2560, 0x1.b14cda94a0bbdp8, 0x1.6b5ae1b259461p-47),
1667: new QFP (QFP_P, -3584, 0x1.454d054bb4af8p182, 0x1.7b0f4c02b0d7ap126),
1668: new QFP (QFP_P, -4096, 0x1.e870ba12ebdb7p-157, 0x1.5f0fa5fb329e7p-211),
1669: new QFP (QFP_P, -5120, 0x1.6eb2893ea54e2p17, 0x1.b268e1eb7534p-38),
1670: new QFP (QFP_P, -6144, 0x1.134c7749892f7p191, -0x1.78c9be2976cf8p137),
1671: new QFP (QFP_P, -6656, 0x1.9d5ca69e686c6p-148, -0x1.0ddb6d7695869p-202),
1672: new QFP (QFP_P, -7680, 0x1.3655081e5142cp26, 0x1.c7f1c9d4e0198p-28),
1673: new QFP (QFP_P, -8704, 0x1.d1f6fb85bd815p199, -0x1.fdd33889c15f4p145),
1674: new QFP (QFP_P, -9216, 0x1.5dd2e72224515p-139, 0x1.e5718c3e1a28p-193),
1675: new QFP (QFP_P, -10240, 0x1.06a17e7922aebp35, 0x1.43f3cf11b5fc6p-19),
1676: new QFP (QFP_P, -11264, 0x1.8a57514d5d62cp208, -0x1.36b0b39a33d88p154),
1677: new QFP (QFP_P, -11776, 0x1.280d5f1f07facp-130, 0x1.32a5a6f1a7076p-184),
1678: new QFP (QFP_P, -12800, 0x1.bc85ff1a6f95bp43, 0x1.fc518fbd22355p-14),
1679: new QFP (QFP_P, 0, 0x1.0p0, 0.0),
1680: new QFP (QFP_P, -13824, 0x1.4dba0991a59d4p217, -0x1.0e90e3f6e2f1ep159),
1681: new QFP (QFP_P, -27136, 0x1.b30d8416d0db5p-78, 0x1.a574753f616c1p-135),
1682: };
1683: public String toString () {
1684: int xf = this.flg;
1685: if ((xf & QFP_ZIN) != 0) {
1686: return (xf == (QFP_P | QFP_Z) ? "0" :
1687: xf == (QFP_M | QFP_Z) ? "-0" :
1688: xf == (QFP_P | QFP_I) ? "Infinity" :
1689: xf == (QFP_M | QFP_I) ? "-Infinity" :
1690: "NaN");
1691: }
1692: StringBuilder sb = new StringBuilder ();
1693: QFP x = new QFP (this);
1694: if ((xf & QFP_M) != 0) {
1695: sb.append ('-');
1696: x.neg ();
1697: }
1698: QFP t = new QFP ();
1699:
1700:
1701: int e = (int) Math.floor ((double) (x.epp + Math.getExponent (x.dvl)) * 0.30102999566398119521373889472);
1702:
1703: if (0 < e) {
1704: x.mul (QFP_TEN_M16QR[e & 15]);
1705: if (16 <= e) {
1706: x.mul (QFP_TEN_M16QR[16 + (e >> 4 & 15)]);
1707: if (256 <= e) {
1708: x.mul (QFP_TEN_M16QR[32 + (e >> 8 & 15)]);
1709: if (4096 <= e) {
1710: x.mul (QFP_TEN_M16QR[48 + (e >> 12)]);
1711: }
1712: }
1713: }
1714: } else if (e < 0) {
1715: x.mul (QFP_TEN_P16QR[-e & 15]);
1716: if (e <= -16) {
1717: x.mul (QFP_TEN_P16QR[16 + (-e >> 4 & 15)]);
1718: if (e <= -256) {
1719: x.mul (QFP_TEN_P16QR[32 + (-e >> 8 & 15)]);
1720: if (e <= -4096) {
1721: x.mul (QFP_TEN_P16QR[48 + (-e >> 12)]);
1722: }
1723: }
1724: }
1725: }
1726:
1727:
1728: char[] w = new char[34];
1729: {
1730: int num = x.geti ();
1731: int bcd = XEiJ.FMT_BCD4[num];
1732: w[0] = (char) ('0' | bcd >> 4 );
1733: w[1] = (char) ('0' | bcd & 15);
1734: for (int i = 2; i < 34; i += 4) {
1735: x.sub (t.seti (num)).mul (QFP_TENTO4);
1736: num = x.geti ();
1737: bcd = XEiJ.FMT_BCD4[num];
1738: w[i ] = (char) ('0' | bcd >> 12 );
1739: w[i + 1] = (char) ('0' | bcd >> 8 & 15);
1740: w[i + 2] = (char) ('0' | bcd >> 4 & 15);
1741: w[i + 3] = (char) ('0' | bcd & 15);
1742: }
1743: }
1744:
1745:
1746: int h = w[0] != '0' ? 0 : w[1] != '0' ? 1 : 2;
1747:
1748: int o = h + 30;
1749: if ('5' <= w[o]) {
1750: int i = o;
1751: while ('9' < ++w[--i]) {
1752: w[i] = '0';
1753: }
1754: if (i < h) {
1755: h--;
1756: o--;
1757: }
1758: }
1759:
1760:
1761: e -= h - 1;
1762:
1763:
1764: while (w[o - 1] == '0') {
1765: o--;
1766: }
1767:
1768: if (0 <= e && e < 30) {
1769: sb.append (w, h, e + 1);
1770: h += e + 1;
1771: if (h < o) {
1772: sb.append ('.')
1773: .append (w, h, o - h);
1774: }
1775: } else if (-4 <= e && e < 0) {
1776: sb.append ('0')
1777: .append ('.');
1778: while (++e < 0) {
1779: sb.append ('0');
1780: }
1781: sb.append (w, h, o - h);
1782: } else {
1783: sb.append (w[h++]);
1784: if (h < o) {
1785: sb.append ('.')
1786: .append (w, h, o - h);
1787: }
1788: sb.append ('e')
1789: .append (e);
1790: }
1791: return sb.toString ();
1792: }
1793:
1794: }
1795:
1796:
1797: