4380
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2017 by eXept Software AG
|
4395
|
3 |
All Rights Reserved
|
4380
|
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:''
|
4392
|
18 |
classVariableNames:'DefaultPrintFormat QDoubleZero QDoubleOne Pi E Ln2 Ln10 Epsilon
|
4412
|
19 |
FMax FMin InvFact'
|
4380
|
20 |
poolDictionaries:''
|
|
21 |
category:'Magnitude-Numbers'
|
|
22 |
!
|
|
23 |
|
|
24 |
!QDouble primitiveDefinitions!
|
4411
|
25 |
ry:'Magnitude-Numbers'
|
4380
|
26 |
! !
|
|
27 |
|
|
28 |
!QDouble primitiveFunctions!
|
4411
|
29 |
= quick_two_sum(s1, *c3Ptr, &s2);
|
4380
|
30 |
} else {
|
|
31 |
s0 = quick_two_sum(s0, *c2Ptr, &s1);
|
4411
|
32 |
if (s1 ! !
|
4380
|
33 |
|
|
34 |
!QDouble class methodsFor:'documentation'!
|
|
35 |
|
|
36 |
copyright
|
|
37 |
"
|
|
38 |
COPYRIGHT (c) 2017 by eXept Software AG
|
4395
|
39 |
All Rights Reserved
|
4380
|
40 |
|
|
41 |
This software is furnished under a license and may be used
|
|
42 |
only in accordance with the terms of that license and with the
|
|
43 |
inclusion of the above copyright notice. This software may not
|
|
44 |
be provided or otherwise made available to, or used by, any
|
|
45 |
other person. No title to or ownership of the software is
|
|
46 |
hereby transferred.
|
|
47 |
"
|
|
48 |
!
|
|
49 |
|
|
50 |
documentation
|
|
51 |
"
|
4391
|
52 |
ATTENTION: ongoing, unfinished work.
|
|
53 |
This does not work correctly at the moment.
|
|
54 |
|
4380
|
55 |
QDoubles represent rational numbers with extended, but still limited precision.
|
|
56 |
|
|
57 |
In contrast to Floats (which use the C-compilers native 64bit 'double' format),
|
|
58 |
QDoubles give you 212 bit or approx. 64 decimal digits of precision.
|
|
59 |
|
|
60 |
Representation:
|
4395
|
61 |
QDoubles use 4 IEEE doubles, each keeping 53 bits of precision.
|
4380
|
62 |
|
|
63 |
Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
|
|
64 |
|
4395
|
65 |
Float decimalPrecision
|
|
66 |
QDouble decimalPrecision
|
|
67 |
|
4380
|
68 |
[author:]
|
4395
|
69 |
Claus Gittinger
|
4380
|
70 |
|
|
71 |
[see also:]
|
4395
|
72 |
Number
|
|
73 |
Float ShortFloat Fraction FixedPoint Integer Complex
|
|
74 |
FloatArray DoubleArray
|
4380
|
75 |
"
|
|
76 |
! !
|
|
77 |
|
|
78 |
!QDouble class methodsFor:'instance creation'!
|
|
79 |
|
|
80 |
basicNew
|
|
81 |
"return a new quad-precision double - here we return 0.0
|
|
82 |
Notice that numbers are usually NOT created this way ...
|
|
83 |
It's implemented here to allow things like binary store & load
|
|
84 |
of floats. (but even this support will go away eventually, it's not
|
|
85 |
a good idea to store the bits of a float - the reader might have a
|
|
86 |
totally different representation - so floats should be
|
|
87 |
binary stored in a device independent format."
|
|
88 |
|
|
89 |
%{ /* NOCONTEXT */
|
|
90 |
#ifdef __SCHTEAM__
|
|
91 |
ERROR("trying to instantiate a quad double");
|
|
92 |
#else
|
|
93 |
OBJ newFloat;
|
4404
|
94 |
|
4395
|
95 |
__qNew(newFloat, sizeof(struct __quadDoubleStruct));
|
|
96 |
__stx_setClass(newFloat, QDouble);
|
|
97 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = 0.0;
|
|
98 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
|
|
99 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
|
|
100 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
|
4380
|
101 |
RETURN (newFloat);
|
|
102 |
#endif /* not SCHTEAM */
|
|
103 |
%}
|
|
104 |
|
|
105 |
"
|
|
106 |
self basicNew
|
|
107 |
"
|
|
108 |
|
|
109 |
"Created: / 12-06-2017 / 16:00:38 / cg"
|
|
110 |
!
|
|
111 |
|
|
112 |
d0:d0 d1:d1 d2:d2 d3:d3
|
|
113 |
"return a new quad-precision double from individual double components"
|
|
114 |
|
|
115 |
%{ /* NOCONTEXT */
|
|
116 |
#ifdef __SCHTEAM__
|
|
117 |
ERROR("trying to instantiate a quad double");
|
|
118 |
#else
|
|
119 |
OBJ newQD;
|
|
120 |
|
4395
|
121 |
if (__isFloatLike(d0)
|
4380
|
122 |
&& __isFloatLike(d1)
|
|
123 |
&& __isFloatLike(d2)
|
4395
|
124 |
&& __isFloatLike(d3)) {
|
|
125 |
__qNew_qdReal(newQD, __floatVal(d0), __floatVal(d1),
|
|
126 |
__floatVal(d2), __floatVal(d3));
|
|
127 |
RETURN (newQD);
|
4380
|
128 |
}
|
|
129 |
#endif
|
|
130 |
%}.
|
|
131 |
self error:'invalid argument'
|
|
132 |
|
|
133 |
"
|
|
134 |
self d0: 3.141592653589793116e+00
|
4395
|
135 |
d1: 1.224646799147353207e-16
|
|
136 |
d2: -2.994769809718339666e-33
|
|
137 |
d3: 1.112454220863365282e-49
|
4380
|
138 |
"
|
|
139 |
|
|
140 |
"Created: / 12-06-2017 / 20:17:14 / cg"
|
|
141 |
!
|
|
142 |
|
|
143 |
fromDoubleArray:aDoubleArray
|
|
144 |
"return a new quad-precision double from coercing a double array"
|
|
145 |
|
|
146 |
%{ /* NOCONTEXT */
|
|
147 |
#ifdef __SCHTEAM__
|
|
148 |
ERROR("trying to instantiate a quad double");
|
|
149 |
#else
|
|
150 |
OBJ newQD;
|
|
151 |
|
4395
|
152 |
if (__isDoubleArray(aDoubleArray)) {
|
|
153 |
__qNew_qdReal(newQD,
|
|
154 |
__DoubleArrayInstPtr(aDoubleArray)->d_element[0],
|
|
155 |
__DoubleArrayInstPtr(aDoubleArray)->d_element[1],
|
|
156 |
__DoubleArrayInstPtr(aDoubleArray)->d_element[2],
|
|
157 |
__DoubleArrayInstPtr(aDoubleArray)->d_element[3]);
|
|
158 |
RETURN (newQD);
|
4380
|
159 |
}
|
|
160 |
#endif
|
|
161 |
%}.
|
|
162 |
self error:'invalid argument'
|
|
163 |
|
|
164 |
"
|
4395
|
165 |
self fromDoubleArray(DoubleArray
|
|
166 |
with: 3.141592653589793116e+00
|
|
167 |
with: 1.224646799147353207e-16
|
|
168 |
with: -2.994769809718339666e-33
|
|
169 |
with: 1.112454220863365282e-49)
|
4380
|
170 |
"
|
|
171 |
|
|
172 |
"Created: / 12-06-2017 / 18:25:32 / cg"
|
|
173 |
!
|
|
174 |
|
|
175 |
fromFloat:aFloat
|
|
176 |
"return a new quad-precision double from coercing aFloat"
|
|
177 |
|
|
178 |
%{ /* NOCONTEXT */
|
|
179 |
#ifdef __SCHTEAM__
|
|
180 |
ERROR("trying to instantiate a quad double");
|
|
181 |
#else
|
|
182 |
double dVal;
|
|
183 |
OBJ newFloat;
|
|
184 |
|
|
185 |
if (__isFloatLike(aFloat)) {
|
4395
|
186 |
dVal = __floatVal(aFloat);
|
|
187 |
} else if (__isShortFloat(aFloat)) {
|
|
188 |
dVal = __shortFloatVal(aFloat);
|
4380
|
189 |
} else {
|
4395
|
190 |
goto badArg;
|
|
191 |
}
|
|
192 |
|
|
193 |
__qNew(newFloat, sizeof(struct __quadDoubleStruct));
|
|
194 |
__stx_setClass(newFloat, QDouble);
|
|
195 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = dVal;
|
|
196 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
|
|
197 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
|
|
198 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
|
4380
|
199 |
RETURN (newFloat);
|
|
200 |
|
|
201 |
badArg: ;
|
|
202 |
|
|
203 |
#endif
|
|
204 |
%}.
|
|
205 |
self error:'invalid argument'
|
|
206 |
|
|
207 |
"
|
|
208 |
self fromFloat:1.0
|
|
209 |
"
|
|
210 |
|
|
211 |
"Created: / 12-06-2017 / 16:06:54 / cg"
|
|
212 |
!
|
|
213 |
|
|
214 |
fromInteger:anInteger
|
|
215 |
"return a new quad-precision double from coercing anInteger"
|
|
216 |
|
|
217 |
%{ /* NOCONTEXT */
|
|
218 |
#ifndef __SCHTEAM__
|
|
219 |
OBJ newFloat;
|
|
220 |
|
|
221 |
if (__isSmallInteger(anInteger)) {
|
4395
|
222 |
__qNew(newFloat, sizeof(struct __quadDoubleStruct));
|
|
223 |
__stx_setClass(newFloat, QDouble);
|
|
224 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[0] = (double)(__smallIntegerVal(anInteger));
|
|
225 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[1] = 0.0;
|
|
226 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[2] = 0.0;
|
|
227 |
__QuadDoubleInstPtr(newFloat)->d_quadDoubleValue[3] = 0.0;
|
|
228 |
RETURN (newFloat);
|
4380
|
229 |
}
|
|
230 |
#endif
|
|
231 |
%}.
|
|
232 |
^ super fromInteger:anInteger
|
|
233 |
|
|
234 |
"
|
|
235 |
self fromInteger:2
|
|
236 |
"
|
|
237 |
|
|
238 |
"Created: / 12-06-2017 / 16:10:10 / cg"
|
|
239 |
! !
|
|
240 |
|
4395
|
241 |
!QDouble class methodsFor:'coercing & converting'!
|
|
242 |
|
|
243 |
coerce:aNumber
|
|
244 |
"convert the argument aNumber into an instance of the receiver's class and return it."
|
|
245 |
|
|
246 |
^ aNumber asQDouble
|
|
247 |
|
|
248 |
"Created: / 12-06-2017 / 17:13:47 / cg"
|
|
249 |
"Modified: / 12-06-2017 / 21:09:06 / cg"
|
|
250 |
! !
|
|
251 |
|
4380
|
252 |
!QDouble class methodsFor:'constants'!
|
|
253 |
|
|
254 |
e
|
|
255 |
"return the constant e as quad precision double.
|
|
256 |
(returns approx. 212 bits of precision)"
|
|
257 |
|
|
258 |
E isNil ifTrue:[
|
4388
|
259 |
E := self fromDoubleArray:(DoubleArray
|
|
260 |
with: 2.718281828459045091e+00
|
|
261 |
with: 1.445646891729250158e-16
|
|
262 |
with: -2.127717108038176765e-33
|
|
263 |
with: 1.515630159841218954e-49)
|
|
264 |
].
|
4380
|
265 |
^ E
|
|
266 |
|
|
267 |
"
|
|
268 |
self e
|
|
269 |
"
|
|
270 |
|
|
271 |
"Created: / 12-06-2017 / 18:29:36 / cg"
|
|
272 |
!
|
|
273 |
|
4392
|
274 |
fmax
|
|
275 |
"return the constant e as quad precision double.
|
|
276 |
(returns approx. 212 bits of precision)"
|
|
277 |
|
|
278 |
FMax isNil ifTrue:[
|
4395
|
279 |
FMax := self fromDoubleArray:(DoubleArray
|
|
280 |
with: 1.797693134862314E+308
|
|
281 |
with: 9.97920154767359795037e+291
|
|
282 |
with: 5.53956966280111259858e+275
|
|
283 |
with: 3.07507889307840487279e+259)
|
4392
|
284 |
].
|
|
285 |
^ FMax
|
|
286 |
|
|
287 |
"
|
|
288 |
Float fmax
|
|
289 |
self fmax
|
|
290 |
"
|
|
291 |
|
|
292 |
"Created: / 14-06-2017 / 19:14:18 / cg"
|
|
293 |
!
|
|
294 |
|
|
295 |
fmin
|
|
296 |
"return the smallest representable instance of this class"
|
|
297 |
|
|
298 |
FMin isNil ifTrue:[
|
4395
|
299 |
FMin := 1.6259745436952323e-260 asQDouble
|
4392
|
300 |
].
|
|
301 |
^ FMin
|
|
302 |
|
|
303 |
"
|
|
304 |
QDouble fmin
|
|
305 |
Float fmin
|
|
306 |
"
|
|
307 |
|
|
308 |
"Created: / 14-06-2017 / 19:14:49 / cg"
|
|
309 |
!
|
|
310 |
|
4411
|
311 |
infinity
|
|
312 |
^ Infinity positive
|
|
313 |
|
|
314 |
"Created: / 18-06-2017 / 23:41:07 / cg"
|
|
315 |
!
|
|
316 |
|
4412
|
317 |
invFact
|
|
318 |
InvFact isNil ifTrue:[
|
|
319 |
InvFact := Array new:15.
|
|
320 |
InvFact at:1 put:(self d0:1.66666666666666657e-01 d1:9.25185853854297066e-18 d2:5.13581318503262866e-34 d3:2.85094902409834186e-50).
|
|
321 |
InvFact at:2 put:(self d0:4.16666666666666644e-02 d1:2.31296463463574266e-18 d2:1.28395329625815716e-34 d3:7.12737256024585466e-51).
|
|
322 |
InvFact at:3 put:(self d0:8.33333333333333322e-03 d1:1.15648231731787138e-19 d2:1.60494162032269652e-36 d3:2.22730392507682967e-53).
|
|
323 |
InvFact at:4 put:(self d0:1.38888888888888894e-03 d1:-5.30054395437357706e-20 d2:-1.73868675534958776e-36 d3:-1.63335621172300840e-52).
|
|
324 |
InvFact at:5 put:(self d0:1.98412698412698413e-04 d1:1.72095582934207053e-22 d2:1.49269123913941271e-40 d3:1.29470326746002471e-58).
|
|
325 |
InvFact at:6 put:(self d0:2.48015873015873016e-05 d1:2.15119478667758816e-23 d2:1.86586404892426588e-41 d3:1.61837908432503088e-59).
|
|
326 |
InvFact at:7 put:(self d0:2.75573192239858925e-06 d1:-1.85839327404647208e-22 d2:8.49175460488199287e-39 d3:-5.72661640789429621e-55).
|
|
327 |
InvFact at:8 put:(self d0:2.75573192239858883e-07 d1:2.37677146222502973e-23 d2:-3.26318890334088294e-40 d3:1.61435111860404415e-56).
|
|
328 |
InvFact at:9 put:(self d0:2.50521083854417202e-08 d1:-1.44881407093591197e-24 d2:2.04267351467144546e-41 d3:-8.49632672007163175e-58).
|
|
329 |
InvFact at:10 put:(self d0:2.08767569878681002e-09 d1:-1.20734505911325997e-25 d2:1.70222792889287100e-42 d3:1.41609532150396700e-58).
|
|
330 |
InvFact at:11 put:(self d0:1.60590438368216133e-10 d1:1.25852945887520981e-26 d2:-5.31334602762985031e-43 d3:3.54021472597605528e-59).
|
|
331 |
InvFact at:12 put:(self d0:1.14707455977297245e-11 d1:2.06555127528307454e-28 d2:6.88907923246664603e-45 d3:5.72920002655109095e-61).
|
|
332 |
InvFact at:13 put:(self d0:7.64716373181981641e-13 d1:7.03872877733453001e-30 d2:-7.82753927716258345e-48 d3:1.92138649443790242e-64).
|
|
333 |
InvFact at:14 put:(self d0:4.77947733238738525e-14 d1:4.39920548583408126e-31 d2:-4.89221204822661465e-49 d3:1.20086655902368901e-65).
|
|
334 |
InvFact at:15 put:(self d0:2.81145725434552060e-15 d1:1.65088427308614326e-31 d2:-2.87777179307447918e-50 d3:4.27110689256293549e-67).
|
|
335 |
].
|
|
336 |
^ InvFact
|
|
337 |
|
|
338 |
"Created: / 19-06-2017 / 02:22:23 / cg"
|
|
339 |
!
|
|
340 |
|
4380
|
341 |
ln10
|
|
342 |
"return the constant e as quad precision double.
|
|
343 |
(returns approx. 212 bits of precision)"
|
|
344 |
|
|
345 |
Ln10 isNil ifTrue:[
|
4388
|
346 |
Ln10 := self fromDoubleArray:(DoubleArray
|
|
347 |
with: 2.302585092994045901e+00
|
|
348 |
with: -2.170756223382249351e-16
|
|
349 |
with: -9.984262454465776570e-33
|
|
350 |
with: -4.023357454450206379e-49)
|
|
351 |
].
|
4380
|
352 |
^ Ln10
|
|
353 |
|
|
354 |
"
|
|
355 |
self ln10
|
|
356 |
"
|
|
357 |
|
|
358 |
"Created: / 12-06-2017 / 18:32:29 / cg"
|
|
359 |
!
|
|
360 |
|
|
361 |
ln2
|
|
362 |
"return the constant e as quad precision double.
|
|
363 |
(returns approx. 212 bits of precision)"
|
|
364 |
|
|
365 |
Ln2 isNil ifTrue:[
|
4388
|
366 |
Ln2 := self fromDoubleArray:(DoubleArray
|
|
367 |
with: 6.931471805599452862e-01
|
|
368 |
with: 2.319046813846299558e-17
|
|
369 |
with: 5.707708438416212066e-34
|
|
370 |
with: -3.582432210601811423e-50)
|
|
371 |
].
|
4380
|
372 |
^ Ln2
|
|
373 |
|
|
374 |
"
|
|
375 |
self ln2
|
|
376 |
"
|
|
377 |
|
|
378 |
"Created: / 12-06-2017 / 18:31:34 / cg"
|
|
379 |
!
|
|
380 |
|
4411
|
381 |
negativeInfinity
|
|
382 |
^ Infinity negative
|
|
383 |
|
|
384 |
"Created: / 18-06-2017 / 23:40:47 / cg"
|
|
385 |
!
|
|
386 |
|
4380
|
387 |
pi
|
|
388 |
"return the constant pi as quad precision double.
|
|
389 |
(returns approx. 212 bits of precision)"
|
|
390 |
|
|
391 |
Pi isNil ifTrue:[
|
4388
|
392 |
Pi := self fromDoubleArray:(DoubleArray
|
|
393 |
with: 3.141592653589793116e+00
|
|
394 |
with: 1.224646799147353207e-16
|
|
395 |
with: -2.994769809718339666e-33
|
|
396 |
with: 1.112454220863365282e-49)
|
|
397 |
].
|
4380
|
398 |
^ Pi
|
|
399 |
|
|
400 |
"
|
|
401 |
self pi
|
|
402 |
"
|
|
403 |
|
|
404 |
"Created: / 12-06-2017 / 18:27:13 / cg"
|
4395
|
405 |
!
|
|
406 |
|
|
407 |
unity
|
|
408 |
"return the neutral element for multiplication (1.0) as QDouble"
|
|
409 |
|
|
410 |
QDoubleOne isNil ifTrue:[
|
|
411 |
QDoubleOne := 1.0 asQDouble.
|
|
412 |
].
|
|
413 |
^ QDoubleOne
|
|
414 |
|
|
415 |
"
|
|
416 |
self unity
|
|
417 |
"
|
|
418 |
|
|
419 |
"Created: / 15-06-2017 / 11:45:22 / cg"
|
|
420 |
!
|
|
421 |
|
|
422 |
zero
|
|
423 |
"return the neutral element for addition (0.0) as QDouble"
|
|
424 |
|
|
425 |
QDoubleZero isNil ifTrue:[
|
|
426 |
QDoubleZero := 0.0 asQDouble
|
|
427 |
].
|
|
428 |
^ QDoubleZero
|
|
429 |
|
|
430 |
"
|
|
431 |
self zero
|
|
432 |
"
|
|
433 |
|
|
434 |
"Created: / 15-06-2017 / 11:44:13 / cg"
|
4380
|
435 |
! !
|
|
436 |
|
|
437 |
!QDouble class methodsFor:'queries'!
|
|
438 |
|
4395
|
439 |
defaultPrintPrecision
|
|
440 |
"return the number of decimal digits printed by default"
|
|
441 |
|
|
442 |
^ 10
|
|
443 |
|
|
444 |
"
|
|
445 |
ShortFloat defaultPrintPrecision
|
|
446 |
Float defaultPrintPrecision
|
|
447 |
LongFloat defaultPrintPrecision
|
|
448 |
QDouble defaultPrintPrecision
|
|
449 |
"
|
|
450 |
|
|
451 |
"Created: / 17-06-2017 / 02:58:51 / cg"
|
|
452 |
!
|
|
453 |
|
4380
|
454 |
epsilon
|
|
455 |
"return the maximum relative spacing of instances of mySelf
|
|
456 |
(i.e. the value-delta of the least significant bit)"
|
|
457 |
|
4392
|
458 |
^ 1.2154326714572500565324311366323150942261000827598106963711353e-63
|
4380
|
459 |
|
|
460 |
"
|
|
461 |
Float epsilon
|
|
462 |
ShortFloat epsilon
|
|
463 |
QDouble epsilon
|
|
464 |
"
|
|
465 |
|
|
466 |
"Created: / 12-06-2017 / 18:52:44 / cg"
|
4392
|
467 |
"Modified: / 14-06-2017 / 19:12:23 / cg"
|
4380
|
468 |
!
|
|
469 |
|
|
470 |
numBitsInExponent
|
|
471 |
"answer the number of bits in the exponent"
|
|
472 |
|
|
473 |
^ Float numBitsInExponent
|
|
474 |
|
|
475 |
"
|
|
476 |
1.0 asQDouble class numBitsInExponent
|
|
477 |
"
|
|
478 |
|
|
479 |
"Created: / 12-06-2017 / 11:11:04 / cg"
|
|
480 |
!
|
|
481 |
|
|
482 |
numBitsInMantissa
|
|
483 |
"answer the number of bits in the mantissa"
|
|
484 |
|
|
485 |
^ Float precision * 4
|
4395
|
486 |
|
4380
|
487 |
"
|
|
488 |
1.0 class numBitsInMantissa
|
|
489 |
1.0 asShortFloat class numBitsInMantissa
|
|
490 |
1.0 asLongFloat class numBitsInMantissa
|
|
491 |
1.0 asDDouble class numBitsInMantissa
|
|
492 |
1.0 asQDouble class numBitsInMantissa
|
|
493 |
|
|
494 |
Float numBitsInMantissa
|
|
495 |
ShortFloat numBitsInMantissa
|
|
496 |
QDouble numBitsInMantissa
|
|
497 |
"
|
|
498 |
|
|
499 |
"Created: / 12-06-2017 / 11:13:44 / cg"
|
|
500 |
"Modified: / 12-06-2017 / 18:48:48 / cg"
|
|
501 |
!
|
|
502 |
|
|
503 |
precision
|
|
504 |
"answer the number of bits in the mantissa"
|
|
505 |
|
|
506 |
^ Float precision * 4
|
4395
|
507 |
|
4380
|
508 |
"
|
|
509 |
1.0 class numBitsInMantissa
|
|
510 |
1.0 asShortFloat class numBitsInMantissa
|
|
511 |
1.0 asLongFloat class numBitsInMantissa
|
|
512 |
1.0 asDDouble class numBitsInMantissa
|
|
513 |
1.0 asQDouble class numBitsInMantissa
|
|
514 |
|
|
515 |
Float numBitsInMantissa
|
|
516 |
ShortFloat numBitsInMantissa
|
|
517 |
QDouble numBitsInMantissa
|
|
518 |
QDouble precision
|
|
519 |
"
|
|
520 |
|
|
521 |
"Created: / 12-06-2017 / 18:49:11 / cg"
|
|
522 |
!
|
|
523 |
|
|
524 |
radix
|
|
525 |
"answer the radix of a Floats exponent
|
|
526 |
This is an IEEE float, which is represented as binary"
|
|
527 |
|
|
528 |
^ Float radix
|
|
529 |
|
|
530 |
"Created: / 12-06-2017 / 18:50:04 / cg"
|
|
531 |
! !
|
|
532 |
|
|
533 |
!QDouble methodsFor:'arithmetic'!
|
|
534 |
|
|
535 |
* aNumber
|
|
536 |
"return the product of the receiver and the argument, aNumber"
|
|
537 |
|
|
538 |
^ aNumber productFromQDouble:self
|
|
539 |
|
|
540 |
"
|
4392
|
541 |
(((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) * (QDouble fromFloat:2.0)) asDoubleArray
|
4380
|
542 |
"
|
|
543 |
|
|
544 |
"Created: / 13-06-2017 / 01:00:47 / cg"
|
4392
|
545 |
"Modified (comment): / 14-06-2017 / 12:08:50 / cg"
|
4380
|
546 |
!
|
|
547 |
|
|
548 |
+ aNumber
|
|
549 |
"return the sum of the receiver and the argument, aNumber"
|
|
550 |
|
|
551 |
^ aNumber sumFromQDouble:self
|
|
552 |
|
|
553 |
"
|
|
554 |
((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) asDoubleArray
|
|
555 |
"
|
|
556 |
|
|
557 |
"Created: / 12-06-2017 / 16:17:46 / cg"
|
|
558 |
"Modified: / 12-06-2017 / 23:06:22 / cg"
|
|
559 |
!
|
|
560 |
|
|
561 |
- aNumber
|
|
562 |
"return the sum of the receiver and the argument, aNumber"
|
|
563 |
|
4393
|
564 |
^ self + (aNumber negated)
|
4380
|
565 |
|
|
566 |
"
|
|
567 |
(QDouble fromFloat:1e20) asDoubleArray
|
|
568 |
((QDouble fromFloat:1e20) - (QDouble fromFloat:1.0)) asDoubleArray
|
|
569 |
(QDouble fromFloat:1e-20) asDoubleArray
|
|
570 |
((QDouble fromFloat:1e-20) - (QDouble fromFloat:1.0)) asDoubleArray
|
|
571 |
((QDouble fromFloat:2.0) - (QDouble fromFloat:1.0)) asDoubleArray
|
4395
|
572 |
|
4393
|
573 |
((QDouble fromFloat:2.0) - (QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)) asDoubleArray
|
|
574 |
((QDouble fromFloat:1e-20) - (QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)) asDoubleArray
|
4380
|
575 |
"
|
|
576 |
|
|
577 |
"Created: / 12-06-2017 / 23:41:39 / cg"
|
4393
|
578 |
"Modified (comment): / 15-06-2017 / 00:34:41 / cg"
|
4386
|
579 |
!
|
|
580 |
|
|
581 |
/ aNumber
|
|
582 |
"return the quotient of the receiver and the argument, aNumber"
|
|
583 |
|
|
584 |
^ aNumber quotientFromQDouble:self
|
|
585 |
|
|
586 |
"
|
|
587 |
((QDouble fromFloat:1e20) / (QDouble fromFloat:2.0)) asDoubleArray
|
4395
|
588 |
|
4393
|
589 |
((QDouble fromFloat:1.2345) / (QDouble fromFloat:10.0)) asDoubleArray
|
|
590 |
((QDouble fromFloat:1.2345) / 10.0) asDoubleArray
|
|
591 |
|
4386
|
592 |
"
|
|
593 |
|
|
594 |
"Created: / 13-06-2017 / 17:59:09 / cg"
|
4393
|
595 |
"Modified (comment): / 15-06-2017 / 00:14:26 / cg"
|
4380
|
596 |
! !
|
|
597 |
|
|
598 |
!QDouble methodsFor:'coercing & converting'!
|
|
599 |
|
|
600 |
asDoubleArray
|
4395
|
601 |
^ DoubleArray
|
|
602 |
with:self d0
|
|
603 |
with:self d1
|
|
604 |
with:self d2
|
|
605 |
with:self d3.
|
4380
|
606 |
|
|
607 |
"
|
4386
|
608 |
(QDouble fromFloat:1.0) asDoubleArray
|
|
609 |
(QDouble fromFloat:2.0) asDoubleArray
|
4380
|
610 |
"
|
|
611 |
|
|
612 |
"Created: / 12-06-2017 / 18:19:19 / cg"
|
4386
|
613 |
"Modified (comment): / 13-06-2017 / 17:58:09 / cg"
|
4380
|
614 |
!
|
|
615 |
|
|
616 |
asFloat
|
4386
|
617 |
^ self d0
|
4380
|
618 |
|
|
619 |
"
|
|
620 |
(QDouble fromFloat:1.0) asFloat
|
|
621 |
(QDouble fromFloat:2.0) asFloat
|
|
622 |
"
|
|
623 |
|
|
624 |
"Created: / 12-06-2017 / 18:15:27 / cg"
|
4386
|
625 |
"Modified: / 13-06-2017 / 17:56:50 / cg"
|
4380
|
626 |
!
|
|
627 |
|
4395
|
628 |
asQDouble
|
|
629 |
"return a QDouble with same value as myself."
|
|
630 |
|
|
631 |
^ self
|
|
632 |
|
|
633 |
"Created: / 15-06-2017 / 12:08:02 / cg"
|
|
634 |
!
|
|
635 |
|
4380
|
636 |
coerce:aNumber
|
|
637 |
"convert the argument aNumber into an instance of the receiver's class and return it."
|
|
638 |
|
|
639 |
^ aNumber asQDouble
|
|
640 |
|
|
641 |
"Created: / 12-06-2017 / 17:13:47 / cg"
|
|
642 |
"Modified: / 12-06-2017 / 21:09:06 / cg"
|
|
643 |
!
|
|
644 |
|
|
645 |
generality
|
|
646 |
"return the generality value - see ArithmeticValue>>retry:coercing:"
|
|
647 |
|
|
648 |
^ 95
|
|
649 |
|
|
650 |
"Created: / 12-06-2017 / 17:13:14 / cg"
|
|
651 |
!
|
|
652 |
|
|
653 |
negative
|
4386
|
654 |
^ self d0 negative
|
4380
|
655 |
|
|
656 |
"
|
|
657 |
(QDouble fromFloat:0.0) negative
|
|
658 |
(QDouble fromFloat:1.0) negative
|
|
659 |
(QDouble fromFloat:-1.0) negative
|
|
660 |
"
|
|
661 |
|
|
662 |
"Created: / 13-06-2017 / 01:57:39 / cg"
|
4386
|
663 |
"Modified: / 13-06-2017 / 17:58:26 / cg"
|
4380
|
664 |
!
|
|
665 |
|
|
666 |
positive
|
4386
|
667 |
^ self d0 positive
|
4380
|
668 |
|
|
669 |
"
|
|
670 |
(QDouble fromFloat:1.0) positive
|
|
671 |
(QDouble fromFloat:-1.0) positive
|
|
672 |
"
|
|
673 |
|
|
674 |
"Created: / 13-06-2017 / 01:56:53 / cg"
|
4386
|
675 |
"Modified: / 13-06-2017 / 17:58:41 / cg"
|
4380
|
676 |
! !
|
|
677 |
|
4385
|
678 |
!QDouble methodsFor:'comparing'!
|
|
679 |
|
|
680 |
< aNumber
|
|
681 |
"return true, if the argument, aNumber is greater than the receiver"
|
|
682 |
|
|
683 |
^ aNumber lessFromQDouble:self
|
|
684 |
|
|
685 |
"Created: / 13-06-2017 / 16:58:53 / cg"
|
|
686 |
!
|
|
687 |
|
|
688 |
= aNumber
|
|
689 |
"return true, if the argument, aNumber has the same value as than the receiver"
|
|
690 |
|
|
691 |
^ aNumber equalFromQDouble:self
|
|
692 |
|
|
693 |
"Created: / 13-06-2017 / 17:12:09 / cg"
|
|
694 |
! !
|
|
695 |
|
4380
|
696 |
!QDouble methodsFor:'double dispatching'!
|
|
697 |
|
|
698 |
differenceFromFloat:aFloat
|
|
699 |
"aFloat - self"
|
4395
|
700 |
|
4380
|
701 |
^ aFloat + (self negated)
|
|
702 |
|
|
703 |
"
|
|
704 |
1.0 - (QDouble fromFloat:1.0)
|
|
705 |
1e20 - (QDouble fromFloat:1.0)
|
|
706 |
(1.0 - (QDouble fromFloat:1.0)) asFloat
|
|
707 |
(1e20 - (QDouble fromFloat:1.0)) asFloat
|
|
708 |
|
|
709 |
(1.0 - (QDouble fromFloat:1.0)) asDoubleArray
|
|
710 |
(1e20 - (QDouble fromFloat:1.0)) asDoubleArray
|
|
711 |
(1e20 - (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
|
|
712 |
"
|
|
713 |
|
|
714 |
"Created: / 12-06-2017 / 23:38:05 / cg"
|
|
715 |
!
|
|
716 |
|
|
717 |
differenceFromQDouble:aQDouble
|
|
718 |
"aQDouble - self"
|
4395
|
719 |
|
4380
|
720 |
^ aQDouble + (self negated)
|
|
721 |
|
|
722 |
"
|
|
723 |
1.0 - (QDouble fromFloat:1.0)
|
|
724 |
1e20 - (QDouble fromFloat:1.0)
|
|
725 |
(1.0 - (QDouble fromFloat:1.0)) asFloat
|
|
726 |
(1e20 - (QDouble fromFloat:1.0)) asFloat
|
|
727 |
|
|
728 |
(1.0 - (QDouble fromFloat:1.0)) asDoubleArray
|
|
729 |
(1e20 - (QDouble fromFloat:1.0)) asDoubleArray
|
|
730 |
(1e20 - (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
|
|
731 |
"
|
|
732 |
|
|
733 |
"Created: / 12-06-2017 / 23:38:19 / cg"
|
|
734 |
!
|
|
735 |
|
|
736 |
equalFromQDouble:aQDouble
|
|
737 |
%{
|
|
738 |
if (__Class(aQDouble) == QDouble) {
|
4395
|
739 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
740 |
double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
|
|
741 |
|
|
742 |
RETURN ((a[0] == b[0]
|
|
743 |
&& a[1] == b[1]
|
|
744 |
&& a[2] == b[2]
|
|
745 |
&& a[3] == b[3]) ? true : false);
|
4380
|
746 |
}
|
|
747 |
%}.
|
4386
|
748 |
^ (aQDouble d0 = self d0)
|
|
749 |
and:[ (aQDouble d1 = self d1)
|
|
750 |
and:[ (aQDouble d2 = self d2)
|
|
751 |
and:[ (aQDouble d3 = self d3) ]]]
|
4395
|
752 |
|
4380
|
753 |
"
|
|
754 |
(QDouble fromFloat:1.0) = (QDouble fromFloat:1.0)
|
|
755 |
(QDouble fromFloat:1.0) = 1.0
|
|
756 |
1.0 = (QDouble fromFloat:1.0)
|
|
757 |
"
|
|
758 |
|
|
759 |
"Created: / 13-06-2017 / 03:01:19 / cg"
|
4386
|
760 |
"Modified: / 13-06-2017 / 18:01:52 / cg"
|
4380
|
761 |
!
|
|
762 |
|
4385
|
763 |
lessFromQDouble:aQDouble
|
|
764 |
"sent when aQDouble does not know how to compare to the receiver..
|
|
765 |
Return true if aQDouble < self"
|
4380
|
766 |
|
4385
|
767 |
%{
|
|
768 |
if (__Class(aQDouble) == QDouble) {
|
4395
|
769 |
double *a = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
|
|
770 |
double *b = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
771 |
|
|
772 |
// now compare if a < b!
|
|
773 |
RETURN
|
|
774 |
((a[0] < b[0] ||
|
|
775 |
(a[0] == b[0] && (a[1] < b[1] ||
|
|
776 |
(a[1] == b[1] && (a[2] < b[2] ||
|
|
777 |
(a[2] == b[2] && a[3] < b[3])))))) ? true : false);
|
4380
|
778 |
}
|
|
779 |
%}.
|
4385
|
780 |
^ super lessFromQDouble:aQDouble
|
4380
|
781 |
|
|
782 |
"
|
4385
|
783 |
(1.0 + 1e-40) > 1.0
|
|
784 |
((QDouble fromFloat:1.0) + (QDouble fromFloat:1e-40)) > (QDouble fromFloat:1.0)
|
4380
|
785 |
|
4385
|
786 |
(QDouble fromFloat:1.0) > (QDouble fromFloat:1.0)
|
|
787 |
(QDouble fromFloat:1.1) > (QDouble fromFloat:1.0)
|
|
788 |
(QDouble fromFloat:1.0) > 1.0
|
|
789 |
(QDouble fromFloat:1.1) > 1.0
|
|
790 |
1.0 > (QDouble fromFloat:1.0)
|
|
791 |
"
|
|
792 |
|
|
793 |
"Created: / 13-06-2017 / 17:07:47 / cg"
|
4380
|
794 |
!
|
|
795 |
|
|
796 |
productFromFloat:aFloat
|
|
797 |
%{
|
|
798 |
if (__isFloatLike(aFloat)) {
|
4395
|
799 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
800 |
double b = __floatVal(aFloat);
|
|
801 |
double p0, p1, p2, p3;
|
|
802 |
double q0, q1, q2;
|
|
803 |
double s0, s1, s2, s3, s4;
|
|
804 |
OBJ newQD;
|
|
805 |
int savedCV;
|
|
806 |
|
|
807 |
fpu_fix_start(&savedCV);
|
|
808 |
|
|
809 |
m_two_prod(p0, a[0], b, q0);
|
|
810 |
m_two_prod(p1, a[1], b, q1);
|
|
811 |
m_two_prod(p2, a[2], b, q2);
|
|
812 |
p3 = a[3] * b;
|
|
813 |
|
|
814 |
s0 = p0;
|
|
815 |
|
|
816 |
m_two_sum(s1, q0, p1, s2);
|
|
817 |
|
|
818 |
m_three_sum(s2, q1, p2);
|
|
819 |
|
|
820 |
m_three_sum2(q1, q2, p3);
|
|
821 |
s3 = q1;
|
|
822 |
|
|
823 |
s4 = q2 + p2;
|
|
824 |
|
|
825 |
m_renorm5(s0, s1, s2, s3, s4);
|
|
826 |
fpu_fix_end(&savedCV);
|
|
827 |
|
|
828 |
__qNew_qdReal(newQD, s0, s1, s2, s3);
|
|
829 |
RETURN( newQD );
|
4380
|
830 |
}
|
|
831 |
%}.
|
|
832 |
^ super productFromFloat:aFloat.
|
|
833 |
|
|
834 |
"
|
4387
|
835 |
(QDouble fromFloat:1.0) productFromFloat:2.0
|
|
836 |
((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) productFromFloat:2.0
|
|
837 |
((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) productFromFloat:2e20
|
|
838 |
|
4380
|
839 |
2.0 * (QDouble fromFloat:1.0)
|
4387
|
840 |
2.0 * (QDouble fromFloat:3.0)
|
4395
|
841 |
|
|
842 |
2.0 * ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))
|
4387
|
843 |
(2.0 * ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))) - (QDouble fromFloat:1e20) - (QDouble fromFloat:1e20)
|
|
844 |
|
4380
|
845 |
(2.0 * (QDouble fromFloat:1.0)) asFloat
|
|
846 |
(1e20 * (QDouble fromFloat:1.0)) asFloat
|
|
847 |
|
|
848 |
(1e20 * (QDouble fromFloat:1.0) * 1e-20) asDoubleArray
|
|
849 |
"
|
|
850 |
|
|
851 |
"Created: / 13-06-2017 / 00:58:56 / cg"
|
4387
|
852 |
"Modified: / 14-06-2017 / 11:42:57 / cg"
|
4380
|
853 |
!
|
|
854 |
|
|
855 |
productFromQDouble:aQDouble
|
|
856 |
%{
|
|
857 |
if (__Class(aQDouble) == QDouble) {
|
4395
|
858 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
859 |
double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
|
|
860 |
OBJ newQD;
|
|
861 |
|
|
862 |
// sloppy
|
|
863 |
double p0, p1, p2, p3, p4, p5;
|
|
864 |
double q0, q1, q2, q3, q4, q5;
|
|
865 |
double t0, t1;
|
|
866 |
double s0, s1, s2;
|
|
867 |
int savedCV;
|
|
868 |
|
|
869 |
fpu_fix_start(&savedCV);
|
|
870 |
|
|
871 |
m_two_prod(p0, a[0], b[0], q0);
|
|
872 |
// fprintf(stderr, "%f * %f -> %f, %f\n", a[0], b[0], p0, q0);
|
|
873 |
|
|
874 |
m_two_prod(p1, a[0], b[1], q1);
|
|
875 |
m_two_prod(p2, a[1], b[0], q2);
|
|
876 |
// fprintf(stderr, "%f * %f -> %f, %f\n", a[0], b[1], p1, q1);
|
|
877 |
// fprintf(stderr, "%f * %f -> %f, %f\n", a[1], b[0], p2, q2);
|
|
878 |
|
|
879 |
m_two_prod(p3, a[0], b[2], q3);
|
|
880 |
m_two_prod(p4, a[1], b[1], q4);
|
|
881 |
m_two_prod(p5, a[2], b[0], q5);
|
|
882 |
|
|
883 |
// fprintf(stderr, "%f * %f -> %f, %f\n", a[0], b[2], p3, q3);
|
|
884 |
// fprintf(stderr, "%f * %f -> %f, %f\n", a[1], b[1], p4, q4);
|
|
885 |
// fprintf(stderr, "%f * %f -> %f, %f\n", a[2], b[0], p5, q5);
|
|
886 |
|
|
887 |
/* Start Accumulation */
|
|
888 |
m_three_sum(p1, p2, q0);
|
|
889 |
// fprintf(stderr, "mul7: after three_sum: p1:%e p2:%e q0:%e\n", p1, p2, q0);
|
|
890 |
|
|
891 |
/* Six-Three Sum of p2, q1, q2, p3, p4, p5. */
|
|
892 |
m_three_sum(p2, q1, q2);
|
|
893 |
// fprintf(stderr, "mul8: after three_sum: p2:%e q1:%e q2:%e\n", p2, q1, q2);
|
|
894 |
m_three_sum(p3, p4, p5);
|
|
895 |
// fprintf(stderr, "mul9: after three_sum: p3:%e p4:%e p5:%e\n", p3, p4, p5);
|
|
896 |
|
|
897 |
/* compute (s0, s1, s2) = (p2, q1, q2) + (p3, p4, p5). */
|
|
898 |
m_two_sum(s0, p2, p3, t0);
|
|
899 |
// fprintf(stderr, "mul10: after two_sum: s0:%e p2:%e p3:%e t0:%e\n", s0, p2, p3, t0);
|
|
900 |
m_two_sum(s1, q1, p4, t1);
|
|
901 |
// fprintf(stderr, "mul11: after two_sum: s1:%e q1:%e p4:%e t1:%e\n", s1, q1, p4, t1);
|
|
902 |
s2 = q2 + p5;
|
|
903 |
m_two_sum(s1, s1, t0, t0);
|
|
904 |
// fprintf(stderr, "mul12: after two_sum: s1:%e s1:%e t0:%e t0:%e\n", s1, s1, t0, t0);
|
|
905 |
s2 += (t0 + t1);
|
|
906 |
|
|
907 |
/* O(eps^3) order terms */
|
|
908 |
s1 += a[0]*b[3] + a[1]*b[2] + a[2]*b[1] + a[3]*b[0] + q0 + q3 + q4 + q5;
|
|
909 |
|
|
910 |
// fprintf(stderr, "before renorm5: p0:%e p2:%e s0:%e s1:%e s2:%e\n", p0, p1, s0, s1, s2);
|
|
911 |
m_renorm5(p0, p1, s0, s1, s2);
|
|
912 |
// fprintf(stderr, "after renorm5: p0:%e p2:%e s0:%e s1:%e s2:%e\n", p0, p1, s0, s1, s2);
|
|
913 |
|
|
914 |
fpu_fix_end(&savedCV);
|
|
915 |
|
|
916 |
__qNew_qdReal(newQD, p0, p1, s0, s1);
|
|
917 |
RETURN( newQD );
|
4380
|
918 |
}
|
|
919 |
%}.
|
|
920 |
^ super productFromQDouble:aQDouble.
|
|
921 |
|
|
922 |
"
|
4387
|
923 |
(QDouble fromFloat:1.0) * 2.0
|
4380
|
924 |
2.0 * (QDouble fromFloat:1.0)
|
4387
|
925 |
(QDouble fromFloat:1.0) * (QDouble fromFloat:2.0)
|
|
926 |
|
4380
|
927 |
1e20 * (QDouble fromFloat:1.0)
|
|
928 |
(2.0 * (QDouble fromFloat:1.0)) asFloat
|
|
929 |
(1e20 * (QDouble fromFloat:1.0)) asFloat
|
|
930 |
|
|
931 |
(1e20 * (QDouble fromFloat:1.0) * 1e-20) asDoubleArray
|
4392
|
932 |
|
|
933 |
( ((QDouble fromFloat:1.0) + (QDouble fromFloat:1e20)) * (QDouble fromFloat:2.0)) asDoubleArray
|
4380
|
934 |
"
|
|
935 |
|
|
936 |
"Created: / 13-06-2017 / 01:06:22 / cg"
|
4392
|
937 |
"Modified: / 14-06-2017 / 16:59:58 / cg"
|
4380
|
938 |
!
|
|
939 |
|
4385
|
940 |
quotientFromQDouble:aQDouble
|
4386
|
941 |
"sloppy"
|
4395
|
942 |
|
4385
|
943 |
|q0 q1 q2 q3 r|
|
|
944 |
|
4393
|
945 |
q0 := aQDouble d0 / self d0.
|
|
946 |
"/ Stdout showCR:('q0: %1 (a[0]=%2; b[0]=%3)\n' bindWith:q0 with:self d0 with:aQDouble d0).
|
|
947 |
r := aQDouble - (self * q0).
|
|
948 |
"/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
|
4385
|
949 |
|
4393
|
950 |
q1 := r d0 / self d0.
|
|
951 |
"/ Stdout showCR:('q1: %1 (r[0]=%2; b[0]=%3)\n' bindWith:q1 with:r d0 with:aQDouble d0).
|
|
952 |
r := r - (self * q1).
|
|
953 |
"/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
|
4395
|
954 |
|
4393
|
955 |
q2 := r d0 / self d0.
|
|
956 |
"/ Stdout showCR:('q2: %1 (r[0]=%2; b[0]=%3)\n' bindWith:q2 with:r d0 with:aQDouble d0).
|
|
957 |
r := r - (self * q2).
|
|
958 |
"/ Stdout showCR:('r: %1\n' bindWith:r asDoubleArray).
|
4380
|
959 |
|
4393
|
960 |
q3 := r d0 / self d0.
|
|
961 |
"/ Stdout showCR:('q3: %1 (r[0]=%2; b[0]=%3)\n' bindWith:q3 with:r d0 with:aQDouble d0).
|
4386
|
962 |
|
|
963 |
r := self class d0:q0 d1:q1 d2:q2 d3:q3.
|
4393
|
964 |
"/ Stdout showCR:('before renorm: %1\n' bindWith:r asDoubleArray).
|
4386
|
965 |
r renorm.
|
4393
|
966 |
"/ Stdout showCR:('after renorm: %1\n' bindWith:r asDoubleArray).
|
4386
|
967 |
^ r
|
4380
|
968 |
|
|
969 |
"
|
4385
|
970 |
2.0 / (QDouble fromFloat:2.0)
|
4387
|
971 |
2.0 / (QDouble fromFloat:1.0)
|
4385
|
972 |
1e20 / (QDouble fromFloat:1.0)
|
|
973 |
(2.0 / (QDouble fromFloat:1.0)) asFloat
|
|
974 |
(1e20 / (QDouble fromFloat:1.0)) asFloat
|
|
975 |
|
|
976 |
(QDouble fromFloat:2.0) / 2.0
|
|
977 |
(QDouble fromFloat:1e20) / 2.0
|
|
978 |
((QDouble fromFloat:1.0) / 2.0) asFloat
|
|
979 |
((QDouble fromFloat:1e20 / 2.0)) asFloat
|
4395
|
980 |
|
4385
|
981 |
((1e20 + (QDouble fromFloat:1.0) + 1e-20) / 2.0) asDoubleArray
|
4393
|
982 |
|
|
983 |
((QDouble fromFloat:10.0) quotientFromQDouble: (QDouble fromFloat:1.234)) asDoubleArray
|
|
984 |
((QDouble fromFloat:1.234) / (QDouble fromFloat:10.0)) asDoubleArray
|
4395
|
985 |
|
4393
|
986 |
q0: 1.234000e-01 (a[0]=1.234000e+00; b[0]=1.000000e+01)
|
|
987 |
a: 1.234000e+00/0.000000e+00/0.000000e+00/0.000000e+00
|
|
988 |
b: 1.000000e+01/0.000000e+00/0.000000e+00/0.000000e+00
|
|
989 |
(b * q0): 1.234000e+00/-2.775558e-17/0.000000e+00/0.000000e+00
|
|
990 |
r: 2.775558e-17/0.000000e+00/0.000000e+00/0.000000e+00
|
|
991 |
|
|
992 |
q1: 2.775558e-18 (r[0]=2.775558e-17; b[0]=1.000000e+01)
|
|
993 |
r: -1.540744e-33/0.000000e+00/0.000000e+00/0.000000e+00
|
|
994 |
|
|
995 |
q2: -1.540744e-34 (r[0]=-1.540744e-33; b[0]=1.000000e+01)
|
|
996 |
r: 8.552847e-50/0.000000e+00/0.000000e+00/0.000000e+00
|
|
997 |
|
|
998 |
q3: 8.552847e-51 (r[0]=8.552847e-50; b[0]=1.000000e+01)
|
|
999 |
|
|
1000 |
before renorm: 1.234000e-01/2.775558e-18/-1.540744e-34/8.552847e-51
|
|
1001 |
after renorm: 1.234000e-01/2.775558e-18/-1.540744e-34/8.552847e-51
|
|
1002 |
1.234/10.0 is: 0.123400 / 0.000000 / -0.000000 / 0.000000
|
|
1003 |
|
|
1004 |
|
4380
|
1005 |
"
|
|
1006 |
|
4385
|
1007 |
"Created: / 13-06-2017 / 17:50:35 / cg"
|
4393
|
1008 |
"Modified (comment): / 15-06-2017 / 01:02:05 / cg"
|
4380
|
1009 |
!
|
|
1010 |
|
|
1011 |
sumFromFloat:aFloat
|
|
1012 |
%{
|
|
1013 |
if (__isFloatLike(aFloat)) {
|
4395
|
1014 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1015 |
double b = __floatVal(aFloat);
|
|
1016 |
double c0, c1, c2, c3;
|
|
1017 |
double e;
|
|
1018 |
OBJ newQD;
|
|
1019 |
int savedCV;
|
|
1020 |
|
|
1021 |
fpu_fix_start(&savedCV);
|
|
1022 |
|
|
1023 |
m_two_sum(c0, a[0], b, e);
|
|
1024 |
m_two_sum(c1 ,a[1], e, e);
|
|
1025 |
m_two_sum(c2, a[2], e, e);
|
|
1026 |
m_two_sum(c3, a[3], e, e);
|
|
1027 |
|
|
1028 |
m_renorm5(c0, c1, c2, c3, e);
|
|
1029 |
fpu_fix_end(&savedCV);
|
|
1030 |
__qNew_qdReal(newQD, c0, c1, c2, c3);
|
|
1031 |
RETURN( newQD );
|
4380
|
1032 |
}
|
|
1033 |
%}.
|
|
1034 |
^ super sumFromFloat:aFloat.
|
|
1035 |
|
|
1036 |
"
|
|
1037 |
1.0 + (QDouble fromFloat:1.0)
|
|
1038 |
1e20 + (QDouble fromFloat:1.0)
|
|
1039 |
(1.0 + (QDouble fromFloat:1.0)) asFloat
|
|
1040 |
(1e20 + (QDouble fromFloat:1.0)) asFloat
|
|
1041 |
|
|
1042 |
(1.0 + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1043 |
(1e20 + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1044 |
(1e20 + (QDouble fromFloat:1.0) + 1e-20) asDoubleArray
|
|
1045 |
"
|
|
1046 |
|
|
1047 |
"Created: / 12-06-2017 / 17:16:41 / cg"
|
4387
|
1048 |
"Modified: / 14-06-2017 / 11:43:47 / cg"
|
4380
|
1049 |
!
|
|
1050 |
|
|
1051 |
sumFromQDouble:aQDouble
|
|
1052 |
%{
|
|
1053 |
if (__Class(aQDouble) == QDouble) {
|
4395
|
1054 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1055 |
double *b = __QuadDoubleInstPtr(aQDouble)->d_quadDoubleValue;
|
|
1056 |
OBJ newQD;
|
|
1057 |
|
4380
|
1058 |
#ifndef QD_IEEE_ADD
|
4395
|
1059 |
// sloppy_add...
|
4380
|
1060 |
|
4393
|
1061 |
# if 0
|
4395
|
1062 |
double s0, s1, s2, s3;
|
|
1063 |
double t0, t1, t2, t3;
|
|
1064 |
int savedCV;
|
|
1065 |
|
|
1066 |
fpu_fix_start(&savedCV);
|
|
1067 |
m_two_sum(s0, a[0], b[0], t0);
|
|
1068 |
m_two_sum(s1, a[1], b[1], t1);
|
|
1069 |
m_two_sum(s2, a[2], b[2], t2);
|
|
1070 |
m_two_sum(s3, a[3], b[3], t3);
|
|
1071 |
|
|
1072 |
m_two_sum(s1, s1, t0, t0);
|
|
1073 |
m_three_sum(s2, t0, t1);
|
|
1074 |
m_three_sum2(s3, t0, t2);
|
|
1075 |
t0 = t0 + t1 + t3;
|
|
1076 |
|
|
1077 |
m_renorm5(s0, s1, s2, s3, t0);
|
|
1078 |
fpu_fix_end(&savedCV);
|
|
1079 |
|
|
1080 |
__qNew_qdReal(newQD, s0, s1, s2, s3);
|
|
1081 |
RETURN(newQD);
|
4393
|
1082 |
# else
|
4380
|
1083 |
|
4395
|
1084 |
/* Same as above, but addition re-organized to minimize
|
|
1085 |
data dependency ... unfortunately some compilers are
|
|
1086 |
not very smart to do this automatically */
|
|
1087 |
double s0, s1, s2, s3;
|
|
1088 |
double t0, t1, t2, t3;
|
|
1089 |
double v0, v1, v2, v3;
|
|
1090 |
double u0, u1, u2, u3;
|
|
1091 |
double w0, w1, w2, w3;
|
|
1092 |
int savedCV;
|
|
1093 |
|
|
1094 |
fpu_fix_start(&savedCV);
|
|
1095 |
s0 = a[0] + b[0];
|
|
1096 |
s1 = a[1] + b[1];
|
|
1097 |
s2 = a[2] + b[2];
|
|
1098 |
s3 = a[3] + b[3];
|
|
1099 |
|
|
1100 |
v0 = s0 - a[0];
|
|
1101 |
v1 = s1 - a[1];
|
|
1102 |
v2 = s2 - a[2];
|
|
1103 |
v3 = s3 - a[3];
|
|
1104 |
|
|
1105 |
u0 = s0 - v0;
|
|
1106 |
u1 = s1 - v1;
|
|
1107 |
u2 = s2 - v2;
|
|
1108 |
u3 = s3 - v3;
|
|
1109 |
|
|
1110 |
w0 = a[0] - u0;
|
|
1111 |
w1 = a[1] - u1;
|
|
1112 |
w2 = a[2] - u2;
|
|
1113 |
w3 = a[3] - u3;
|
|
1114 |
|
|
1115 |
u0 = b[0] - v0;
|
|
1116 |
u1 = b[1] - v1;
|
|
1117 |
u2 = b[2] - v2;
|
|
1118 |
u3 = b[3] - v3;
|
|
1119 |
|
|
1120 |
t0 = w0 + u0;
|
|
1121 |
t1 = w1 + u1;
|
|
1122 |
t2 = w2 + u2;
|
|
1123 |
t3 = w3 + u3;
|
|
1124 |
|
|
1125 |
m_two_sum(s1, s1, t0, t0);
|
|
1126 |
m_three_sum(s2, t0, t1);
|
|
1127 |
m_three_sum2(s3, t0, t2);
|
|
1128 |
t0 = t0 + t1 + t3;
|
|
1129 |
|
|
1130 |
/* renormalize */
|
|
1131 |
m_renorm5(s0, s1, s2, s3, t0);
|
|
1132 |
fpu_fix_end(&savedCV);
|
|
1133 |
__qNew_qdReal(newQD, s0, s1, s2, s3);
|
|
1134 |
RETURN(newQD);
|
4393
|
1135 |
# endif
|
4380
|
1136 |
#else
|
4395
|
1137 |
// ieee_add...
|
|
1138 |
int i, j, k;
|
|
1139 |
double s, t;
|
|
1140 |
double u, v; /* double-length accumulator */
|
|
1141 |
double x[4] = {0.0, 0.0, 0.0, 0.0};
|
|
1142 |
int savedCV;
|
|
1143 |
|
|
1144 |
fpu_fix_start(&savedCV);
|
|
1145 |
i = j = k = 0;
|
|
1146 |
if (abs(a[i]) > abs(b[j]))
|
|
1147 |
u = a[i++];
|
|
1148 |
else
|
|
1149 |
u = b[j++];
|
|
1150 |
if (abs(a[i]) > abs(b[j]))
|
|
1151 |
v = a[i++];
|
|
1152 |
else
|
|
1153 |
v = b[j++];
|
|
1154 |
|
|
1155 |
u = quick_two_sum(u, v, v);
|
|
1156 |
|
|
1157 |
while (k < 4) {
|
|
1158 |
if (i >= 4 && j >= 4) {
|
|
1159 |
x[k] = u;
|
|
1160 |
if (k < 3)
|
|
1161 |
x[++k] = v;
|
|
1162 |
break;
|
|
1163 |
}
|
|
1164 |
|
|
1165 |
if (i >= 4)
|
|
1166 |
t = b[j++];
|
|
1167 |
else if (j >= 4)
|
|
1168 |
t = a[i++];
|
|
1169 |
else if (abs(a[i]) > abs(b[j])) {
|
|
1170 |
t = a[i++];
|
|
1171 |
} else
|
|
1172 |
t = b[j++];
|
|
1173 |
|
|
1174 |
s = quick_three_accum(u, v, t);
|
|
1175 |
|
|
1176 |
if (s != 0.0) {
|
|
1177 |
x[k++] = s;
|
|
1178 |
}
|
|
1179 |
}
|
|
1180 |
|
|
1181 |
/* add the rest. */
|
|
1182 |
for (k = i; k < 4; k++)
|
|
1183 |
x[3] += a[k];
|
|
1184 |
for (k = j; k < 4; k++)
|
|
1185 |
x[3] += b[k];
|
|
1186 |
|
|
1187 |
m_renorm4(x[0], x[1], x[2], x[3]);
|
|
1188 |
fpu_fix_end(&savedCV);
|
|
1189 |
__qNew_qdReal(newQD, x[0], x[1], x[2], x[3]);
|
|
1190 |
RETURN(newQD);
|
4380
|
1191 |
#endif
|
|
1192 |
}
|
|
1193 |
%}.
|
|
1194 |
^ super sumFromQDouble:aQDouble
|
4395
|
1195 |
|
4380
|
1196 |
"
|
|
1197 |
(QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)
|
|
1198 |
(QDouble fromFloat:1.0) + 1.0
|
|
1199 |
1.0 + (QDouble fromFloat:1.0)
|
|
1200 |
|
|
1201 |
((QDouble fromFloat:1.0) + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1202 |
((QDouble fromFloat:1.0) + 1.0) asDoubleArray
|
|
1203 |
(1.0 + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1204 |
(1e-20 + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1205 |
(1e20 + (QDouble fromFloat:1.0)) asDoubleArray
|
|
1206 |
"
|
|
1207 |
|
|
1208 |
"Created: / 12-06-2017 / 21:15:43 / cg"
|
4393
|
1209 |
"Modified: / 15-06-2017 / 00:49:10 / cg"
|
4380
|
1210 |
! !
|
|
1211 |
|
|
1212 |
!QDouble methodsFor:'inspecting'!
|
|
1213 |
|
|
1214 |
inspectorExtraAttributes
|
|
1215 |
"extra (pseudo instvar) entries to be shown in an inspector."
|
|
1216 |
|
|
1217 |
^ super inspectorExtraAttributes
|
4395
|
1218 |
add:'-{doubles}' ->
|
|
1219 |
[
|
|
1220 |
self asDoubleArray printString
|
|
1221 |
];
|
|
1222 |
yourself
|
4380
|
1223 |
|
|
1224 |
"Created: / 12-06-2017 / 23:43:05 / cg"
|
|
1225 |
! !
|
|
1226 |
|
4385
|
1227 |
!QDouble methodsFor:'mathematical functions'!
|
|
1228 |
|
4412
|
1229 |
exp
|
|
1230 |
"/ Strategy: We first reduce the size of x by noting that
|
|
1231 |
"/
|
|
1232 |
"/ exp(kr + m * log(2)) = 2^m * exp(r)^k
|
|
1233 |
"/
|
|
1234 |
"/ where m and k are integers. By choosing m appropriately
|
|
1235 |
"/ we can make |kr| <= log(2) / 2 = 0.347. Then exp(r) is
|
|
1236 |
"/ evaluated using the familiar Taylor series. Reducing the
|
|
1237 |
"/ argument substantially speeds up the convergence. */
|
|
1238 |
|
|
1239 |
|k inv_k d0 m mul_pwr2 r
|
|
1240 |
s p t thresh _eps i|
|
|
1241 |
|
|
1242 |
_eps := 1.21543267145725e-63. "/ = 2^-209.
|
|
1243 |
|
|
1244 |
k := 1.0 ldexp:16.
|
|
1245 |
inv_k := 1.0 / k.
|
|
1246 |
|
|
1247 |
d0 := self d0.
|
|
1248 |
(d0 <= -709.0) ifTrue:[
|
|
1249 |
^ 0.0 asQDouble.
|
|
1250 |
].
|
|
1251 |
(d0 >= 709.0) ifTrue:[
|
|
1252 |
^ Infinity positive
|
|
1253 |
].
|
|
1254 |
|
|
1255 |
self isZero ifTrue:[
|
|
1256 |
^ 1.0 asQDouble.
|
|
1257 |
].
|
|
1258 |
|
|
1259 |
self isOne ifTrue:[
|
|
1260 |
^ self class e
|
|
1261 |
].
|
|
1262 |
|
|
1263 |
"/ double m = std::floor(a.x[0] / qd_real::_log2.x[0] + 0.5);
|
|
1264 |
m := (d0 / Float ln2 + 0.5) floor.
|
|
1265 |
|
|
1266 |
mul_pwr2 := [:a :b | QDouble d0:(a d0 * b) d1:(a d1 * b) d2:(a d2 * b) d3:(a d3 * b) ].
|
|
1267 |
|
|
1268 |
"/ qd_real r = mul_pwr2(a - qd_real::_log2 * m, inv_k);
|
|
1269 |
r := mul_pwr2 value:(self - (self class ln2 * m)) value:inv_k.
|
|
1270 |
thresh := inv_k * _eps.
|
|
1271 |
|
|
1272 |
p := r squared.
|
|
1273 |
s := r + (mul_pwr2 value:p value:0.5).
|
|
1274 |
i := 1.
|
|
1275 |
[
|
|
1276 |
p := p * r.
|
|
1277 |
t := p * (self class invFact at:i).
|
|
1278 |
i := i+1.
|
|
1279 |
s := s + t.
|
|
1280 |
] doWhile:[ (t asFloat abs > thresh) and:[i < 10] ]. "/ (std::abs(to_double(t)) > thresh && i < 9);
|
|
1281 |
|
|
1282 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1283 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1284 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1285 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1286 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1287 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1288 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1289 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1290 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1291 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1292 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1293 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1294 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1295 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1296 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1297 |
s := (mul_pwr2 value:s value:2.0) + s squared.
|
|
1298 |
s := s + 1.0.
|
|
1299 |
^ s ldexp:m asInteger.
|
|
1300 |
|
|
1301 |
"
|
|
1302 |
1.0 exp -> 2.71828182845905
|
|
1303 |
1.0 asQDouble exp -> 2.71828182845905
|
|
1304 |
"
|
|
1305 |
|
|
1306 |
"Created: / 19-06-2017 / 01:49:32 / cg"
|
|
1307 |
!
|
|
1308 |
|
4385
|
1309 |
floor
|
|
1310 |
"return the receiver truncated towards negative infinity"
|
|
1311 |
|
|
1312 |
%{
|
|
1313 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1314 |
OBJ newQD;
|
|
1315 |
|
|
1316 |
double x0, x1, x2, x3;
|
|
1317 |
x1 = x2 = x3 = 0.0;
|
|
1318 |
x0 =floor(a[0]);
|
|
1319 |
|
|
1320 |
if (x0 == a[0]) {
|
4395
|
1321 |
x1 = floor(a[1]);
|
|
1322 |
|
|
1323 |
if (x1 == a[1]) {
|
|
1324 |
x2 = floor(a[2]);
|
|
1325 |
|
|
1326 |
if (x2 == a[2]) {
|
|
1327 |
x3 = floor(a[3]);
|
|
1328 |
}
|
|
1329 |
}
|
|
1330 |
|
|
1331 |
m_renorm4(x0, x1, x2, x3);
|
|
1332 |
__qNew_qdReal(newQD, x0, x1, x2, x3);
|
|
1333 |
RETURN( newQD );
|
4385
|
1334 |
}
|
|
1335 |
|
|
1336 |
__qNew_qdReal(newQD, x0, x1, x2, x3);
|
|
1337 |
RETURN( newQD );
|
|
1338 |
%}.
|
|
1339 |
|
|
1340 |
"
|
|
1341 |
(QDouble fromFloat:4.0) floor
|
|
1342 |
(QDouble fromFloat:4.1) floor
|
|
1343 |
(QDouble fromFloat:0.1) floor
|
|
1344 |
(0.1 + (QDouble fromFloat:1.0)) floor
|
4395
|
1345 |
(1e20 + (QDouble fromFloat:1.0)) floor
|
4385
|
1346 |
|
|
1347 |
(QDouble fromFloat:1.5) floor
|
|
1348 |
(QDouble fromFloat:0.5) floor
|
|
1349 |
(QDouble fromFloat:-0.5) floor
|
|
1350 |
(QDouble fromFloat:-1.5) floor
|
|
1351 |
"
|
|
1352 |
|
|
1353 |
"Created: / 13-06-2017 / 01:52:44 / cg"
|
|
1354 |
"Modified (comment): / 13-06-2017 / 17:33:19 / cg"
|
|
1355 |
!
|
|
1356 |
|
4411
|
1357 |
ln
|
4412
|
1358 |
|d0 x|
|
|
1359 |
|
|
1360 |
d0 := self d0.
|
|
1361 |
d0 = 1.0 ifTrue:[
|
|
1362 |
self isOne ifTrue:[ ^ self class zero ].
|
|
1363 |
].
|
|
1364 |
d0 < 0.0 ifTrue:[
|
|
1365 |
^ self class
|
|
1366 |
raise:#domainErrorSignal
|
|
1367 |
receiver:self
|
|
1368 |
selector:#ln
|
|
1369 |
arguments:#()
|
|
1370 |
errorString:'bad receiver in ln'
|
|
1371 |
].
|
|
1372 |
d0 = 0.0 ifTrue:[
|
|
1373 |
^ Infinity negative
|
|
1374 |
].
|
|
1375 |
|
|
1376 |
"/ initial approx.
|
|
1377 |
x := d0 ln asQDouble.
|
|
1378 |
"/ two iterations of taylor
|
|
1379 |
x := x + (self * (x negated exp)) - 1.0.
|
|
1380 |
x := x + (self * (x negated exp)) - 1.0.
|
|
1381 |
x := x + (self * (x negated exp)) - 1.0.
|
|
1382 |
^ x
|
4411
|
1383 |
|
|
1384 |
"
|
4412
|
1385 |
-1 ln
|
4411
|
1386 |
1.0 asQDouble ln
|
|
1387 |
"
|
|
1388 |
|
|
1389 |
"Created: / 18-06-2017 / 23:32:54 / cg"
|
4412
|
1390 |
"Modified: / 19-06-2017 / 01:17:02 / cg"
|
4411
|
1391 |
!
|
|
1392 |
|
4385
|
1393 |
negated
|
4395
|
1394 |
^ self class
|
|
1395 |
d0:(self d0) negated
|
|
1396 |
d1:(self d1) negated
|
|
1397 |
d2:(self d2) negated
|
|
1398 |
d3:(self d3) negated
|
|
1399 |
|
|
1400 |
"
|
4385
|
1401 |
(QDouble fromFloat:1.0) negated
|
|
1402 |
((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0)) negated asDoubleArray
|
|
1403 |
|
|
1404 |
(((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))
|
|
1405 |
+ ((QDouble fromFloat:1e20) + (QDouble fromFloat:1.0))) asDoubleArray
|
|
1406 |
"
|
|
1407 |
|
|
1408 |
"Created: / 12-06-2017 / 20:14:55 / cg"
|
|
1409 |
"Modified (comment): / 12-06-2017 / 23:46:57 / cg"
|
|
1410 |
!
|
|
1411 |
|
|
1412 |
squared
|
|
1413 |
%{
|
|
1414 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
|
1415 |
double p0, p1, p2, p3, p4, p5;
|
|
1416 |
double q0, q1, q2, q3;
|
|
1417 |
double s0, s1;
|
|
1418 |
double t0, t1;
|
|
1419 |
double t;
|
|
1420 |
OBJ newQD;
|
4395
|
1421 |
|
4385
|
1422 |
m_two_sqr(p0, a[0], q0);
|
|
1423 |
t = 2.0 * a[0];
|
|
1424 |
|
|
1425 |
m_two_prod(p1, t, a[1], q1);
|
|
1426 |
m_two_prod(p2, t, a[2], q2);
|
|
1427 |
m_two_sqr(p3, a[1], q3);
|
|
1428 |
|
|
1429 |
m_two_sum(p1, q0, p1, q0);
|
|
1430 |
|
|
1431 |
m_two_sum(q0, q0, q1, q1);
|
|
1432 |
m_two_sum(p2, p2, p3, p3);
|
|
1433 |
|
|
1434 |
m_two_sum(s0, q0, p2, t0);
|
|
1435 |
m_two_sum(s1, q1, p3, t1);
|
|
1436 |
|
|
1437 |
m_two_sum(s1, s1, t0, t0);
|
|
1438 |
t0 += t1;
|
|
1439 |
|
|
1440 |
m_quick_two_sum(s1, s1, t0, t0);
|
|
1441 |
m_quick_two_sum(p2, s0, s1, t1);
|
|
1442 |
m_quick_two_sum(p3, t1, t0, q0);
|
|
1443 |
|
|
1444 |
p4 = 2.0 * a[0] * a[3];
|
|
1445 |
p5 = 2.0 * a[1] * a[2];
|
|
1446 |
|
|
1447 |
m_two_sum(p4, p4, p5, p5);
|
|
1448 |
m_two_sum(q2, q2, q3, q3);
|
|
1449 |
|
|
1450 |
m_two_sum(t0, p4, q2, t1);
|
|
1451 |
t1 = t1 + p5 + q3;
|
|
1452 |
|
|
1453 |
m_two_sum(p3, p3, t0, p4);
|
|
1454 |
p4 = p4 + q0 + t1;
|
|
1455 |
|
|
1456 |
m_renorm5(p0, p1, p2, p3, p4);
|
|
1457 |
|
|
1458 |
__qNew_qdReal(newQD, p0, p1, s0, s1);
|
|
1459 |
RETURN( newQD );
|
|
1460 |
%}.
|
|
1461 |
|
|
1462 |
"
|
|
1463 |
(QDouble fromFloat:4.0) squared
|
4395
|
1464 |
(1e20 + (QDouble fromFloat:1.0)) squared
|
4385
|
1465 |
"
|
|
1466 |
|
|
1467 |
"Created: / 13-06-2017 / 01:27:58 / cg"
|
|
1468 |
! !
|
|
1469 |
|
4380
|
1470 |
!QDouble methodsFor:'printing & storing'!
|
|
1471 |
|
4393
|
1472 |
digitsWithPrecision:precision
|
4395
|
1473 |
"generate digits and exponent.
|
|
1474 |
if precision is >0, that many digits are generated.
|
|
1475 |
If it is 0 the required number of digits is generated
|
|
1476 |
(but never more than the decimalPrecision, which is 65)"
|
|
1477 |
|
4393
|
1478 |
|numDigits r exp i d out str|
|
|
1479 |
|
|
1480 |
numDigits := precision+1. "/ number of digits
|
|
1481 |
r := self abs.
|
|
1482 |
self d0 = 0.0 ifTrue:[
|
4395
|
1483 |
^ { String new:(precision max:1) withAll:$0 . 0 }
|
4393
|
1484 |
].
|
|
1485 |
|
|
1486 |
out := WriteStream on:(String new:precision+5).
|
|
1487 |
|
|
1488 |
"/ determine approx. exponent
|
|
1489 |
exp := self d0 abs log10 floor.
|
|
1490 |
exp < -300 ifTrue:[
|
4395
|
1491 |
"/ 1e-305 asQDouble
|
|
1492 |
r := r * (10.0 raisedToInteger:300).
|
|
1493 |
r := r / (10.0 raisedToInteger:(exp+300)).
|
4393
|
1494 |
] ifFalse:[
|
4395
|
1495 |
exp > 300 ifTrue:[
|
|
1496 |
"/ 1e305 asQDouble
|
|
1497 |
"/ lexpr(x,exp) = x * 2 ^ exp
|
4393
|
1498 |
self halt.
|
4395
|
1499 |
r := r * (2 raisedTo:-53).
|
|
1500 |
r := r / (10.0 asQDouble raisedTo: exp).
|
|
1501 |
r := r * (2 raisedTo:53).
|
|
1502 |
] ifFalse:[
|
|
1503 |
r := r / (10.0 asQDouble raisedTo:exp).
|
|
1504 |
]
|
4393
|
1505 |
].
|
|
1506 |
|
|
1507 |
"/ Fix exponent if we are off by one
|
|
1508 |
(r >= 10.0) ifTrue:[
|
4395
|
1509 |
r := r / 10.0.
|
|
1510 |
exp := exp + 1.
|
4393
|
1511 |
] ifFalse:[
|
4395
|
1512 |
(r < 1.0) ifTrue:[
|
|
1513 |
r := r * 10.0.
|
|
1514 |
exp := exp - 1.
|
|
1515 |
]
|
4393
|
1516 |
].
|
|
1517 |
|
|
1518 |
((r >= 10.0) or:[ r < 1.0 ]) ifTrue:[
|
4395
|
1519 |
self error:'can''t compute exponent.'.
|
4393
|
1520 |
].
|
|
1521 |
|
4395
|
1522 |
"/
|
4393
|
1523 |
"/ Extract the digits
|
4395
|
1524 |
"/ notice, that the d1,d2 and d3 components might
|
|
1525 |
"/ be negative; therefore characters out of the 0..9 range
|
|
1526 |
"/ might be produced here
|
|
1527 |
"/
|
|
1528 |
i := 1.
|
|
1529 |
[ (precision ~~ 0 and:[ i <= numDigits ])
|
|
1530 |
or:[ (precision == 0 and:[r d0 ~= 0.0]) ]] whileTrue:[
|
|
1531 |
d := r d0 truncated.
|
|
1532 |
r := r - d.
|
|
1533 |
r := r * 10.0.
|
|
1534 |
|
|
1535 |
out nextPut:($0 + d).
|
|
1536 |
i := i + 1.
|
4393
|
1537 |
].
|
4395
|
1538 |
numDigits := i-1.
|
4393
|
1539 |
|
|
1540 |
str := out contents.
|
4395
|
1541 |
|
4393
|
1542 |
"/ Fix out-of-range digits.
|
4395
|
1543 |
numDigits to:2 by:-1 do:[:i |
|
|
1544 |
(str at:i) < $0 ifTrue:[
|
|
1545 |
str at:i-1 put:(str at:i-1) - 1.
|
|
1546 |
str at:i put:(str at:i) + 10.
|
|
1547 |
] ifFalse:[
|
|
1548 |
(str at:i) > $9 ifTrue:[
|
|
1549 |
str at:i-1 put:(str at:i-1) + 1.
|
|
1550 |
str at:i put:(str at:i) - 10.
|
|
1551 |
].
|
|
1552 |
].
|
4393
|
1553 |
].
|
|
1554 |
|
4395
|
1555 |
str first <= $0 ifTrue:[
|
|
1556 |
self error:'non-positive leading digit'
|
|
1557 |
].
|
|
1558 |
|
|
1559 |
"/ Round, handle carry
|
4393
|
1560 |
(str at:numDigits) >= $5 ifTrue:[
|
4395
|
1561 |
str at:numDigits-1 put:(str at:numDigits-1) + 1.
|
|
1562 |
i := numDigits-1.
|
|
1563 |
[i > 1 and:[(str at:i) > $9]] whileTrue:[
|
|
1564 |
str at:i put:(str at:i) - 10.
|
|
1565 |
i := i - 1.
|
|
1566 |
str at:i put:(str at:i) + 1.
|
|
1567 |
]
|
|
1568 |
].
|
4393
|
1569 |
|
|
1570 |
"/ If first digit is 10, shift everything.
|
4395
|
1571 |
str first > $9 ifTrue:[
|
|
1572 |
exp := exp + 1.
|
|
1573 |
str at:1 put:$0.
|
|
1574 |
str := '1',str
|
|
1575 |
].
|
|
1576 |
^ { (str copyTo:numDigits-1) . exp }
|
|
1577 |
|
4393
|
1578 |
"
|
4395
|
1579 |
0 asQDouble digitsWithPrecision:1 -> #('0' 0)
|
|
1580 |
0 asQDouble digitsWithPrecision:0 -> #('0' 0)
|
|
1581 |
|
|
1582 |
|
|
1583 |
1.2345 printfPrintString:'%.4f'
|
|
1584 |
1.2345 asQDouble digitsWithPrecision:5 -> #('12345' 0)
|
|
1585 |
|
|
1586 |
--- but 1.2345 is not really what you think:
|
|
1587 |
1.2345 printfPrintString:'%.20f'
|
|
1588 |
1.2345 asQDouble digitsWithPrecision:20 -> #('12344999999999999307' 0)
|
|
1589 |
|
|
1590 |
12.345 asQDouble digitsWithPrecision:5 -> #('12345' 1)
|
|
1591 |
12345 asQDouble digitsWithPrecision:5 -> #('12345' 4)
|
|
1592 |
12345.1 asQDouble digitsWithPrecision:5 -> #('12345' 4)
|
|
1593 |
12345.9 asQDouble digitsWithPrecision:5 -> #('12346' 4)
|
|
1594 |
|
4393
|
1595 |
1.2345 asQDouble / 10.0 asQDouble
|
4395
|
1596 |
1.2345 asQDouble / 10.0
|
4393
|
1597 |
"
|
|
1598 |
|
4395
|
1599 |
"Created: / 15-06-2017 / 09:10:01 / cg"
|
|
1600 |
"Modified: / 16-06-2017 / 10:01:03 / cg"
|
4393
|
1601 |
!
|
|
1602 |
|
|
1603 |
printOn:aStream
|
4395
|
1604 |
"return a printed representation of the receiver.
|
|
1605 |
|
|
1606 |
Notice:
|
|
1607 |
this code was adapted from an ugly piece of c++ code,
|
|
1608 |
which was obviously hacked.
|
|
1609 |
It does need a rework.
|
|
1610 |
As an alternative, use the printf functions, which should also deal wth QDoubles"
|
|
1611 |
|
4404
|
1612 |
PrintfScanf printf:'%f' on:aStream argument:self.
|
4395
|
1613 |
|
|
1614 |
"/ self
|
|
1615 |
"/ printOn:aStream precision:40 width:0
|
|
1616 |
"/ fixed:true showPositive:false uppercase:false fillChar:(Character space)
|
4393
|
1617 |
|
|
1618 |
"
|
4404
|
1619 |
(1.2345 asQDouble) printOn:Transcript . Transcript cr.
|
|
1620 |
(1.2345 asFloat) printOn:Transcript . Transcript cr.
|
|
1621 |
(1.2345 asLongFloat) printOn:Transcript . Transcript cr.
|
|
1622 |
(1.2345 asShortFloat) printOn:Transcript . Transcript cr.
|
|
1623 |
|
4393
|
1624 |
((QDouble fromFloat:1.2345) / 10.0) printOn:Transcript
|
|
1625 |
"
|
|
1626 |
|
|
1627 |
"Created: / 15-06-2017 / 01:51:36 / cg"
|
4404
|
1628 |
"Modified: / 17-06-2017 / 03:30:41 / cg"
|
4393
|
1629 |
!
|
|
1630 |
|
4395
|
1631 |
printOn:aStream precision:precisionIn width:width
|
4393
|
1632 |
fixed:fixed showPositive:showPositive uppercase:uppercase fillChar:fillChar
|
|
1633 |
|
|
1634 |
"return a printed representation of the receiver.
|
4395
|
1635 |
This is a parametrized entry, which can be used by printf-like functions.
|
|
1636 |
Notice:
|
|
1637 |
this code was adapted from an ugly piece of c++ code,
|
|
1638 |
which was obviously hacked.
|
|
1639 |
It does need a rework.
|
|
1640 |
As an alternative, use the printf functions, which should also deal wth QDoubles
|
|
1641 |
"
|
|
1642 |
|
|
1643 |
"
|
|
1644 |
1.2345 asQDouble printString
|
|
1645 |
12.345 asQDouble printString
|
|
1646 |
12345 asQDouble printString
|
|
1647 |
"
|
|
1648 |
|
|
1649 |
|sgn count delta exp precision|
|
|
1650 |
|
|
1651 |
"/ self d1 = 0.0 ifTrue:[
|
|
1652 |
"/ self d0 printOn:aStream.
|
|
1653 |
"/ ^ self.
|
|
1654 |
"/ ].
|
4385
|
1655 |
|
4393
|
1656 |
count := 0.
|
|
1657 |
sgn := true.
|
|
1658 |
exp := 0.
|
4395
|
1659 |
precision := precisionIn.
|
|
1660 |
|
4393
|
1661 |
self isInfinite ifTrue:[
|
4395
|
1662 |
self < 0 ifTrue:[
|
|
1663 |
aStream nextPut:$-.
|
|
1664 |
count := 1.
|
|
1665 |
] ifFalse:[
|
|
1666 |
showPositive ifTrue:[
|
|
1667 |
aStream nextPut:$+.
|
|
1668 |
count := 1.
|
|
1669 |
] ifFalse:[
|
|
1670 |
sgn := false.
|
|
1671 |
].
|
|
1672 |
].
|
|
1673 |
uppercase ifTrue:[
|
|
1674 |
aStream nextPutAll:'INF'
|
|
1675 |
] ifFalse:[
|
|
1676 |
aStream nextPutAll:'inf'
|
|
1677 |
].
|
|
1678 |
count := count + 3.
|
4385
|
1679 |
] ifFalse:[
|
4395
|
1680 |
self isNaN ifTrue:[
|
|
1681 |
uppercase ifTrue:[
|
|
1682 |
aStream nextPutAll:'NAN'
|
|
1683 |
] ifFalse:[
|
|
1684 |
aStream nextPutAll:'nan'
|
|
1685 |
].
|
|
1686 |
count := count + 3.
|
|
1687 |
] ifFalse:[
|
|
1688 |
self < 0 ifTrue:[
|
|
1689 |
aStream nextPut:$-.
|
|
1690 |
count := count + 1.
|
|
1691 |
] ifFalse:[
|
|
1692 |
showPositive ifTrue:[
|
|
1693 |
aStream nextPut:$+.
|
|
1694 |
count := count + 1.
|
|
1695 |
] ifFalse:[
|
|
1696 |
sgn := false.
|
|
1697 |
].
|
|
1698 |
].
|
|
1699 |
self = 0.0 ifTrue:[
|
|
1700 |
aStream nextPut:$0.
|
|
1701 |
count := count + 1.
|
|
1702 |
precision > 0 ifTrue:[
|
|
1703 |
aStream nextPut:$..
|
|
1704 |
count := count + 1.
|
|
1705 |
precision timesRepeat:[ aStream nextPut:$0 ].
|
|
1706 |
count := count + precision.
|
|
1707 |
].
|
|
1708 |
self halt.
|
|
1709 |
] ifFalse:[
|
|
1710 |
|off d d_width_extra|
|
|
1711 |
|
|
1712 |
"/ non-zero case
|
|
1713 |
off := fixed
|
|
1714 |
ifTrue:[ 1 + self asFloat abs log10 floor asInteger ]
|
|
1715 |
ifFalse:[1].
|
|
1716 |
d := precision + off.
|
|
1717 |
d_width_extra := d.
|
|
1718 |
fixed ifTrue:[
|
|
1719 |
d_width_extra := 40 max:d.
|
|
1720 |
].
|
|
1721 |
"/ highly special case - fixed mode, precision is zero, abs(*this) < 1.0
|
|
1722 |
"/ without this trap a number like 0.9 printed fixed with 0 precision prints as 0
|
|
1723 |
"/ should be rounded to 1.
|
|
1724 |
(fixed and:[ (precision == 0) and:[ (self abs < 1.0) ]]) ifTrue:[
|
|
1725 |
(self abs >= 0.5) ifTrue:[
|
|
1726 |
aStream nextPut:$1
|
|
1727 |
] ifFalse:[
|
|
1728 |
aStream nextPut:$0
|
|
1729 |
].
|
|
1730 |
^ self
|
|
1731 |
].
|
|
1732 |
|
|
1733 |
"/ handle near zero to working precision (but not exactly zero)
|
|
1734 |
(fixed and:[ d <= 0 ]) ifTrue:[
|
|
1735 |
aStream nextPut:$0.
|
|
1736 |
(precision > 0) ifTrue:[
|
|
1737 |
aStream nextPut:$. .
|
|
1738 |
aStream next:precision put:$0.
|
|
1739 |
]
|
|
1740 |
] ifFalse:[
|
|
1741 |
"/ default
|
|
1742 |
|
|
1743 |
|t j|
|
|
1744 |
|
|
1745 |
t := self digitsWithPrecision:(fixed ifTrue:[d_width_extra] ifFalse:[d])+1.
|
|
1746 |
exp := t second.
|
|
1747 |
t := t first.
|
|
1748 |
|
|
1749 |
fixed ifTrue:[
|
|
1750 |
"/ fix the string if it's been computed incorrectly
|
|
1751 |
"/ round here in the decimal string if required
|
|
1752 |
t := self round_string_qd:t at:(d + 1) offset:off.
|
|
1753 |
precision := t at:3.
|
|
1754 |
off := t at:2.
|
|
1755 |
t := t at:1.
|
|
1756 |
|
|
1757 |
(off > 0) ifTrue:[
|
|
1758 |
aStream next:off putAll:t startingAt:1.
|
|
1759 |
(precision > 0) ifTrue:[
|
|
1760 |
aStream nextPut:$. .
|
|
1761 |
aStream next:precision-1 putAll:t startingAt:off+1.
|
|
1762 |
]
|
|
1763 |
] ifFalse:[
|
|
1764 |
aStream nextPutAll:'0.'.
|
|
1765 |
(off < 0) ifTrue:[
|
|
1766 |
aStream next:off negated put:$0.
|
|
1767 |
].
|
|
1768 |
aStream next:d putAll:t startingAt:0.
|
|
1769 |
]
|
|
1770 |
] ifFalse:[
|
|
1771 |
aStream nextPut:(t at:1).
|
|
1772 |
(precision > 0) ifTrue:[
|
|
1773 |
aStream nextPut:$. .
|
|
1774 |
].
|
|
1775 |
aStream next:precision putAll:t startingAt:2.
|
|
1776 |
]
|
|
1777 |
].
|
|
1778 |
].
|
|
1779 |
]
|
4385
|
1780 |
].
|
4393
|
1781 |
|
|
1782 |
"/ trap for improper offset with large values
|
|
1783 |
"/ without this trap, output of values of the for 10^j - 1 fail for j > 28
|
|
1784 |
"/ and are output with the point in the wrong place, leading to a dramatically off value
|
4385
|
1785 |
|
4393
|
1786 |
"/ (fixed and:[ (precision > 0) ]) ifTrue:[
|
|
1787 |
"/ "/ make sure that the value isn't dramatically larger
|
|
1788 |
"/ from_string = atof(s.c_str());
|
|
1789 |
"/
|
|
1790 |
"/ // if this ratio is large, then we've got problems
|
|
1791 |
"/ if( fabs( from_string / this->x[0] ) > 3.0 ){
|
|
1792 |
"/
|
|
1793 |
"/ int point_position;
|
|
1794 |
"/ char temp;
|
|
1795 |
"/
|
|
1796 |
"/ // loop on the string, find the point, move it up one
|
|
1797 |
"/ // don't act on the first character
|
|
1798 |
"/ for(i=1; i < s.length(); i++){
|
|
1799 |
"/ if(s[i] == '.'){
|
|
1800 |
"/ s[i] = s[i-1] ;
|
|
1801 |
"/ s[i-1] = '.' ;
|
|
1802 |
"/ break;
|
|
1803 |
"/ }
|
|
1804 |
"/ }
|
|
1805 |
"/
|
|
1806 |
"/ from_string = atof(s.c_str());
|
|
1807 |
"/ // if this ratio is large, then the string has not been fixed
|
|
1808 |
"/ if( fabs( from_string / this->x[0] ) > 3.0 ){
|
|
1809 |
"/ dd_real::error("Re-rounding unsuccessful in large number fixed point trap.") ;
|
|
1810 |
"/ }
|
|
1811 |
"/ }
|
|
1812 |
"/ }
|
|
1813 |
"/
|
4395
|
1814 |
fixed ifFalse:[
|
|
1815 |
"/ Fill in exponent part
|
|
1816 |
aStream nextPut:(uppercase ifTrue:[$E] ifFalse:[$e]).
|
|
1817 |
aStream print:exp.
|
|
1818 |
].
|
4393
|
1819 |
|
|
1820 |
"/ fill in the blanks
|
|
1821 |
(delta := width-count) > 0 ifTrue:[
|
4395
|
1822 |
self halt.
|
4393
|
1823 |
"/ if (fmt & ios_base::internal) {
|
|
1824 |
"/ if (sgn)
|
|
1825 |
"/ s.insert(static_cast<string::size_type>(1), delta, fill);
|
|
1826 |
"/ else
|
|
1827 |
"/ s.insert(static_cast<string::size_type>(0), delta, fill);
|
|
1828 |
"/ } else if (fmt & ios_base::left) {
|
|
1829 |
"/ s.append(delta, fill);
|
|
1830 |
"/ } else {
|
|
1831 |
"/ s.insert(static_cast<string::size_type>(0), delta, fill);
|
|
1832 |
"/ }
|
|
1833 |
"/ }
|
|
1834 |
].
|
|
1835 |
|
|
1836 |
"Created: / 15-06-2017 / 02:37:31 / cg"
|
4395
|
1837 |
"Modified (comment): / 16-06-2017 / 14:48:30 / cg"
|
4385
|
1838 |
!
|
|
1839 |
|
4380
|
1840 |
printString
|
|
1841 |
"return a printed representation of the receiver"
|
|
1842 |
|
4393
|
1843 |
^ String streamContents:[:s | self printOn:s]
|
4380
|
1844 |
|
|
1845 |
"Created: / 12-06-2017 / 23:41:04 / cg"
|
4393
|
1846 |
"Modified: / 15-06-2017 / 01:53:46 / cg"
|
4395
|
1847 |
!
|
|
1848 |
|
|
1849 |
round_string_qd:str at:precisionIn offset:offsetIn
|
|
1850 |
"returns a triple of: { new-str . new-offset . new-precision }"
|
|
1851 |
|
|
1852 |
"/
|
|
1853 |
"/ Input string must be all digits or errors will occur.
|
|
1854 |
"/
|
|
1855 |
|
|
1856 |
|i numDigits offsetOut precisionOut|
|
|
1857 |
|
|
1858 |
numDigits := precisionIn.
|
|
1859 |
|
|
1860 |
offsetOut := offsetIn.
|
|
1861 |
precisionOut := precisionIn.
|
|
1862 |
|
|
1863 |
"/ Round, handle carry
|
|
1864 |
((str at:numDigits) >= $5) ifTrue:[
|
|
1865 |
str at:numDigits-1 put:(str at:numDigits-1)+1.
|
|
1866 |
i := numDigits-1.
|
|
1867 |
[ i > 1 and:[ (str at:i) > $9] ] whileTrue:[
|
|
1868 |
str at:i put:(str at:i)-10.
|
|
1869 |
i := i - 1.
|
|
1870 |
str at:i put:(str at:i)+1.
|
|
1871 |
]
|
|
1872 |
].
|
|
1873 |
|
|
1874 |
"/ If first digit is 10, shift everything.
|
|
1875 |
(str at:1) > $9 ifTrue:[
|
|
1876 |
"/ e++; // don't modify exponent here
|
|
1877 |
str replaceFrom:2 with:str startingAt:1.
|
|
1878 |
str at:1 put:$1.
|
|
1879 |
str at:2 put:$0.
|
|
1880 |
offsetOut := offsetOut + 1.
|
|
1881 |
precisionOut := precisionOut + 1.
|
|
1882 |
].
|
|
1883 |
^ { (str copyTo:precisionOut) . offsetOut . precisionOut }
|
|
1884 |
|
|
1885 |
"Created: / 16-06-2017 / 10:12:39 / cg"
|
|
1886 |
"Modified (comment): / 16-06-2017 / 11:22:03 / cg"
|
4380
|
1887 |
! !
|
|
1888 |
|
|
1889 |
!QDouble methodsFor:'private accessing'!
|
|
1890 |
|
|
1891 |
d0
|
4386
|
1892 |
"the most significant (and highest valued) 53 bits of precision"
|
4380
|
1893 |
%{
|
4395
|
1894 |
RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[0]) );
|
4380
|
1895 |
%}
|
|
1896 |
|
|
1897 |
"Created: / 12-06-2017 / 20:15:12 / cg"
|
4386
|
1898 |
"Modified (comment): / 13-06-2017 / 17:59:47 / cg"
|
4380
|
1899 |
!
|
|
1900 |
|
|
1901 |
d1
|
4386
|
1902 |
"the next most significant (and next highest valued) 53 bits of precision"
|
4380
|
1903 |
%{
|
4395
|
1904 |
RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[1]) );
|
4380
|
1905 |
%}
|
|
1906 |
|
|
1907 |
"Created: / 12-06-2017 / 20:15:12 / cg"
|
4386
|
1908 |
"Modified (comment): / 13-06-2017 / 18:00:00 / cg"
|
4380
|
1909 |
!
|
|
1910 |
|
|
1911 |
d2
|
|
1912 |
%{
|
4395
|
1913 |
RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[2]) );
|
4380
|
1914 |
%}
|
|
1915 |
|
|
1916 |
"Created: / 12-06-2017 / 20:15:29 / cg"
|
|
1917 |
!
|
|
1918 |
|
|
1919 |
d3
|
4386
|
1920 |
"the least significant (and smallest valued) 53 bits of precision"
|
4380
|
1921 |
%{
|
4395
|
1922 |
RETURN ( __MKFLOAT(__QuadDoubleInstPtr(self)->d_quadDoubleValue[3]) );
|
4380
|
1923 |
%}
|
|
1924 |
|
|
1925 |
"Created: / 12-06-2017 / 20:15:32 / cg"
|
4386
|
1926 |
"Modified (comment): / 13-06-2017 / 18:00:18 / cg"
|
|
1927 |
!
|
|
1928 |
|
|
1929 |
renorm
|
4393
|
1930 |
"destructive renormalization"
|
4386
|
1931 |
%{
|
4395
|
1932 |
double *a = __QuadDoubleInstPtr(self)->d_quadDoubleValue;
|
4386
|
1933 |
double c0, c1, c2, c3;
|
|
1934 |
|
|
1935 |
c0 = a[0];
|
|
1936 |
c1 = a[1];
|
|
1937 |
c2 = a[2];
|
|
1938 |
c3 = a[3];
|
|
1939 |
m_renorm4(c0, c1, c2, c3);
|
|
1940 |
a[0] = c0;
|
|
1941 |
a[1] = c1;
|
|
1942 |
a[2] = c2;
|
|
1943 |
a[3] = c3;
|
|
1944 |
RETURN( self );
|
|
1945 |
%}.
|
|
1946 |
^ self error.
|
|
1947 |
|
|
1948 |
"
|
|
1949 |
(QDouble fromFloat:1.0) renorm
|
|
1950 |
"
|
|
1951 |
|
|
1952 |
"Created: / 13-06-2017 / 18:05:33 / cg"
|
4393
|
1953 |
"Modified: / 15-06-2017 / 00:12:59 / cg"
|
|
1954 |
! !
|
|
1955 |
|
|
1956 |
!QDouble methodsFor:'testing'!
|
|
1957 |
|
4404
|
1958 |
isFinite
|
|
1959 |
^ self d0 isFinite
|
|
1960 |
|
|
1961 |
"Created: / 17-06-2017 / 03:40:30 / cg"
|
|
1962 |
!
|
|
1963 |
|
4393
|
1964 |
isInfinite
|
|
1965 |
^ self d0 isInfinite
|
|
1966 |
|
|
1967 |
"Created: / 15-06-2017 / 01:57:57 / cg"
|
|
1968 |
!
|
|
1969 |
|
|
1970 |
isNaN
|
|
1971 |
^ self d0 isNaN
|
|
1972 |
|
|
1973 |
"Created: / 15-06-2017 / 01:57:35 / cg"
|
4411
|
1974 |
!
|
|
1975 |
|
|
1976 |
isOne
|
|
1977 |
^ self d0 = 1.0
|
|
1978 |
and:[ self d1 = 0.0
|
|
1979 |
and:[ self d2 = 0.0
|
|
1980 |
and:[ self d3 = 0.0 ]]]
|
|
1981 |
|
|
1982 |
"Created: / 18-06-2017 / 23:29:07 / cg"
|
|
1983 |
!
|
|
1984 |
|
|
1985 |
isZero
|
|
1986 |
^ self d0 = 0.0
|
|
1987 |
|
|
1988 |
"Created: / 18-06-2017 / 23:29:25 / cg"
|
4380
|
1989 |
! !
|
|
1990 |
|
|
1991 |
!QDouble class methodsFor:'documentation'!
|
|
1992 |
|
|
1993 |
version
|
|
1994 |
^ '$Header$'
|
|
1995 |
!
|
|
1996 |
|
|
1997 |
version_CVS
|
|
1998 |
^ '$Header$'
|
|
1999 |
! !
|
4411
|
2000 |
|