4380
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2017 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libbasic2' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
LimitedPrecisionReal variableByteSubclass:#QDouble
|
|
17 |
instanceVariableNames:''
|
|
18 |
classVariableNames:'DefaultPrintFormat QDoubleZero QDoubleOne Pi E Ln2 Ln10 Epsilon'
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Magnitude-Numbers'
|
|
21 |
!
|
|
22 |
|
|
23 |
!QDouble primitiveDefinitions!
|
4385
|
24 |
|
4380
|
25 |
%{
|
|
26 |
#include <stdio.h>
|
|
27 |
#include <errno.h>
|
|
28 |
|
|
29 |
#define __USE_ISOC9X 1
|
|
30 |
#define __USE_ISOC99 1
|
|
31 |
#include <math.h>
|
|
32 |
|
|
33 |
/*
|
|
34 |
* on some systems, errno is a macro ... check for it here
|
|
35 |
*/
|
|
36 |
#ifndef errno
|
|
37 |
extern errno;
|
|
38 |
#endif
|
|
39 |
|
|
40 |
#if !defined (__win32__)
|
|
41 |
# include <locale.h>
|
|
42 |
#endif
|
|
43 |
|
|
44 |
#if defined (__aix__)
|
|
45 |
# include <float.h>
|
|
46 |
#endif
|
|
47 |
|
|
48 |
#if defined(__irix__) || defined(__solaris__) || defined(__sunos__)
|
|
49 |
# include <nan.h>
|
|
50 |
#endif
|
|
51 |
|
|
52 |
#if defined(__linux__)
|
|
53 |
# ifndef NAN
|
|
54 |
# include <bits/nan.h>
|
|
55 |
# endif
|
|
56 |
#endif
|
|
57 |
|
|
58 |
struct qd_real {
|
|
59 |
double x[4]; /* The Components. */
|
|
60 |
};
|
|
61 |
|
|
62 |
struct __quadDoubleStruct {
|
|
63 |
STX_OBJ_HEADER
|
|
64 |
#ifdef __NEED_DOUBLE_ALIGN
|
|
65 |
__FILLTYPE_DOUBLE f_filler;
|
|
66 |
#endif
|
|
67 |
double d_quadDoubleValue[4];
|
|
68 |
};
|
|
69 |
|
|
70 |
#define __QuadDoubleInstPtr(obj) ((struct __quadDoubleStruct *)(__objPtr(obj)))
|
|
71 |
|
|
72 |
#ifndef __isQuadDouble
|
|
73 |
# define __isQuadDouble(o) \
|
|
74 |
(__Class(o) == @global(QuadDouble))
|
|
75 |
#endif
|
|
76 |
|
|
77 |
#ifndef __qIsQuadDouble
|
|
78 |
# define __qIsQuadDouble(o) \
|
|
79 |
(__qClass(o) == @global(QuadDouble))
|
|
80 |
#endif
|
|
81 |
|
|
82 |
#define __qNew_qdReal(newQD, d0,d1,d2,d3) { \
|
|
83 |
__qNew(newQD, sizeof(struct __quadDoubleStruct)); \
|
|
84 |
__stx_setClass(newQD, QDouble); \
|
|
85 |
__QuadDoubleInstPtr(newQD)->d_quadDoubleValue[0] = d0; \
|
|
86 |
__QuadDoubleInstPtr(newQD)->d_quadDoubleValue[1] = d1; \
|
|
87 |
__QuadDoubleInstPtr(newQD)->d_quadDoubleValue[2] = d2; \
|
|
88 |
__QuadDoubleInstPtr(newQD)->d_quadDoubleValue[3] = d3; \
|
|
89 |
}
|
|
90 |
|
|
91 |
// qd_real(c0, c1, c2, c3);
|
|
92 |
|
|
93 |
#define _QD_SPLITTER 134217729.0 // = 2^27 + 1
|
|
94 |
#define _QD_SPLIT_THRESH 6.69692879491417e+299 // = 2^996
|
|
95 |
|
|
96 |
#define m_quick_two_sum(rslt, a, b, err) {\
|
|
97 |
double s = a + b;\
|
|
98 |
err = b - (s - a);\
|
|
99 |
rslt = s; \
|
|
100 |
}
|
|
101 |
|
|
102 |
#define m_two_sum(rslt, a, b, err) {\
|
|
103 |
double s = a + b;\
|
|
104 |
double bb = s - a;\
|
|
105 |
err = (a - (s - bb)) + (b - bb);\
|
|
106 |
rslt = s;\
|
|
107 |
}
|
|
108 |
|
|
109 |
#define m_three_sum(a, b, c) { \
|
|
110 |
double t1, t2, t3; \
|
|
111 |
m_two_sum(t1, a, b, t2); \
|
|
112 |
m_two_sum(a, c, t1, t3); \
|
|
113 |
m_two_sum(b, t2, t3, c); \
|
|
114 |
}
|
|
115 |
|
|
116 |
#define m_three_sum2(a, b, c) {\
|
|
117 |
double t1, t2, t3;\
|
|
118 |
m_two_sum(t1, a, b, t2);\
|
|
119 |
m_two_sum(a, c, t1, t3);\
|
|
120 |
b = t2 + t3;\
|
|
121 |
}
|
|
122 |
|
|
123 |
#ifndef QD_FMS
|
|
124 |
|
|
125 |
/* Computes high word and lo word of a */
|
|
126 |
#define m_split(a, hi, lo) {\
|
|
127 |
double temp;\
|
|
128 |
if (a > _QD_SPLIT_THRESH || a < -_QD_SPLIT_THRESH) {\
|
|
129 |
a *= 3.7252902984619140625e-09;\
|
|
130 |
temp = _QD_SPLITTER * a;\
|
|
131 |
hi = temp - (temp - a);\
|
|
132 |
lo = a - hi;\
|
|
133 |
hi *= 268435456.0;\
|
|
134 |
lo *= 268435456.0;\
|
|
135 |
} else {\
|
|
136 |
temp = _QD_SPLITTER * a;\
|
|
137 |
hi = temp - (temp - a);\
|
|
138 |
lo = a - hi;\
|
|
139 |
}\
|
|
140 |
}
|
|
141 |
|
|
142 |
#endif
|
|
143 |
|
|
144 |
|
|
145 |
#ifdef QD_FMS
|
|
146 |
|
|
147 |
/* Computes fl(a*b) and err(a*b). */
|
|
148 |
|
|
149 |
#define m_two_prod(rslt, a, b, err) {\
|
|
150 |
double p = a * b;\
|
|
151 |
err = QD_FMS(a, b, p);\
|
|
152 |
rslt = p; \
|
|
153 |
}
|
|
154 |
|
|
155 |
#else
|
|
156 |
|
|
157 |
#define m_two_prod(rslt, a, b, err) {\
|
|
158 |
double a_hi, a_lo, b_hi, b_lo;\
|
|
159 |
double p = a * b;\
|
|
160 |
m_split(a, a_hi, a_lo);\
|
|
161 |
m_split(b, b_hi, b_lo);\
|
|
162 |
err = ((a_hi * b_hi - p) + a_hi * b_lo + a_lo * b_hi) + a_lo * b_lo;\
|
|
163 |
rslt = p; \
|
|
164 |
}
|
|
165 |
|
|
166 |
#endif
|
|
167 |
|
|
168 |
#ifdef QD_FMS
|
|
169 |
|
|
170 |
#define m_two_sqr(rslt, a, err) {\
|
|
171 |
double p = a * a;\
|
|
172 |
err = QD_FMS(a, a, p);\
|
|
173 |
rslt = p;\
|
|
174 |
}
|
|
175 |
|
|
176 |
#else
|
|
177 |
|
|
178 |
#define m_two_sqr(rslt, a, err) {\
|
|
179 |
double hi, lo;\
|
|
180 |
double q = a * a;\
|
|
181 |
m_split(a, hi, lo);\
|
|
182 |
err = ((hi * hi - q) + 2.0 * hi * lo) + lo * lo;\
|
|
183 |
rslt = q;\
|
|
184 |
}
|
|
185 |
|
|
186 |
#endif
|
|
187 |
|
|
188 |
#define m_renorm4(c0, c1, c2, c3) {\
|
|
189 |
double s0, s1, s2 = 0.0, s3 = 0.0;\
|
|
190 |
\
|
|
191 |
if (! isinf(c0)) { \
|
|
192 |
\
|
|
193 |
m_quick_two_sum(s0, c2, c3, c3);\
|
|
194 |
m_quick_two_sum(s0, c1, s0, c2);\
|
|
195 |
m_quick_two_sum(c0, c0, s0, c1);\
|
|
196 |
\
|
|
197 |
s0 = c0;\
|
|
198 |
s1 = c1;\
|
|
199 |
if (s1 != 0.0) {\
|
|
200 |
m_quick_two_sum(s1, s1, c2, s2);\
|
|
201 |
if (s2 != 0.0) {\
|
|
202 |
m_quick_two_sum(s2, s2, c3, s3);\
|
|
203 |
} else {\
|
|
204 |
m_quick_two_sum(s1, s1, c3, s2);\
|
4385
|
205 |
}\
|
4380
|
206 |
} else {\
|
|
207 |
m_quick_two_sum(s0, s0, c2, s1);\
|
|
208 |
if (s1 != 0.0) {\
|
|
209 |
m_quick_two_sum(s1, s1, c3, s2);\
|
|
210 |
} else {\
|
|
211 |
m_quick_two_sum(s0, s0, c3, s1);\
|
|
212 |
}\
|
|
213 |
}\
|
|
214 |
\
|
|
215 |
c0 = s0;\
|
|
216 |
c1 = s1;\
|
|
217 |
c2 = s2;\
|
|
218 |
c3 = s3;\
|
|
219 |
}\
|
|
220 |
}
|
|
221 |
|
|
222 |
#define m_renorm5(c0, c1, c2, c3, c4) { \
|
|
223 |
double s0, s1, s2 = 0.0, s3 = 0.0; \
|
|
224 |
\
|
|
225 |
if (! isinf(c0)) { \
|
|
226 |
m_two_sum(s0, c3, c4, c4); \
|
|
227 |
m_quick_two_sum(s0, c2, s0, c3); \
|
|
228 |
m_quick_two_sum(s0, c1, s0, c2); \
|
|
229 |
m_quick_two_sum(c0, c0, s0, c1); \
|
|
230 |
\
|
|
231 |
s0 = c0; \
|
|
232 |
s1 = c1; \
|
|
233 |
\
|
|
234 |
m_two_sum(s0, c0, c1, s1); \
|
|
235 |
if (s1 != 0.0) { \
|
|
236 |
m_quick_two_sum(s1, s1, c2, s2); \
|
|
237 |
if (s2 != 0.0) { \
|
|
238 |
m_quick_two_sum(s2 ,s2, c3, s3); \
|
|
239 |
if (s3 != 0.0) {\
|
|
240 |
s3 += c4; \
|
|
241 |
} else {\
|
|
242 |
s2 += c4;\
|
|
243 |
}\
|
|
244 |
} else { \
|
|
245 |
m_quick_two_sum(s1, s1, c3, s2); \
|
|
246 |
if (s2 != 0.0) {\
|
|
247 |
m_quick_two_sum(s2, s2, c4, s3); \
|
|
248 |
} else { \
|
|
249 |
m_quick_two_sum(s1, s1, c4, s2); \
|
|
250 |
} \
|
|
251 |
} \
|
|
252 |
} else { \
|
|
253 |
m_quick_two_sum(s0,s0, c2, s1); \
|
|
254 |
if (s1 != 0.0) { \
|
|
255 |
m_quick_two_sum(s1,s1, c3, s2); \
|
|
256 |
if (s2 != 0.0) {\
|
|
257 |
m_quick_two_sum(s2,s2, c4, s3); \
|
|
258 |
} else { \
|
|
259 |
m_quick_two_sum(s1 ,s1, c4, s2); \
|
|
260 |
} \
|
|
261 |
} else { \
|
|
262 |
m_quick_two_sum(s0,s0, c3, s1); \
|
|
263 |
if (s1 != 0.0) { \
|
|
264 |
m_quick_two_sum(s1,s1, c4, s2); \
|
|
265 |
} else { \
|
|
266 |
m_quick_two_sum(s0,s0, c4, s1); \
|
|
267 |
} \
|
|
268 |
} \
|
|
269 |
} \
|
|
270 |
\
|
|
271 |
c0 = s0; \
|
|
272 |
c1 = s1; \
|
|
273 |
c2 = s2; \
|
|
274 |
c3 = s3; \
|
|
275 |
} \
|
|
276 |
}
|
|
277 |
|
|
278 |
%}
|
|
279 |
! !
|
|
280 |
|
|
281 |
!QDouble primitiveFunctions!
|
|
282 |
%{
|
|
283 |
|
|
284 |
/*********** Basic Functions ************/
|
|
285 |
/* Computes fl(a+b) and err(a+b). Assumes |a| >= |b|. */
|
|
286 |
inline double
|
|
287 |
quick_two_sum(double a, double b, double *errPtr) {
|
|
288 |
double s = a + b;
|
|
289 |
*errPtr = b - (s - a);
|
|
290 |
return s;
|
|
291 |
}
|
|
292 |
|
|
293 |
/* Computes fl(a-b) and err(a-b). Assumes |a| >= |b| */
|
|
294 |
inline double
|
|
295 |
quick_two_diff(double a, double b, double *errPtr) {
|
|
296 |
double s = a - b;
|
|
297 |
*errPtr = (a - s) - b;
|
|
298 |
return s;
|
|
299 |
}
|
|
300 |
|
|
301 |
/* Computes fl(a+b) and err(a+b). */
|
|
302 |
inline double
|
|
303 |
two_sum(double a, double b, double *errPtr) {
|
|
304 |
double s = a + b;
|
|
305 |
double bb = s - a;
|
|
306 |
*errPtr = (a - (s - bb)) + (b - bb);
|
|
307 |
return s;
|
|
308 |
}
|
|
309 |
|
|
310 |
/* Computes fl(a-b) and err(a-b). */
|
|
311 |
inline double
|
|
312 |
two_diff(double a, double b, double *errPtr) {
|
|
313 |
double s = a - b;
|
|
314 |
double bb = s - a;
|
|
315 |
*errPtr = (a - (s - bb)) - (b + bb);
|
|
316 |
return s;
|
|
317 |
}
|
|
318 |
|
|
319 |
#ifndef QD_FMS
|
|
320 |
/* Computes high word and lo word of a */
|
|
321 |
inline void
|
|
322 |
split(double a, double *hiPtr, double *loPtr) {
|
|
323 |
double temp;
|
|
324 |
if (a > _QD_SPLIT_THRESH || a < -_QD_SPLIT_THRESH) {
|
|
325 |
a *= 3.7252902984619140625e-09; // 2^-28
|
|
326 |
temp = _QD_SPLITTER * a;
|
|
327 |
*hiPtr = temp - (temp - a);
|
|
328 |
*loPtr = a - *hiPtr;
|
|
329 |
*hiPtr *= 268435456.0; // 2^28
|
|
330 |
*loPtr *= 268435456.0; // 2^28
|
|
331 |
} else {
|
|
332 |
temp = _QD_SPLITTER * a;
|
|
333 |
*hiPtr = temp - (temp - a);
|
|
334 |
*loPtr = a - *hiPtr;
|
|
335 |
}
|
|
336 |
}
|
|
337 |
#endif
|
|
338 |
|
|
339 |
/* Computes fl(a*b) and err(a*b). */
|
|
340 |
inline double
|
|
341 |
two_prod(double a, double b, double *errPtr) {
|
|
342 |
#ifdef QD_FMS
|
|
343 |
double p = a * b;
|
|
344 |
*errPtr = QD_FMS(a, b, p);
|
|
345 |
return p;
|
|
346 |
#else
|
|
347 |
double a_hi, a_lo, b_hi, b_lo;
|
|
348 |
double p = a * b;
|
|
349 |
split(a, &a_hi, &a_lo);
|
|
350 |
split(b, &b_hi, &b_lo);
|
|
351 |
*errPtr = ((a_hi * b_hi - p) + a_hi * b_lo + a_lo * b_hi) + a_lo * b_lo;
|
|
352 |
return p;
|
|
353 |
#endif
|
|
354 |
}
|
|
355 |
|
|
356 |
/* Computes fl(a*a) and err(a*a). Faster than the above method. */
|
|
357 |
inline double
|
|
358 |
two_sqr(double a, double *errPtr) {
|
|
359 |
#ifdef QD_FMS
|
|
360 |
double p = a * a;
|
|
361 |
*errPtr = QD_FMS(a, a, p);
|
|
362 |
return p;
|
|
363 |
#else
|
|
364 |
double hi, lo;
|
|
365 |
double q = a * a;
|
|
366 |
split(a, &hi, &lo);
|
|
367 |
*errPtr = ((hi * hi - q) + 2.0 * hi * lo) + lo * lo;
|
|
368 |
return q;
|
|
369 |
#endif
|
|
370 |
}
|
|
371 |
|
|
372 |
/* Computes the nearest integer to d. */
|
|
373 |
inline double
|
|
374 |
nint(double d) {
|
|
375 |
if (d == floor(d))
|
|
376 |
return d;
|
|
377 |
return floor(d + 0.5);
|
|
378 |
}
|
|
379 |
|
|
380 |
/* Computes the truncated integer. */
|
|
381 |
inline double
|
|
382 |
aint(double d) {
|
|
383 |
return (d >= 0.0) ? floor(d) : ceil(d);
|
|
384 |
}
|
|
385 |
|
|
386 |
inline void
|
|
387 |
renorm4(double *c0Ptr, double *c1Ptr, double *c2Ptr, double *c3Ptr) {
|
|
388 |
double s0, s1, s2 = 0.0, s3 = 0.0;
|
|
389 |
double c0 = *c0Ptr;
|
|
390 |
|
|
391 |
if (isinf(c0)) return;
|
|
392 |
|
|
393 |
s0 = quick_two_sum(*c2Ptr, *c3Ptr, c3Ptr);
|
|
394 |
s0 = quick_two_sum(*c1Ptr, s0, c2Ptr);
|
|
395 |
c0 = quick_two_sum(c0, s0, c1Ptr);
|
|
396 |
|
|
397 |
s0 = c0;
|
|
398 |
s1 = *c1Ptr;
|
|
399 |
if (s1 != 0.0) {
|
|
400 |
s1 = quick_two_sum(s1, *c2Ptr, &s2);
|
|
401 |
if (s2 != 0.0)
|
|
402 |
s2 = quick_two_sum(s2, *c3Ptr, &s3);
|
|
403 |
else
|
|
404 |
s1 = quick_two_sum(s1, *c3Ptr, &s2);
|
|
405 |
} else {
|
|
406 |
s0 = quick_two_sum(s0, *c2Ptr, &s1);
|
|
407 |
if (s1 != 0.0)
|
|
408 |
s1 = quick_two_sum(s1, *c3Ptr, &s2);
|
|
409 |
else
|
|
410 |
s0 = quick_two_sum(s0, *c3Ptr, &s1);
|
|
411 |
}
|
|
412 |
|
|
413 |
*c0Ptr = s0;
|
|
414 |
*c1Ptr = s1;
|
|
415 |
*c2Ptr = s2;
|
|
416 |
*c3Ptr = s3;
|
|
417 |
}
|
|
418 |
|
|
419 |
inline void
|
|
420 |
renorm5(double *c0Ptr, double *c1Ptr, double *c2Ptr, double *c3Ptr, double *c4Ptr) {
|
|
421 |
double s0, s1, s2 = 0.0, s3 = 0.0;
|
|
422 |
|
|
423 |
if (isinf(*c0Ptr)) return;
|
|
424 |
|
|
425 |
s0 = quick_two_sum(*c3Ptr, *c4Ptr, c4Ptr);
|
|
426 |
s0 = quick_two_sum(*c2Ptr, s0, c3Ptr);
|
|
427 |
s0 = quick_two_sum(*c1Ptr, s0, c2Ptr);
|
|
428 |
*c0Ptr = quick_two_sum(*c0Ptr, s0, c1Ptr);
|
|
429 |
|
|
430 |
s0 = *c0Ptr;
|
|
431 |
s1 = *c1Ptr;
|
|
432 |
|
|
433 |
s0 = quick_two_sum(*c0Ptr, *c1Ptr, &s1);
|
|
434 |
if (s1 != 0.0) {
|
|
435 |
s1 = quick_two_sum(s1, *c2Ptr, &s2);
|
|
436 |
if (s2 != 0.0) {
|
|
437 |
s2 =quick_two_sum(s2, *c3Ptr, &s3);
|
|
438 |
if (s3 != 0.0)
|
|
439 |
s3 += *c4Ptr;
|
|
440 |
else
|
|
441 |
s2 += *c4Ptr;
|
|
442 |
} else {
|
|
443 |
s1 = quick_two_sum(s1, *c3Ptr, &s2);
|
|
444 |
if (s2 != 0.0)
|
|
445 |
s2 = quick_two_sum(s2, *c4Ptr, &s3);
|
|
446 |
else
|
|
447 |
s1 = quick_two_sum(s1, *c4Ptr, &s2);
|
|
448 |
}
|
|
449 |
} else {
|
|
450 |
s0 = quick_two_sum(s0, *c2Ptr, &s1);
|
|
451 |
if (s1 != 0.0) {
|
|
452 |
s1 = quick_two_sum(s1, *c3Ptr, &s2);
|
|
453 |
if (s2 != 0.0)
|
|
454 |
s2 = quick_two_sum(s2, *c4Ptr, &s3);
|
|
455 |
else
|
|
456 |
s1 = quick_two_sum(s1, *c4Ptr, &s2);
|
|
457 |
} else {
|
|
458 |
s0 = quick_two_sum(s0, *c3Ptr, &s1);
|
|
459 |
if (s1 != 0.0)
|
|
460 |
s1 = quick_two_sum(s1, *c4Ptr, &s2);
|
|
461 |
else
|
|
462 |
s0 = quick_two_sum(s0, *c4Ptr, &s1);
|
|
463 |
}
|
|
464 |
}
|
|
465 |
|
|
466 |
*c0Ptr = s0;
|
|
467 |
*c1Ptr = s1;
|
|
468 |
*c2Ptr = s2;
|
|
469 |
*c3Ptr = s3;
|
|
470 |
}
|
|
471 |
|
|
472 |
inline void
|
|
473 |
three_sum(double *aPtr, double *bPtr, double *cPtr) {
|
|
474 |
double t1, t2, t3;
|
|
475 |
t1 = two_sum(*aPtr, *bPtr, &t2);
|
|
476 |
*aPtr = two_sum(*cPtr, t1, &t3);
|
|
477 |
*bPtr = two_sum(t2, t3, cPtr);
|
|
478 |
}
|
|
479 |
|
|
480 |
inline void three_sum2(double *aPtr, double *bPtr, double *cPtr) {
|
|
481 |
double t1, t2, t3;
|
|
482 |
t1 = two_sum(*aPtr, *bPtr, &t2);
|
|
483 |
*aPtr = two_sum(*cPtr, t1, &t3);
|
|
484 |
*bPtr = t2 + t3;
|
|
485 |
}
|
|
486 |
|
|
487 |
|
|
488 |
#if 0
|
|
489 |
/* These are provided to give consistent
|
|
490 |
interface for double with double-double and quad-double. */
|
|
491 |
inline void
|
|
492 |
sincosh(double t, double &sinh_t, double &cosh_t) {
|
|
493 |
sinh_t = sinh(t);
|
|
494 |
cosh_t = cosh(t);
|
|
495 |
}
|
|
496 |
|
|
497 |
inline double
|
|
498 |
sqr(double t) {
|
|
499 |
return t * t;
|
|
500 |
}
|
|
501 |
|
|
502 |
inline double
|
|
503 |
to_double(double a) {
|
|
504 |
return a;
|
|
505 |
}
|
|
506 |
|
|
507 |
inline int
|
|
508 |
to_int(double a) {
|
|
509 |
return static_cast<int>(a);
|
|
510 |
}
|
|
511 |
#endif
|
|
512 |
|
|
513 |
%}
|
|
514 |
! !
|
|
515 |
|
|
516 |
!QDouble class methodsFor:'documentation'!
|
|
517 |
|
|
518 |
copyright
|
|
519 |
"
|
|
520 |
COPYRIGHT (c) 2017 by eXept Software AG
|
|
521 |
All Rights Reserved
|
|
522 |
|
|
523 |
This software is furnished under a license and may be used
|
|
524 |
only in accordance with the terms of that license and with the
|
|
525 |
inclusion of the above copyright notice. This software may not
|
|
526 |
be provided or otherwise made available to, or used by, any
|
|
527 |
other person. No title to or ownership of the software is
|
|
528 |
hereby transferred.
|
|
529 |
"
|
|
530 |
!
|
|
531 |
|
|
532 |
documentation
|
|
533 |
"
|
|
534 |
QDoubles represent rational numbers with extended, but still limited precision.
|
|
535 |
|
|
536 |
In contrast to Floats (which use the C-compilers native 64bit 'double' format),
|
|
537 |
QDoubles give you 212 bit or approx. 64 decimal digits of precision.
|
|
538 |
|
|
539 |
Representation:
|
|
540 |
QDoubles use 4 IEEE doubles, each keeping 53 bits of precision.
|
|
541 |
|
|
542 |
Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
|
|
543 |
|
|
544 |
[author:]
|
|
545 |
Claus Gittinger
|
|
546 |
|
|
547 |
[see also:]
|
|
548 |
Number
|
|
549 |
Float ShortFloat Fraction FixedPoint Integer Complex
|
|
550 |
FloatArray DoubleArray
|
|
551 |
"
|
|
552 |
! !
|
|
553 |
|
|
554 |
!QDouble class methodsFor:'instance creation'!
|
|
555 |
|
|
556 |
basicNew
|
|
557 |
"return a new quad-precision double - here we return 0.0
|
|
558 |
Notice that numbers are usually NOT created this way ...
|
|
559 |
It's implemented here to allow things like binary store & load
|
|
560 |
of floats. (but even this support will go away eventually, it's not
|
|
561 |
a good idea to store the bits of a float - the reader might have a
|
|
562 |
totally different representation - so floats should be
|
|
563 |
binary stored in a device independent format."
|
|
564 |
|
|
565 |
%{ /* NOCONTEXT */
|
|
566 |
#ifdef __SCHTEAM__
|
|
567 |
ERROR("trying to instantiate a quad double");
|
|
568 |
#else
|
|
569 |
OBJ newFloat;
|
|
570 |
printf("xxx\n");
|
|
571 |
__qNew(newFloat, sizeof(struct __quadDoubleStruct));
|
|
572 |
__stx_setClass(newFloat, QDouble);
|
|
573 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = 0.0;
|
|
574 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
|
|
575 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
|
|
576 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
|
|
577 |
RETURN (newFloat);
|
|
578 |
#endif /* not SCHTEAM */
|
|
579 |
%}
|
|
580 |
|
|
581 |
"
|
|
582 |
self basicNew
|
|
583 |
"
|
|
584 |
|
|
585 |
"Created: / 12-06-2017 / 16:00:38 / cg"
|
|
586 |
!
|
|
587 |
|
|
588 |
d0:d0 d1:d1 d2:d2 d3:d3
|
|
589 |
"return a new quad-precision double from individual double components"
|
|
590 |
|
|
591 |
%{ /* NOCONTEXT */
|
|
592 |
#ifdef __SCHTEAM__
|
|
593 |
ERROR("trying to instantiate a quad double");
|
|
594 |
#else
|
|
595 |
OBJ newQD;
|
|
596 |
|
|
597 |
if (__isFloatLike(d0)
|
|
598 |
&& __isFloatLike(d1)
|
|
599 |
&& __isFloatLike(d2)
|
|
600 |
&& __isFloatLike(d3)) {
|
|
601 |
__qNew_qdReal(newQD, __floatVal(d0), __floatVal(d1),
|
|
602 |
__floatVal(d2), __floatVal(d3));
|
|
603 |
RETURN (newQD);
|
|
604 |
}
|
|
605 |
#endif
|
|
606 |
%}.
|
|
607 |
self error:'invalid argument'
|
|
608 |
|
|
609 |
"
|
|
610 |
self d0: 3.141592653589793116e+00
|
|
611 |
d1: 1.224646799147353207e-16
|
|
612 |
d2: -2.994769809718339666e-33
|
|
613 |
d3: 1.112454220863365282e-49
|
|
614 |
"
|
|
615 |
|
|
616 |
"Created: / 12-06-2017 / 20:17:14 / cg"
|
|
617 |
!
|
|
618 |
|
|
619 |
fromDoubleArray:aDoubleArray
|
|
620 |
"return a new quad-precision double from coercing a double array"
|
|
621 |
|
|
622 |
%{ /* NOCONTEXT */
|
|
623 |
#ifdef __SCHTEAM__
|
|
624 |
ERROR("trying to instantiate a quad double");
|
|
625 |
#else
|
|
626 |
OBJ newQD;
|
|
627 |
|
|
628 |
if (__isDoubleArray(aDoubleArray)) {
|
|
629 |
__qNew_qdReal(newQD,
|
|
630 |
__DoubleArrayInstPtr(aDoubleArray)->d_element[0],
|
|
631 |
__DoubleArrayInstPtr(aDoubleArray)->d_element[1],
|
|
632 |
__DoubleArrayInstPtr(aDoubleArray)->d_element[2],
|
|
633 |
__DoubleArrayInstPtr(aDoubleArray)->d_element[3]);
|
|
634 |
RETURN (newQD);
|
|
635 |
}
|
|
636 |
#endif
|
|
637 |
%}.
|
|
638 |
self error:'invalid argument'
|
|
639 |
|
|
640 |
"
|
|
641 |
self fromDoubleArray(DoubleArray
|
|
642 |
with: 3.141592653589793116e+00
|
|
643 |
with: 1.224646799147353207e-16
|
|
644 |
with: -2.994769809718339666e-33
|
|
645 |
with: 1.112454220863365282e-49)
|
|
646 |
"
|
|
647 |
|
|
648 |
"Created: / 12-06-2017 / 18:25:32 / cg"
|
|
649 |
!
|
|
650 |
|
|
651 |
fromFloat:aFloat
|
|
652 |
"return a new quad-precision double from coercing aFloat"
|
|
653 |
|
|
654 |
%{ /* NOCONTEXT */
|
|
655 |
#ifdef __SCHTEAM__
|
|
656 |
ERROR("trying to instantiate a quad double");
|
|
657 |
#else
|
|
658 |
double dVal;
|
|
659 |
OBJ newFloat;
|
|
660 |
|
|
661 |
if (__isFloatLike(aFloat)) {
|
|
662 |
dVal = __floatVal(aFloat);
|
|
663 |
} else if (__isShortFloat(aFloat)) {
|
|
664 |
dVal = __shortFloatVal(aFloat);
|
|
665 |
} else {
|
|
666 |
goto badArg;
|
|
667 |
}
|
|
668 |
|
|
669 |
__qNew(newFloat, sizeof(struct __quadDoubleStruct));
|
|
670 |
__stx_setClass(newFloat, QDouble);
|
|
671 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = dVal;
|
|
672 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
|
|
673 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
|
|
674 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
|
|
675 |
RETURN (newFloat);
|
|
676 |
|
|
677 |
badArg: ;
|
|
678 |
|
|
679 |
#endif
|
|
680 |
%}.
|
|
681 |
self error:'invalid argument'
|
|
682 |
|
|
683 |
"
|
|
684 |
self fromFloat:1.0
|
|
685 |
"
|
|
686 |
|
|
687 |
"Created: / 12-06-2017 / 16:06:54 / cg"
|
|
688 |
!
|
|
689 |
|
|
690 |
fromInteger:anInteger
|
|
691 |
"return a new quad-precision double from coercing anInteger"
|
|
692 |
|
|
693 |
%{ /* NOCONTEXT */
|
|
694 |
#ifndef __SCHTEAM__
|
|
695 |
OBJ newFloat;
|
|
696 |
|
|
697 |
if (__isSmallInteger(anInteger)) {
|
|
698 |
__qNew(newFloat, sizeof(struct __quadDoubleStruct));
|
|
699 |
__stx_setClass(newFloat, QDouble);
|
|
700 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = (double)(__smallIntegerVal(anInteger));
|
|
701 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
|
|
702 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
|
|
703 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
|
|
704 |
RETURN (newFloat);
|
|
705 |
}
|
|
706 |
#endif
|
|
707 |
%}.
|
|
708 |
^ super fromInteger:anInteger
|
|
709 |
|
|
710 |
"
|
|
711 |
self fromInteger:2
|
|
712 |
"
|
|
713 |
|
|
714 |
"Created: / 12-06-2017 / 16:10:10 / cg"
|
|
715 |
! !
|
|
716 |
|
|
717 |
!QDouble class methodsFor:'constants'!
|
|
718 |
|
|
719 |
e
|
|
720 |
"return the constant e as quad precision double.
|
|
721 |
(returns approx. 212 bits of precision)"
|
|
722 |
|
|
723 |
E isNil ifTrue:[
|
|
724 |
E := self fromDoubleArray(DoubleArray
|
|
725 |
with: 2.718281828459045091e+00
|
|
726 |
with: 1.445646891729250158e-16
|
|
727 |
with: -2.127717108038176765e-33
|
|
728 |
with: 1.515630159841218954e-49)
|
|
729 |
].
|
|
730 |
^ E
|
|
731 |
|
|
732 |
"
|
|
733 |
self e
|
|
734 |
"
|
|
735 |
|
|
736 |
"Created: / 12-06-2017 / 18:29:36 / cg"
|
|
737 |
!
|
|
738 |
|
|
739 |
ln10
|
|
740 |
"return the constant e as quad precision double.
|
|
741 |
(returns approx. 212 bits of precision)"
|
|
742 |
|
|
743 |
Ln10 isNil ifTrue:[
|
|
744 |
Ln10 := self fromDoubleArray(DoubleArray
|
|
745 |
with: 2.302585092994045901e+00
|
|
746 |
with: -2.170756223382249351e-16
|
|
747 |
with: -9.984262454465776570e-33
|
|
748 |
with: -4.023357454450206379e-49)
|
|
749 |
].
|
|
750 |
^ Ln10
|
|
751 |
|
|
752 |
"
|
|
753 |
self ln10
|
|
754 |
"
|
|
755 |
|
|
756 |
"Created: / 12-06-2017 / 18:32:29 / cg"
|
|
757 |
!
|
|
758 |
|
|
759 |
ln2
|
|
760 |
"return the constant e as quad precision double.
|
|
761 |
(returns approx. 212 bits of precision)"
|
|
762 |
|
|
763 |
Ln2 isNil ifTrue:[
|
|
764 |
Ln2 := self fromDoubleArray(DoubleArray
|
|
765 |
with: 6.931471805599452862e-01
|
|
766 |
with: 2.319046813846299558e-17
|
|
767 |
with: 5.707708438416212066e-34
|
|
768 |
with: -3.582432210601811423e-50)
|
|
769 |
].
|
|
770 |
^ Ln2
|
|
771 |
|
|
772 |
"
|
|
773 |
self ln2
|
|
774 |
"
|
|
775 |
|
|
776 |
"Created: / 12-06-2017 / 18:31:34 / cg"
|
|
777 |
!
|
|
778 |
|
|
779 |
pi
|
|
780 |
"return the constant pi as quad precision double.
|
|
781 |
(returns approx. 212 bits of precision)"
|
|
782 |
|
|
783 |
Pi isNil ifTrue:[
|
|
784 |
Pi := self fromDoubleArray(DoubleArray
|
|
785 |
with: 3.141592653589793116e+00
|
|
786 |
with: 1.224646799147353207e-16
|
|
787 |
with: -2.994769809718339666e-33
|
|
788 |
with: 1.112454220863365282e-49)
|
|
789 |
].
|
|
790 |
^ Pi
|
|
791 |
|
|
792 |
"
|
|
793 |
self pi
|
|
794 |
"
|
|
795 |
|
|
796 |
"Created: / 12-06-2017 / 18:27:13 / cg"
|
|
797 |
! !
|
|
798 |
|
|
799 |
!QDouble class methodsFor:'queries'!
|
|
800 |
|
|
801 |
epsilon
|
|
802 |
"return the maximum relative spacing of instances of mySelf
|
|
803 |
(i.e. the value-delta of the least significant bit)"
|
|
804 |
|
|
805 |
^ Float epsilon
|
|
806 |
|
|
807 |
"
|
|
808 |
Float epsilon
|
|
809 |
ShortFloat epsilon
|
|
810 |
QDouble epsilon
|
|
811 |
"
|
|
812 |
|
|
813 |
"Created: / 12-06-2017 / 18:52:44 / cg"
|
|
814 |
!
|
|
815 |
|
|
816 |
numBitsInExponent
|
|
817 |
"answer the number of bits in the exponent"
|
|
818 |
|
|
819 |
^ Float numBitsInExponent
|
|
820 |
|
|
821 |
"
|
|
822 |
1.0 asQDouble class numBitsInExponent
|
|
823 |
"
|
|
824 |
|
|
825 |
"Created: / 12-06-2017 / 11:11:04 / cg"
|
|
826 |
!
|
|
827 |
|
|
828 |
numBitsInMantissa
|
|
829 |
"answer the number of bits in the mantissa"
|
|
830 |
|
|
831 |
^ Float precision * 4
|
|
832 |
|
|
833 |
"
|
|
834 |
1.0 class numBitsInMantissa
|
|
835 |
1.0 asShortFloat class numBitsInMantissa
|
|
836 |
1.0 asLongFloat class numBitsInMantissa
|
|
837 |
1.0 asDDouble class numBitsInMantissa
|
|
838 |
1.0 asQDouble class numBitsInMantissa
|
|
839 |
|
|
840 |
Float numBitsInMantissa
|
|
841 |
ShortFloat numBitsInMantissa
|
|
842 |
QDouble numBitsInMantissa
|
|
843 |
"
|
|
844 |
|
|
845 |
"Created: / 12-06-2017 / 11:13:44 / cg"
|
|
846 |
"Modified: / 12-06-2017 / 18:48:48 / cg"
|
|
847 |
!
|
|
848 |
|
|
849 |
precision
|
|
850 |
"answer the number of bits in the mantissa"
|
|
851 |
|
|
852 |
^ Float precision * 4
|
|
853 |
|
|
854 |
"
|
|
855 |
1.0 class numBitsInMantissa
|
|
856 |
1.0 asShortFloat class numBitsInMantissa
|
|
857 |
1.0 asLongFloat class numBitsInMantissa
|
|
858 |
1.0 asDDouble class numBitsInMantissa
|
|
859 |
1.0 asQDouble class numBitsInMantissa
|
|
860 |
|
|
861 |
Float numBitsInMantissa
|
|
862 |
ShortFloat numBitsInMantissa
|
|
863 |
QDouble numBitsInMantissa
|
|
864 |
QDouble precision
|
|
865 |
"
|
|
866 |
|
|
867 |
"Created: / 12-06-2017 / 18:49:11 / cg"
|
|
868 |
!
|
|
869 |
|
|
870 |
radix
|
|
871 |
"answer the radix of a Floats exponent
|
|
872 |
This is an IEEE float, which is represented as binary"
|
|
873 |
|
|
874 |
^ Float radix
|
|
875 |
|
|
876 |
"Created: / 12-06-2017 / 18:50:04 / cg"
|
|
877 |
! !
|
|
878 |
|
|
879 |
!QDouble methodsFor:'arithmetic'!
|
|
880 |
|
|
881 |
* aNumber
|
|
882 |
"return the product of the receiver and the argument, aNumber"
|
|
883 |
|
|
884 |
^ aNumber productFromQDouble:self
|
|
885 |
|
|
886 |
"
|
|
887 |
((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) asDoubleArray
|
|
888 |
"
|
|
889 |
|
|
890 |
"Created: / 13-06-2017 / 01:00:47 / cg"
|
|
891 |
!
|
|
892 |
|
|
893 |
+ aNumber
|
|
894 |
"return the sum of the receiver and the argument, aNumber"
|
|
895 |
|
|
896 |
^ aNumber sumFromQDouble:self
|
|
897 |
|
|
898 |
"
|
|
899 |
((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) asDoubleArray
|
|
900 |
"
|
|
901 |
|
|
902 |
"Created: / 12-06-2017 / 16:17:46 / cg"
|
|
903 |
"Modified: / 12-06-2017 / 23:06:22 / cg"
|
|
904 |
!
|
|
905 |
|
|
906 |
- aNumber
|
|
907 |
"return the sum of the receiver and the argument, aNumber"
|
|
908 |
|
|
909 |
^ (aNumber negated) sumFromQDouble:self
|
|
910 |
|
|
911 |
"
|
|
912 |
(QDouble fromFloat:1e20) asDoubleArray
|
|
913 |
((QDouble fromFloat:1e20) - (QDouble fromFloat:1.0)) asDoubleArray
|
|
914 |
(QDouble fromFloat:1e-20) asDoubleArray
|
|
915 |
((QDouble fromFloat:1e-20) - (QDouble fromFloat:1.0)) asDoubleArray
|
|
916 |
((QDouble fromFloat:2.0) - (QDouble fromFloat:1.0)) asDoubleArray
|
|
917 |
"
|
|
918 |
|
|
919 |
"Created: / 12-06-2017 / 23:41:39 / cg"
|
4386
|
920 |
!
|
|
921 |
|
|
922 |
/ aNumber
|
|
923 |
"return the quotient of the receiver and the argument, aNumber"
|
|
924 |
|
|
925 |
^ aNumber quotientFromQDouble:self
|
|
926 |
|
|
927 |
"
|
|
928 |
((QDouble fromFloat:1e20) / (QDouble fromFloat:2.0)) asDoubleArray
|
|
929 |
"
|
|
930 |
|
|
931 |
"Created: / 13-06-2017 / 17:59:09 / cg"
|
4380
|
932 |
! !
|
|
933 |
|
|
934 |
!QDouble methodsFor:'coercing & converting'!
|
|
935 |
|
|
936 |
asDoubleArray
|
4386
|
937 |
^ DoubleArray
|
|
938 |
with:self d0
|
|
939 |
with:self d1
|
|
940 |
with:self d2
|
|
941 |
with:self d3.
|
4380
|
942 |
|
|
943 |
"
|
4386
|
944 |
(QDouble fromFloat:1.0) asDoubleArray
|
|
945 |
(QDouble fromFloat:2.0) asDoubleArray
|
4380
|
946 |
"
|
|
947 |
|
|
948 |
"Created: / 12-06-2017 / 18:19:19 / cg"
|
4386
|
949 |
"Modified (comment): / 13-06-2017 / 17:58:09 / cg"
|
4380
|
950 |
!
|
|
951 |
|
|
952 |
asFloat
|
4386
|
953 |
^ self d0
|
4380
|
954 |
|
|
955 |
"
|
|
956 |
(QDouble fromFloat:1.0) asFloat
|
|
957 |
(QDouble fromFloat:2.0) asFloat
|
|
958 |
"
|
|
959 |
|
|
960 |
"Created: / 12-06-2017 / 18:15:27 / cg"
|
4386
|
961 |
"Modified: / 13-06-2017 / 17:56:50 / cg"
|
4380
|
962 |
!
|
|
963 |
|
|
964 |
coerce:aNumber
|
|
965 |
"convert the argument aNumber into an instance of the receiver's class and return it."
|
|
966 |
|
|
967 |
^ aNumber asQDouble
|
|
968 |
|
|
969 |
"Created: / 12-06-2017 / 17:13:47 / cg"
|
|
970 |
"Modified: / 12-06-2017 / 21:09:06 / cg"
|
|
971 |
!
|
|
972 |
|
|
973 |
generality
|
|
974 |
"return the generality value - see ArithmeticValue>>retry:coercing:"
|
|
975 |
|
|
976 |
^ 95
|
|
977 |
|
|
978 |
"Created: / 12-06-2017 / 17:13:14 / cg"
|
|
979 |
!
|
|
980 |
|
|
981 |
negative
|
4386
|
982 |
^ self d0 negative
|
4380
|
983 |
|
|
984 |
"
|
|
985 |
(QDouble fromFloat:0.0) negative
|
|
986 |
(QDouble fromFloat:1.0) negative
|
|
987 |
(QDouble fromFloat:-1.0) negative
|
|
988 |
"
|
|
989 |
|
|
990 |
"Created: / 13-06-2017 / 01:57:39 / cg"
|
4386
|
991 |
"Modified: / 13-06-2017 / 17:58:26 / cg"
|
4380
|
992 |
!
|
|
993 |
|
|
994 |
positive
|
4386
|
995 |
^ self d0 positive
|
4380
|
996 |
|
|
997 |
"
|
|
998 |
(QDouble fromFloat:1.0) positive
|
|
999 |
(QDouble fromFloat:-1.0) positive
|
|
1000 |
"
|
|
1001 |
|
|
1002 |
"Created: / 13-06-2017 / 01:56:53 / cg"
|
4386
|
1003 |
"Modified: / 13-06-2017 / 17:58:41 / cg"
|
4380
|
1004 |
! !
|
|
1005 |
|
4385
|
1006 |
!QDouble methodsFor:'comparing'!
|
|
1007 |
|
|
1008 |
< aNumber
|
|
1009 |
"return true, if the argument, aNumber is greater than the receiver"
|
|
1010 |
|
|
1011 |
^ aNumber lessFromQDouble:self
|
|
1012 |
|
|
1013 |
"Created: / 13-06-2017 / 16:58:53 / cg"
|
|
1014 |
!
|
|
1015 |
|
|
1016 |
= aNumber
|
|
1017 |
"return true, if the argument, aNumber has the same value as than the receiver"
|
|
1018 |
|
|
1019 |
^ aNumber equalFromQDouble:self
|
|
1020 |
|
|
1021 |
"Created: / 13-06-2017 / 17:12:09 / cg"
|
|
1022 |
! !
|
|
1023 |
|
4380
|
1024 |
!QDouble methodsFor:'double dispatching'!
|
|
1025 |
|
|
1026 |
differenceFromFloat:aFloat
|
|
1027 |
"aFloat - self"
|
|
1028 |
|
|
1029 |
^ aFloat + (self negated)
|
|
1030 |
|
|
1031 |
"
|
|
1032 |
1.0 - (QDouble fromFloat:1.0)
|
|
1033 |
1e20 - (QDouble fromFloat:1.0)
|
|
1034 |
(1.0 - (QDouble fromFloat:1.0)) asFloat
|
|
1035 |
(1e20 - (QDouble fromFloat:1.0)) asFloat
|
|
1036 |
|
|
1037 |
(1.0 - (QDouble fromFloat:1.0)) asDoubleArray
|
|
1038 |
(1e20 - (QDouble fromFloat:1.0)) asDoubleArray
|
|
1039 |
(1e20 - (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
|
|
1040 |
"
|
|
1041 |
|
|
1042 |
"Created: / 12-06-2017 / 23:38:05 / cg"
|
|
1043 |
!
|
|
1044 |
|
|
1045 |
differenceFromQDouble:aQDouble
|
|
1046 |
"aQDouble - self"
|
|
1047 |
|
|
1048 |
^ aQDouble + (self negated)
|
|
1049 |
|
|
1050 |
"
|
|
1051 |
1.0 - (QDouble fromFloat:1.0)
|
|
1052 |
1e20 - (QDouble fromFloat:1.0)
|
|
1053 |
(1.0 - (QDouble fromFloat:1.0)) asFloat
|
|
1054 |
(1e20 - (QDouble fromFloat:1.0)) asFloat
|
|
1055 |
|
|
1056 |
(1.0 - (QDouble fromFloat:1.0)) asDoubleArray
|
|
1057 |
(1e20 - (QDouble fromFloat:1.0)) asDoubleArray
|
|
1058 |
(1e20 - (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
|
|
1059 |
"
|
|
1060 |
|
|
1061 |
"Created: / 12-06-2017 / 23:38:19 / cg"
|
|
1062 |
!
|
|
1063 |
|
|
1064 |
equalFromQDouble:aQDouble
|
|
1065 |
%{
|
|
1066 |
if (__Class(aQDouble) == QDouble) {
|
|
1067 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1068 |
double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
|
|
1069 |
|
|
1070 |
RETURN ((a[0] == b[0]
|
|
1071 |
&& a[1] == b[1]
|
|
1072 |
&& a[2] == b[2]
|
|
1073 |
&& a[3] == b[3]) ? true : false);
|
|
1074 |
}
|
|
1075 |
%}.
|
4386
|
1076 |
^ (aQDouble d0 = self d0)
|
|
1077 |
and:[ (aQDouble d1 = self d1)
|
|
1078 |
and:[ (aQDouble d2 = self d2)
|
|
1079 |
and:[ (aQDouble d3 = self d3) ]]]
|
4380
|
1080 |
|
|
1081 |
"
|
|
1082 |
(QDouble fromFloat:1.0) = (QDouble fromFloat:1.0)
|
|
1083 |
(QDouble fromFloat:1.0) = 1.0
|
|
1084 |
1.0 = (QDouble fromFloat:1.0)
|
|
1085 |
"
|
|
1086 |
|
|
1087 |
"Created: / 13-06-2017 / 03:01:19 / cg"
|
4386
|
1088 |
"Modified: / 13-06-2017 / 18:01:52 / cg"
|
4380
|
1089 |
!
|
|
1090 |
|
4385
|
1091 |
lessFromQDouble:aQDouble
|
|
1092 |
"sent when aQDouble does not know how to compare to the receiver..
|
|
1093 |
Return true if aQDouble < self"
|
4380
|
1094 |
|
4385
|
1095 |
%{
|
|
1096 |
if (__Class(aQDouble) == QDouble) {
|
|
1097 |
double *a = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
|
|
1098 |
double *b = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
4380
|
1099 |
|
4385
|
1100 |
// now compare if a < b!
|
|
1101 |
RETURN
|
|
1102 |
((a[0] < b[0] ||
|
|
1103 |
(a[0] == b[0] && (a[1] < b[1] ||
|
|
1104 |
(a[1] == b[1] && (a[2] < b[2] ||
|
|
1105 |
(a[2] == b[2] && a[3] < b[3])))))) ? true : false);
|
4380
|
1106 |
}
|
|
1107 |
%}.
|
4385
|
1108 |
^ super lessFromQDouble:aQDouble
|
4380
|
1109 |
|
|
1110 |
"
|
4385
|
1111 |
(1.0 + 1e-40) > 1.0
|
|
1112 |
((QDouble fromFloat:1.0) + (QDouble fromFloat:1e-40)) > (QDouble fromFloat:1.0)
|
4380
|
1113 |
|
4385
|
1114 |
(QDouble fromFloat:1.0) > (QDouble fromFloat:1.0)
|
|
1115 |
(QDouble fromFloat:1.1) > (QDouble fromFloat:1.0)
|
|
1116 |
(QDouble fromFloat:1.0) > 1.0
|
|
1117 |
(QDouble fromFloat:1.1) > 1.0
|
|
1118 |
1.0 > (QDouble fromFloat:1.0)
|
|
1119 |
"
|
|
1120 |
|
|
1121 |
"Created: / 13-06-2017 / 17:07:47 / cg"
|
4380
|
1122 |
!
|
|
1123 |
|
|
1124 |
productFromFloat:aFloat
|
|
1125 |
%{
|
|
1126 |
if (__isFloatLike(aFloat)) {
|
|
1127 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1128 |
double b = __floatVal(aFloat);
|
|
1129 |
double p0, p1, p2, p3;
|
|
1130 |
double q0, q1, q2;
|
|
1131 |
double s0, s1, s2, s3, s4;
|
|
1132 |
OBJ newQD;
|
|
1133 |
|
|
1134 |
m_two_prod(p0, a[0], b, q0);
|
|
1135 |
m_two_prod(p1, a[1], b, q1);
|
|
1136 |
m_two_prod(p2, a[2], b, q2);
|
|
1137 |
p3 = a[3] * b;
|
|
1138 |
|
|
1139 |
s0 = p0;
|
|
1140 |
|
|
1141 |
m_two_sum(s1, q0, p1, s2);
|
|
1142 |
|
|
1143 |
m_three_sum(s2, q1, p2);
|
|
1144 |
|
|
1145 |
m_three_sum2(q1, q2, p3);
|
|
1146 |
s3 = q1;
|
|
1147 |
|
|
1148 |
s4 = q2 + p2;
|
|
1149 |
|
|
1150 |
m_renorm5(s0, s1, s2, s3, s4);
|
|
1151 |
__qNew_qdReal(newQD, s0, s1, s2, s3);
|
|
1152 |
RETURN( newQD );
|
|
1153 |
}
|
|
1154 |
%}.
|
|
1155 |
^ super productFromFloat:aFloat.
|
|
1156 |
|
|
1157 |
"
|
|
1158 |
2.0 * (QDouble fromFloat:1.0)
|
|
1159 |
1e20 * (QDouble fromFloat:1.0)
|
|
1160 |
(2.0 * (QDouble fromFloat:1.0)) asFloat
|
|
1161 |
(1e20 * (QDouble fromFloat:1.0)) asFloat
|
|
1162 |
|
|
1163 |
(1e20 * (QDouble fromFloat:1.0) * 1e-20) asDoubleArray
|
|
1164 |
"
|
|
1165 |
|
|
1166 |
"Created: / 13-06-2017 / 00:58:56 / cg"
|
|
1167 |
!
|
|
1168 |
|
|
1169 |
productFromQDouble:aQDouble
|
|
1170 |
%{
|
|
1171 |
if (__Class(aQDouble) == QDouble) {
|
|
1172 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1173 |
double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
|
|
1174 |
OBJ newQD;
|
|
1175 |
// sloppy
|
|
1176 |
double p0, p1, p2, p3, p4, p5;
|
|
1177 |
double q0, q1, q2, q3, q4, q5;
|
|
1178 |
double t0, t1;
|
|
1179 |
double s0, s1, s2;
|
|
1180 |
|
|
1181 |
m_two_prod(p0, a[0], b[0], q0);
|
|
1182 |
|
|
1183 |
m_two_prod(p1, a[0], b[1], q1);
|
|
1184 |
m_two_prod(p2, a[1], b[0], q2);
|
|
1185 |
|
|
1186 |
m_two_prod(p3, a[0], b[2], q3);
|
|
1187 |
m_two_prod(p4, a[1], b[1], q4);
|
|
1188 |
m_two_prod(p5, a[2], b[0], q5);
|
|
1189 |
|
|
1190 |
/* Start Accumulation */
|
|
1191 |
m_three_sum(p1, p2, q0);
|
|
1192 |
|
|
1193 |
/* Six-Three Sum of p2, q1, q2, p3, p4, p5. */
|
|
1194 |
m_three_sum(p2, q1, q2);
|
|
1195 |
m_three_sum(p3, p4, p5);
|
|
1196 |
/* compute (s0, s1, s2) = (p2, q1, q2) + (p3, p4, p5). */
|
|
1197 |
m_two_sum(s0, p2, p3, t0);
|
|
1198 |
m_two_sum(s1, q1, p4, t1);
|
|
1199 |
s2 = q2 + p5;
|
|
1200 |
m_two_sum(s1, s1, t0, t0);
|
|
1201 |
s2 += (t0 + t1);
|
|
1202 |
|
|
1203 |
/* O(eps^3) order terms */
|
|
1204 |
s1 += a[0]*b[3] + a[1]*b[2] + a[2]*b[1] + a[3]*b[0] + q0 + q3 + q4 + q5;
|
|
1205 |
m_renorm5(p0, p1, s0, s1, s2);
|
|
1206 |
|
|
1207 |
__qNew_qdReal(newQD, p0, p1, s0, s1);
|
|
1208 |
RETURN( newQD );
|
|
1209 |
}
|
|
1210 |
%}.
|
|
1211 |
^ super productFromQDouble:aQDouble.
|
|
1212 |
|
|
1213 |
"
|
|
1214 |
2.0 * (QDouble fromFloat:1.0)
|
|
1215 |
1e20 * (QDouble fromFloat:1.0)
|
|
1216 |
(2.0 * (QDouble fromFloat:1.0)) asFloat
|
|
1217 |
(1e20 * (QDouble fromFloat:1.0)) asFloat
|
|
1218 |
|
|
1219 |
(1e20 * (QDouble fromFloat:1.0) * 1e-20) asDoubleArray
|
|
1220 |
"
|
|
1221 |
|
|
1222 |
"Created: / 13-06-2017 / 01:06:22 / cg"
|
|
1223 |
!
|
|
1224 |
|
4385
|
1225 |
quotientFromQDouble:aQDouble
|
4386
|
1226 |
"sloppy"
|
|
1227 |
|
4385
|
1228 |
|q0 q1 q2 q3 r|
|
|
1229 |
|
|
1230 |
q0 := self d0 / aQDouble d0.
|
|
1231 |
r := self - (aQDouble * q0).
|
|
1232 |
|
|
1233 |
q1 := r d0 / aQDouble d0.
|
|
1234 |
r := r - (aQDouble * q1).
|
4380
|
1235 |
|
4385
|
1236 |
q2 := r d0 / aQDouble d0.
|
|
1237 |
r := r - (aQDouble * q2).
|
4380
|
1238 |
|
4385
|
1239 |
q3 := r d0 / aQDouble d0.
|
4386
|
1240 |
|
|
1241 |
r := self class d0:q0 d1:q1 d2:q2 d3:q3.
|
|
1242 |
r renorm.
|
|
1243 |
^ r
|
4380
|
1244 |
|
|
1245 |
"
|
4385
|
1246 |
2.0 / (QDouble fromFloat:2.0)
|
|
1247 |
1e20 / (QDouble fromFloat:1.0)
|
|
1248 |
(2.0 / (QDouble fromFloat:1.0)) asFloat
|
|
1249 |
(1e20 / (QDouble fromFloat:1.0)) asFloat
|
|
1250 |
|
|
1251 |
(QDouble fromFloat:2.0) / 2.0
|
|
1252 |
(QDouble fromFloat:1e20) / 2.0
|
|
1253 |
((QDouble fromFloat:1.0) / 2.0) asFloat
|
|
1254 |
((QDouble fromFloat:1e20 / 2.0)) asFloat
|
|
1255 |
|
|
1256 |
((1e20 + (QDouble fromFloat:1.0) + 1e-20) / 2.0) asDoubleArray
|
4380
|
1257 |
"
|
|
1258 |
|
4385
|
1259 |
"Created: / 13-06-2017 / 17:50:35 / cg"
|
4380
|
1260 |
!
|
|
1261 |
|
|
1262 |
sumFromFloat:aFloat
|
|
1263 |
%{
|
|
1264 |
if (__isFloatLike(aFloat)) {
|
|
1265 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1266 |
double b = __floatVal(aFloat);
|
|
1267 |
double c0, c1, c2, c3;
|
|
1268 |
double e;
|
|
1269 |
OBJ newQD;
|
|
1270 |
|
|
1271 |
m_two_sum(c0, a[0], b, e);
|
|
1272 |
m_two_sum(c1 ,a[1], e, e);
|
|
1273 |
m_two_sum(c2, a[2], e, e);
|
|
1274 |
m_two_sum(c3, a[3], e, e);
|
|
1275 |
|
|
1276 |
m_renorm5(c0, c1, c2, c3, e);
|
|
1277 |
__qNew_qdReal(newQD, c0, c1, c2, c3);
|
|
1278 |
RETURN( newQD );
|
|
1279 |
}
|
|
1280 |
%}.
|
|
1281 |
^ super sumFromFloat:aFloat.
|
|
1282 |
|
|
1283 |
"
|
|
1284 |
1.0 + (QDouble fromFloat:1.0)
|
|
1285 |
1e20 + (QDouble fromFloat:1.0)
|
|
1286 |
(1.0 + (QDouble fromFloat:1.0)) asFloat
|
|
1287 |
(1e20 + (QDouble fromFloat:1.0)) asFloat
|
|
1288 |
|
|
1289 |
(1.0 + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1290 |
(1e20 + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1291 |
(1e20 + (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
|
|
1292 |
"
|
|
1293 |
|
|
1294 |
"Created: / 12-06-2017 / 17:16:41 / cg"
|
|
1295 |
"Modified: / 12-06-2017 / 22:57:03 / cg"
|
|
1296 |
!
|
|
1297 |
|
|
1298 |
sumFromQDouble:aQDouble
|
|
1299 |
%{
|
|
1300 |
if (__Class(aQDouble) == QDouble) {
|
|
1301 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1302 |
double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
|
|
1303 |
OBJ newQD;
|
|
1304 |
|
|
1305 |
#ifndef QD_IEEE_ADD
|
|
1306 |
// sloppy_add...
|
|
1307 |
|
|
1308 |
/*
|
|
1309 |
double s0, s1, s2, s3;
|
|
1310 |
double t0, t1, t2, t3;
|
|
1311 |
|
|
1312 |
m_two_sum(s0, a[0], b[0], t0);
|
|
1313 |
m_two_sum(s1, a[1], b[1], t1);
|
|
1314 |
m_two_sum(s2, a[2], b[2], t2);
|
|
1315 |
m_two_sum(s3, a[3], b[3], t3);
|
|
1316 |
|
|
1317 |
m_two_sum(s1, s1, t0, t0);
|
|
1318 |
m_three_sum(s2, t0, t1);
|
|
1319 |
m_three_sum2(s3, t0, t2);
|
|
1320 |
t0 = t0 + t1 + t3;
|
|
1321 |
|
|
1322 |
m_renorm5(s0, s1, s2, s3, t0);
|
|
1323 |
return qd_real(s0, s1, s2, s3, t0);
|
|
1324 |
*/
|
|
1325 |
|
|
1326 |
/* Same as above, but addition re-organized to minimize
|
|
1327 |
data dependency ... unfortunately some compilers are
|
|
1328 |
not very smart to do this automatically */
|
|
1329 |
double s0, s1, s2, s3;
|
|
1330 |
double t0, t1, t2, t3;
|
|
1331 |
|
|
1332 |
double v0, v1, v2, v3;
|
|
1333 |
double u0, u1, u2, u3;
|
|
1334 |
double w0, w1, w2, w3;
|
|
1335 |
|
|
1336 |
s0 = a[0] + b[0];
|
|
1337 |
s1 = a[1] + b[1];
|
|
1338 |
s2 = a[2] + b[2];
|
|
1339 |
s3 = a[3] + b[3];
|
|
1340 |
|
|
1341 |
v0 = s0 - a[0];
|
|
1342 |
v1 = s1 - a[1];
|
|
1343 |
v2 = s2 - a[2];
|
|
1344 |
v3 = s3 - a[3];
|
|
1345 |
|
|
1346 |
u0 = s0 - v0;
|
|
1347 |
u1 = s1 - v1;
|
|
1348 |
u2 = s2 - v2;
|
|
1349 |
u3 = s3 - v3;
|
|
1350 |
|
|
1351 |
w0 = a[0] - u0;
|
|
1352 |
w1 = a[1] - u1;
|
|
1353 |
w2 = a[2] - u2;
|
|
1354 |
w3 = a[3] - u3;
|
|
1355 |
|
|
1356 |
u0 = b[0] - v0;
|
|
1357 |
u1 = b[1] - v1;
|
|
1358 |
u2 = b[2] - v2;
|
|
1359 |
u3 = b[3] - v3;
|
|
1360 |
|
|
1361 |
t0 = w0 + u0;
|
|
1362 |
t1 = w1 + u1;
|
|
1363 |
t2 = w2 + u2;
|
|
1364 |
t3 = w3 + u3;
|
|
1365 |
|
|
1366 |
m_two_sum(s1, s1, t0, t0);
|
|
1367 |
m_three_sum(s2, t0, t1);
|
|
1368 |
m_three_sum2(s3, t0, t2);
|
|
1369 |
t0 = t0 + t1 + t3;
|
|
1370 |
|
|
1371 |
/* renormalize */
|
|
1372 |
m_renorm5(s0, s1, s2, s3, t0);
|
|
1373 |
__qNew_qdReal(newQD, s0, s1, s2, s3);
|
|
1374 |
RETURN(newQD);
|
|
1375 |
#else
|
|
1376 |
// ieee_add...
|
|
1377 |
int i, j, k;
|
|
1378 |
double s, t;
|
|
1379 |
double u, v; /* double-length accumulator */
|
|
1380 |
double x[4] = {0.0, 0.0, 0.0, 0.0};
|
|
1381 |
|
|
1382 |
i = j = k = 0;
|
|
1383 |
if (abs(a[i]) > abs(b[j]))
|
|
1384 |
u = a[i++];
|
|
1385 |
else
|
|
1386 |
u = b[j++];
|
|
1387 |
if (abs(a[i]) > abs(b[j]))
|
|
1388 |
v = a[i++];
|
|
1389 |
else
|
|
1390 |
v = b[j++];
|
|
1391 |
|
|
1392 |
u = quick_two_sum(u, v, v);
|
|
1393 |
|
|
1394 |
while (k < 4) {
|
|
1395 |
if (i >= 4 && j >= 4) {
|
|
1396 |
x[k] = u;
|
|
1397 |
if (k < 3)
|
|
1398 |
x[++k] = v;
|
|
1399 |
break;
|
|
1400 |
}
|
|
1401 |
|
|
1402 |
if (i >= 4)
|
|
1403 |
t = b[j++];
|
|
1404 |
else if (j >= 4)
|
|
1405 |
t = a[i++];
|
|
1406 |
else if (abs(a[i]) > abs(b[j])) {
|
|
1407 |
t = a[i++];
|
|
1408 |
} else
|
|
1409 |
t = b[j++];
|
|
1410 |
|
|
1411 |
s = quick_three_accum(u, v, t);
|
|
1412 |
|
|
1413 |
if (s != 0.0) {
|
|
1414 |
x[k++] = s;
|
|
1415 |
}
|
|
1416 |
}
|
|
1417 |
|
|
1418 |
/* add the rest. */
|
|
1419 |
for (k = i; k < 4; k++)
|
|
1420 |
x[3] += a[k];
|
|
1421 |
for (k = j; k < 4; k++)
|
|
1422 |
x[3] += b[k];
|
|
1423 |
|
|
1424 |
m_renorm4(x[0], x[1], x[2], x[3]);
|
|
1425 |
__qNew_qdReal(newQD, x[0], x[1], x[2], x[3]);
|
|
1426 |
RETURN(newQD);
|
|
1427 |
#endif
|
|
1428 |
}
|
|
1429 |
%}.
|
|
1430 |
^ super sumFromQDouble:aQDouble
|
|
1431 |
|
|
1432 |
"
|
|
1433 |
(QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)
|
|
1434 |
(QDouble fromFloat:1.0) + 1.0
|
|
1435 |
1.0 + (QDouble fromFloat:1.0)
|
|
1436 |
|
|
1437 |
((QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1438 |
((QDouble fromFloat:1.0) + 1.0) asDoubleArray
|
|
1439 |
(1.0 + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1440 |
(1e-20 + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1441 |
(1e20 + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1442 |
"
|
|
1443 |
|
|
1444 |
"Created: / 12-06-2017 / 21:15:43 / cg"
|
|
1445 |
"Modified: / 13-06-2017 / 00:30:45 / cg"
|
|
1446 |
! !
|
|
1447 |
|
|
1448 |
!QDouble methodsFor:'inspecting'!
|
|
1449 |
|
|
1450 |
inspectorExtraAttributes
|
|
1451 |
"extra (pseudo instvar) entries to be shown in an inspector."
|
|
1452 |
|
|
1453 |
^ super inspectorExtraAttributes
|
|
1454 |
add:'-{doubles}' ->
|
|
1455 |
[
|
|
1456 |
self asDoubleArray printString
|
|
1457 |
];
|
|
1458 |
yourself
|
|
1459 |
|
|
1460 |
"Created: / 12-06-2017 / 23:43:05 / cg"
|
|
1461 |
! !
|
|
1462 |
|
4385
|
1463 |
!QDouble methodsFor:'mathematical functions'!
|
|
1464 |
|
|
1465 |
floor
|
|
1466 |
"return the receiver truncated towards negative infinity"
|
|
1467 |
|
|
1468 |
%{
|
|
1469 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1470 |
OBJ newQD;
|
|
1471 |
|
|
1472 |
double x0, x1, x2, x3;
|
|
1473 |
x1 = x2 = x3 = 0.0;
|
|
1474 |
x0 =floor(a[0]);
|
|
1475 |
|
|
1476 |
if (x0 == a[0]) {
|
|
1477 |
x1 = floor(a[1]);
|
|
1478 |
|
|
1479 |
if (x1 == a[1]) {
|
|
1480 |
x2 = floor(a[2]);
|
|
1481 |
|
|
1482 |
if (x2 == a[2]) {
|
|
1483 |
x3 = floor(a[3]);
|
|
1484 |
}
|
|
1485 |
}
|
|
1486 |
|
|
1487 |
m_renorm4(x0, x1, x2, x3);
|
|
1488 |
__qNew_qdReal(newQD, x0, x1, x2, x3);
|
|
1489 |
RETURN( newQD );
|
|
1490 |
}
|
|
1491 |
|
|
1492 |
__qNew_qdReal(newQD, x0, x1, x2, x3);
|
|
1493 |
RETURN( newQD );
|
|
1494 |
%}.
|
|
1495 |
|
|
1496 |
"
|
|
1497 |
(QDouble fromFloat:4.0) floor
|
|
1498 |
(QDouble fromFloat:4.1) floor
|
|
1499 |
(QDouble fromFloat:0.1) floor
|
|
1500 |
(0.1 + (QDouble fromFloat:1.0)) floor
|
|
1501 |
(1e20 + (QDouble fromFloat:1.0)) floor
|
|
1502 |
|
|
1503 |
(QDouble fromFloat:1.5) floor
|
|
1504 |
(QDouble fromFloat:0.5) floor
|
|
1505 |
(QDouble fromFloat:-0.5) floor
|
|
1506 |
(QDouble fromFloat:-1.5) floor
|
|
1507 |
"
|
|
1508 |
|
|
1509 |
"Created: / 13-06-2017 / 01:52:44 / cg"
|
|
1510 |
"Modified (comment): / 13-06-2017 / 17:33:19 / cg"
|
|
1511 |
!
|
|
1512 |
|
|
1513 |
negated
|
|
1514 |
^ self class
|
|
1515 |
d0:(self d0) negated
|
|
1516 |
d1:(self d1) negated
|
|
1517 |
d2:(self d2) negated
|
|
1518 |
d3:(self d3) negated
|
|
1519 |
|
|
1520 |
"
|
|
1521 |
(QDouble fromFloat:1.0) negated
|
|
1522 |
((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) negated asDoubleArray
|
|
1523 |
|
|
1524 |
(((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))
|
|
1525 |
+ ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))) asDoubleArray
|
|
1526 |
"
|
|
1527 |
|
|
1528 |
"Created: / 12-06-2017 / 20:14:55 / cg"
|
|
1529 |
"Modified (comment): / 12-06-2017 / 23:46:57 / cg"
|
|
1530 |
!
|
|
1531 |
|
|
1532 |
squared
|
|
1533 |
%{
|
|
1534 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1535 |
double p0, p1, p2, p3, p4, p5;
|
|
1536 |
double q0, q1, q2, q3;
|
|
1537 |
double s0, s1;
|
|
1538 |
double t0, t1;
|
|
1539 |
double t;
|
|
1540 |
OBJ newQD;
|
|
1541 |
|
|
1542 |
m_two_sqr(p0, a[0], q0);
|
|
1543 |
t = 2.0 * a[0];
|
|
1544 |
|
|
1545 |
m_two_prod(p1, t, a[1], q1);
|
|
1546 |
m_two_prod(p2, t, a[2], q2);
|
|
1547 |
m_two_sqr(p3, a[1], q3);
|
|
1548 |
|
|
1549 |
m_two_sum(p1, q0, p1, q0);
|
|
1550 |
|
|
1551 |
m_two_sum(q0, q0, q1, q1);
|
|
1552 |
m_two_sum(p2, p2, p3, p3);
|
|
1553 |
|
|
1554 |
m_two_sum(s0, q0, p2, t0);
|
|
1555 |
m_two_sum(s1, q1, p3, t1);
|
|
1556 |
|
|
1557 |
m_two_sum(s1, s1, t0, t0);
|
|
1558 |
t0 += t1;
|
|
1559 |
|
|
1560 |
m_quick_two_sum(s1, s1, t0, t0);
|
|
1561 |
m_quick_two_sum(p2, s0, s1, t1);
|
|
1562 |
m_quick_two_sum(p3, t1, t0, q0);
|
|
1563 |
|
|
1564 |
p4 = 2.0 * a[0] * a[3];
|
|
1565 |
p5 = 2.0 * a[1] * a[2];
|
|
1566 |
|
|
1567 |
m_two_sum(p4, p4, p5, p5);
|
|
1568 |
m_two_sum(q2, q2, q3, q3);
|
|
1569 |
|
|
1570 |
m_two_sum(t0, p4, q2, t1);
|
|
1571 |
t1 = t1 + p5 + q3;
|
|
1572 |
|
|
1573 |
m_two_sum(p3, p3, t0, p4);
|
|
1574 |
p4 = p4 + q0 + t1;
|
|
1575 |
|
|
1576 |
m_renorm5(p0, p1, p2, p3, p4);
|
|
1577 |
|
|
1578 |
__qNew_qdReal(newQD, p0, p1, s0, s1);
|
|
1579 |
RETURN( newQD );
|
|
1580 |
%}.
|
|
1581 |
|
|
1582 |
"
|
|
1583 |
(QDouble fromFloat:4.0) squared
|
|
1584 |
(1e20 + (QDouble fromFloat:1.0)) squared
|
|
1585 |
"
|
|
1586 |
|
|
1587 |
"Created: / 13-06-2017 / 01:27:58 / cg"
|
|
1588 |
! !
|
|
1589 |
|
4380
|
1590 |
!QDouble methodsFor:'printing & storing'!
|
|
1591 |
|
4385
|
1592 |
printDigitsOn:outStream precision:precision exponentInto:expn
|
|
1593 |
|numDigits r e i d|
|
|
1594 |
|
|
1595 |
numDigits := precision+1. "/ number of digits
|
|
1596 |
r := self abs.
|
|
1597 |
self d0 = 0.0 ifTrue:[
|
|
1598 |
expn value:0.
|
|
1599 |
precision timesRepeat:[ outStream nextPut:$0 ].
|
|
1600 |
^ self.
|
|
1601 |
].
|
|
1602 |
|
|
1603 |
"/ determine approx. exponent
|
|
1604 |
e := self d0 abs log10 floor.
|
|
1605 |
self halt.
|
|
1606 |
e < -300 ifTrue:[
|
|
1607 |
r := r * (10.0 raisedToInteger:300).
|
|
1608 |
r := r / (10.0 raisedToInteger:(e+300)).
|
|
1609 |
] ifFalse:[
|
|
1610 |
e > 300 ifTrue:[
|
|
1611 |
] ifFalse:[
|
|
1612 |
]
|
|
1613 |
].
|
|
1614 |
|
|
1615 |
|
|
1616 |
"
|
|
1617 |
1.2345 asQDouble printDigitsOn:Transcript precision:5 exponentInto:[:e |]
|
|
1618 |
"
|
|
1619 |
|
|
1620 |
"Created: / 13-06-2017 / 17:28:08 / cg"
|
|
1621 |
!
|
|
1622 |
|
4380
|
1623 |
printString
|
|
1624 |
"return a printed representation of the receiver"
|
|
1625 |
|
|
1626 |
self d1 = 0.0 ifTrue:[
|
|
1627 |
^ self d0 printString
|
|
1628 |
].
|
|
1629 |
^ self d0 printString , '...'
|
|
1630 |
|
|
1631 |
"Created: / 12-06-2017 / 23:41:04 / cg"
|
|
1632 |
! !
|
|
1633 |
|
|
1634 |
!QDouble methodsFor:'private accessing'!
|
|
1635 |
|
|
1636 |
d0
|
4386
|
1637 |
"the most significant (and highest valued) 53 bits of precision"
|
4380
|
1638 |
%{
|
|
1639 |
RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[0]) );
|
|
1640 |
%}
|
|
1641 |
|
|
1642 |
"Created: / 12-06-2017 / 20:15:12 / cg"
|
4386
|
1643 |
"Modified (comment): / 13-06-2017 / 17:59:47 / cg"
|
4380
|
1644 |
!
|
|
1645 |
|
|
1646 |
d1
|
4386
|
1647 |
"the next most significant (and next highest valued) 53 bits of precision"
|
4380
|
1648 |
%{
|
|
1649 |
RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[1]) );
|
|
1650 |
%}
|
|
1651 |
|
|
1652 |
"Created: / 12-06-2017 / 20:15:12 / cg"
|
4386
|
1653 |
"Modified (comment): / 13-06-2017 / 18:00:00 / cg"
|
4380
|
1654 |
!
|
|
1655 |
|
|
1656 |
d2
|
|
1657 |
%{
|
|
1658 |
RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[2]) );
|
|
1659 |
%}
|
|
1660 |
|
|
1661 |
"Created: / 12-06-2017 / 20:15:29 / cg"
|
|
1662 |
!
|
|
1663 |
|
|
1664 |
d3
|
4386
|
1665 |
"the least significant (and smallest valued) 53 bits of precision"
|
4380
|
1666 |
%{
|
|
1667 |
RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[3]) );
|
|
1668 |
%}
|
|
1669 |
|
|
1670 |
"Created: / 12-06-2017 / 20:15:32 / cg"
|
4386
|
1671 |
"Modified (comment): / 13-06-2017 / 18:00:18 / cg"
|
|
1672 |
!
|
|
1673 |
|
|
1674 |
renorm
|
|
1675 |
%{
|
|
1676 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1677 |
double c0, c1, c2, c3;
|
|
1678 |
OBJ newQD;
|
|
1679 |
|
|
1680 |
c0 = a[0];
|
|
1681 |
c1 = a[1];
|
|
1682 |
c2 = a[2];
|
|
1683 |
c3 = a[3];
|
|
1684 |
m_renorm4(c0, c1, c2, c3);
|
|
1685 |
a[0] = c0;
|
|
1686 |
a[1] = c1;
|
|
1687 |
a[2] = c2;
|
|
1688 |
a[3] = c3;
|
|
1689 |
RETURN( self );
|
|
1690 |
%}.
|
|
1691 |
^ self error.
|
|
1692 |
|
|
1693 |
"
|
|
1694 |
(QDouble fromFloat:1.0) renorm
|
|
1695 |
"
|
|
1696 |
|
|
1697 |
"Created: / 13-06-2017 / 18:05:33 / cg"
|
4380
|
1698 |
! !
|
|
1699 |
|
|
1700 |
!QDouble class methodsFor:'documentation'!
|
|
1701 |
|
|
1702 |
version
|
|
1703 |
^ '$Header$'
|
|
1704 |
!
|
|
1705 |
|
|
1706 |
version_CVS
|
|
1707 |
^ '$Header$'
|
|
1708 |
! !
|
|
1709 |
|