author | Claus Gittinger <cg@exept.de> |
Mon, 25 Nov 2019 01:14:57 +0100 | |
changeset 5287 | 16a42e9d5748 |
parent 5276 | b81062a163d4 |
child 5290 | 8572a1e6ceba |
permissions | -rw-r--r-- |
4983 | 1 |
"{ Package: 'stx:libbasic2' }" |
2 |
||
3 |
"{ NameSpace: Smalltalk }" |
|
4 |
||
5 |
LimitedPrecisionReal variableByteSubclass:#QuadFloat |
|
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'QuadFloatZero QuadFloatOne Pi E Epsilon NaN PositiveInfinity |
|
5269
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
8 |
NegativeInfinity Halfpi HalfpiNegative Phi' |
4983 | 9 |
poolDictionaries:'' |
10 |
category:'Magnitude-Numbers' |
|
11 |
! |
|
12 |
||
4991 | 13 |
!QuadFloat primitiveDefinitions! |
14 |
%{ |
|
5287 | 15 |
#ifdef __xxosx__ |
16 |
# define SUPPORT_QUADFLOAT |
|
17 |
#endif |
|
5027 | 18 |
|
5276 | 19 |
#include <math.h> |
4998 | 20 |
|
5276 | 21 |
extern float128_t STX_addq(float128_t, float128_t, int); |
22 |
extern float128_t STX_mulq(float128_t, float128_t); |
|
23 |
extern float128_t STX_divq(float128_t, float128_t); |
|
24 |
extern float128_t STX_negq(float128_t); |
|
25 |
extern float128_t STX_absq(float128_t); |
|
26 |
extern float128_t STX_floorq(float128_t); |
|
27 |
extern float128_t STX_frexpq(float128_t, int*); |
|
28 |
extern float128_t STX_ceilq(float128_t); |
|
29 |
extern float128_t STX_logq(float128_t); |
|
30 |
extern float128_t STX_log10q(float128_t); |
|
31 |
extern float128_t STX_log2q(float128_t); |
|
32 |
extern float128_t STX_expq(float128_t); |
|
33 |
extern float128_t STX_sinq(float128_t); |
|
34 |
extern float128_t STX_cosq(float128_t); |
|
35 |
extern float128_t STX_tanq(float128_t); |
|
36 |
extern float128_t STX_sinhq(float128_t); |
|
37 |
extern float128_t STX_coshq(float128_t); |
|
38 |
extern float128_t STX_tanhq(float128_t); |
|
39 |
extern float128_t STX_asinq(float128_t); |
|
40 |
extern float128_t STX_acosq(float128_t); |
|
41 |
extern float128_t STX_atanq(float128_t); |
|
42 |
extern float128_t STX_asinhq(float128_t); |
|
43 |
extern float128_t STX_acoshq(float128_t); |
|
44 |
extern float128_t STX_atanhq(float128_t); |
|
45 |
extern float128_t STX_qZero; |
|
46 |
extern float128_t STX_dbltoq(double); |
|
47 |
extern float128_t STX_inttoq(long); |
|
48 |
extern double STX_qtodbl(float128_t); |
|
49 |
extern int STX_isNanq(float128_t*); |
|
50 |
extern int STX_prcmpq(float128_t*, float128_t*); |
|
5013 | 51 |
|
5276 | 52 |
#define STX_isfiniteq(q) (!STX_isNanq(&(q)) && !STX_isInfq(&(q))) |
53 |
#define STX_eqq(x1, x2) (STX_prcmpq (&(x1), &(x2)) == 0) |
|
54 |
#define STX_neqq(x1, x2) (STX_prcmpq (&(x1), &(x2)) != 0) |
|
55 |
#define STX_gtq(x1, x2) (STX_prcmpq (&(x1), &(x2)) > 0) |
|
56 |
#define STX_geq(x1, x2) (STX_prcmpq (&(x1), &(x2)) >= 0) |
|
57 |
#define STX_ltq(x1, x2) (STX_prcmpq (&(x1), &(x2)) < 0) |
|
58 |
#define STX_leq(x1, x2) (STX_prcmpq (&(x1), &(x2)) <= 0) |
|
4992 | 59 |
|
5276 | 60 |
#ifdef __win32__ |
61 |
/* |
|
62 |
* no finite(x) ? |
|
63 |
* no isnan(x) ? |
|
64 |
*/ |
|
65 |
# ifndef isnan |
|
66 |
# define isnan(x) \ |
|
67 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
68 |
(((unsigned int *)(&x))[1] == 0xFFF80000)) |
|
69 |
# endif |
|
4992 | 70 |
|
5276 | 71 |
# ifndef isPositiveInfinity |
72 |
# define isPositiveInfinity(x) \ |
|
73 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
74 |
(((unsigned int *)(&x))[1] == 0x7FF00000)) |
|
75 |
# endif |
|
4992 | 76 |
|
5276 | 77 |
# ifndef isNegativeInfinity |
78 |
# define isNegativeInfinity(x) \ |
|
79 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
80 |
(((unsigned int *)(&x))[1] == 0xFFF00000)) |
|
81 |
# endif |
|
5014 | 82 |
|
5276 | 83 |
# ifndef isinf |
84 |
# define isinf(x) \ |
|
85 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
86 |
((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000)) |
|
87 |
# endif |
|
4992 | 88 |
|
5276 | 89 |
# ifndef isfinite |
90 |
# define isfinite(x) (!isinf(x) && !isnan(x)) |
|
91 |
# endif |
|
92 |
||
93 |
#else // not win32 |
|
5269
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
94 |
#endif |
4993 | 95 |
|
4992 | 96 |
%} |
97 |
! ! |
|
98 |
||
99 |
!QuadFloat primitiveVariables! |
|
5267 | 100 |
%{ |
101 |
%} |
|
4991 | 102 |
! ! |
103 |
||
4992 | 104 |
!QuadFloat primitiveFunctions! |
5267 | 105 |
%{ |
106 |
%} |
|
4992 | 107 |
! ! |
4991 | 108 |
|
4983 | 109 |
!QuadFloat class methodsFor:'documentation'! |
110 |
||
111 |
documentation |
|
112 |
" |
|
113 |
QuadFloats represent rational numbers with limited precision |
|
5007 | 114 |
and are mapped to IEEE quadruple precision format (128bit), |
115 |
also called binary128. |
|
116 |
||
4983 | 117 |
If the underlying cpu supports them natively, the machine format (long double) is |
118 |
used. Otherwise, a software emulation is done, which is much slower. |
|
119 |
Thus only use them, if you really need the additional precision; |
|
120 |
if not, use Float (which are doubles) or LongFloats which usually have IEEE extended precision (80bit). |
|
121 |
||
122 |
QuadFloats give you definite 128 bit quadruple floats, |
|
123 |
thus, code using quadFloats is guaranteed to be portable from one architecture to another. |
|
124 |
||
125 |
Representation: |
|
4991 | 126 |
128bit quadruple IEEE floats (16bytes); |
127 |
112 bit mantissa, |
|
128 |
16 bit exponent, |
|
129 |
34 decimal digits (approx.) |
|
4983 | 130 |
|
4992 | 131 |
On Sparc CPUs, this is a native supported type (long double) and fast; |
132 |
on x86 CPUs, this is emulated and slow. |
|
133 |
||
4983 | 134 |
Mixed mode arithmetic: |
5007 | 135 |
quadFloat op anyFloat -> quadFloat |
136 |
anyFloat op quadFloat -> quadFloat |
|
4983 | 137 |
|
138 |
Range and precision of storage formats: see LimitedPrecisionReal >> documentation |
|
139 |
||
140 |
[author:] |
|
4991 | 141 |
Claus Gittinger |
4983 | 142 |
|
143 |
[see also:] |
|
4991 | 144 |
Number |
145 |
Float ShortFloat LongFloat Fraction FixedPoint Integer Complex |
|
146 |
FloatArray DoubleArray |
|
147 |
https://en.wikipedia.org/wiki/Extended_precision |
|
4983 | 148 |
" |
149 |
! ! |
|
150 |
||
151 |
!QuadFloat class methodsFor:'instance creation'! |
|
152 |
||
153 |
basicNew |
|
154 |
"return a new quadFloat - here we return 0.0 |
|
155 |
- QuadFloats are usually NOT created this way ... |
|
156 |
Its implemented here to allow things like binary store & load |
|
157 |
of quadFloats. |
|
158 |
(but it is not a good idea to store the bits of a float - the reader might have a |
|
159 |
totally different representation - so floats should be |
|
160 |
binary stored in a device independent format)." |
|
161 |
||
162 |
%{ /* NOCONTEXT */ |
|
4993 | 163 |
#ifdef SUPPORT_QUADFLOAT |
4983 | 164 |
OBJ newFloat; |
4991 | 165 |
|
166 |
if (sizeof(long double) == sizeof(float128_t)) { |
|
167 |
__qMKLFLOAT(newFloat, 0.0); /* OBJECT ALLOCATION */ |
|
4983 | 168 |
} else { |
5276 | 169 |
float128_t qf = STX_qZero; |
4991 | 170 |
__qMKQFLOAT(newFloat, qf); /* OBJECT ALLOCATION */ |
4983 | 171 |
} |
172 |
RETURN (newFloat); |
|
4993 | 173 |
#endif /* SUPPORT_QUADFLOAT */ |
174 |
%}. |
|
175 |
self error:'QuadFloats not supported on this patform' |
|
4983 | 176 |
|
177 |
"Created: / 06-06-2019 / 17:18:58 / Claus Gittinger" |
|
178 |
! |
|
179 |
||
180 |
fromFloat:aFloat |
|
181 |
"return a new quadFloat, given a float value" |
|
182 |
||
183 |
%{ /* NOCONTEXT */ |
|
4993 | 184 |
#ifdef SUPPORT_QUADFLOAT |
4983 | 185 |
OBJ newFloat; |
186 |
||
187 |
if (__isFloatLike(aFloat)) { |
|
5276 | 188 |
double f = __floatVal(aFloat); |
4991 | 189 |
float128_t qf; |
190 |
||
5276 | 191 |
qf = STX_dbltoq (f); |
4991 | 192 |
__qMKQFLOAT(newFloat, qf); /* OBJECT ALLOCATION */ |
193 |
RETURN (newFloat); |
|
4983 | 194 |
} |
5287 | 195 |
#endif /* |
196 |
*/ |
|
4983 | 197 |
%}. |
4993 | 198 |
aFloat isFloat ifTrue:[ |
4997 | 199 |
self errorUnsupported |
4993 | 200 |
]. |
4997 | 201 |
ArgumentError raise |
4983 | 202 |
|
203 |
" |
|
204 |
QuadFloat fromFloat:123.0 |
|
205 |
123.0 asQuadFloat |
|
206 |
123 asQuadFloat |
|
207 |
" |
|
208 |
||
209 |
"Created: / 06-06-2019 / 18:01:03 / Claus Gittinger" |
|
5011 | 210 |
! |
211 |
||
5017 | 212 |
fromInteger:anInteger |
213 |
"return a new quadFloat, given an integer value" |
|
214 |
||
215 |
%{ /* NOCONTEXT */ |
|
216 |
#ifdef SUPPORT_QUADFLOAT |
|
217 |
OBJ newFloat; |
|
218 |
||
219 |
if (__isSmallInteger(anInteger)) { |
|
220 |
INT iVal = __intVal(anInteger); |
|
221 |
float128_t qf; |
|
222 |
||
5276 | 223 |
qf = STX_inttoq( (long)iVal ); |
5017 | 224 |
__qMKQFLOAT(newFloat, qf); /* OBJECT ALLOCATION */ |
225 |
RETURN (newFloat); |
|
226 |
} |
|
227 |
#endif /* SUPPORT_QUADFLOAT */ |
|
228 |
%}. |
|
229 |
^ super fromInteger:anInteger |
|
230 |
||
231 |
" |
|
232 |
QuadFloat fromInteger:123 |
|
233 |
123 asQuadFloat |
|
234 |
" |
|
235 |
! |
|
236 |
||
5014 | 237 |
fromLongFloat:aFloat |
238 |
"return a new quadFloat, given a long float value" |
|
239 |
||
240 |
%{ /* NOCONTEXT */ |
|
5276 | 241 |
#ifdef xSUPPORT_QUADFLOAT |
5014 | 242 |
OBJ newFloat; |
243 |
union { |
|
244 |
LONGFLOAT_t lf; // is long double |
|
245 |
extFloat80_t ef; // is 80bit ext |
|
246 |
float128_t qf; // is 128bit quad |
|
247 |
} u; |
|
248 |
||
249 |
if (__isLongFloat(aFloat)) { |
|
250 |
u.lf = __longFloatVal(aFloat); |
|
251 |
||
252 |
if (sizeof(LONGFLOAT_t) == 16) { |
|
253 |
// longFloat is already 128 bits in size (sparc) |
|
254 |
__qMKQFLOAT(newFloat, u.qf); /* OBJECT ALLOCATION */ |
|
255 |
RETURN (newFloat); |
|
256 |
} |
|
257 |
if (sizeof(LONGFLOAT_t) < 16) { |
|
258 |
// assume 80bit extended float format (amd64, x86_64) |
|
259 |
u.qf = extF80_to_f128( u.ef); |
|
260 |
__qMKQFLOAT(newFloat, u.qf); /* OBJECT ALLOCATION */ |
|
261 |
RETURN (newFloat); |
|
262 |
} |
|
263 |
// fall into error case |
|
264 |
} |
|
265 |
#endif /* SUPPORT_QUADFLOAT */ |
|
266 |
%}. |
|
267 |
aFloat isLongFloat ifTrue:[ |
|
268 |
self errorUnsupported |
|
269 |
]. |
|
270 |
ArgumentError raise |
|
271 |
||
272 |
" |
|
273 |
QuadFloat fromLongFloat:123.0 asLongFloat |
|
274 |
" |
|
275 |
! |
|
276 |
||
5011 | 277 |
fromShortFloat:aShortFloat |
278 |
"return a new quadFloat, given a float value" |
|
279 |
||
5013 | 280 |
^ self fromFloat:(aShortFloat asFloat) |
5011 | 281 |
|
282 |
" |
|
283 |
QuadFloat fromShortFloat:123.0 asShortFloat |
|
284 |
" |
|
285 |
||
286 |
"Created: / 08-06-2019 / 03:28:37 / Claus Gittinger" |
|
4983 | 287 |
! ! |
288 |
||
289 |
!QuadFloat class methodsFor:'coercing & converting'! |
|
290 |
||
291 |
coerce:aNumber |
|
292 |
"convert the argument aNumber into an instance of the receiver's class and return it." |
|
293 |
||
294 |
^ aNumber asQuadFloat. |
|
295 |
||
296 |
"Created: / 06-06-2019 / 16:51:01 / Claus Gittinger" |
|
297 |
! ! |
|
298 |
||
299 |
!QuadFloat class methodsFor:'constants'! |
|
300 |
||
301 |
NaN |
|
5011 | 302 |
"return a quadFloat which represents not-a-Number (i.e. an invalid number)" |
303 |
||
304 |
|nan| |
|
4983 | 305 |
|
306 |
NaN isNil ifTrue:[ |
|
5011 | 307 |
%{ /* NOCONTEXT */ |
5276 | 308 |
#ifdef xSUPPORT_QUADFLOAT |
5011 | 309 |
{ |
310 |
OBJ newFloat; |
|
311 |
float128_t qf; |
|
312 |
||
5014 | 313 |
softfloat_commonNaNToF128M( (uint32_t*)(&qf) ); |
5011 | 314 |
__qMKQFLOAT(newFloat, qf); /* OBJECT ALLOCATION */ |
315 |
nan = newFloat; |
|
316 |
} |
|
317 |
#endif /* SUPPORT_QUADFLOAT */ |
|
318 |
%}. |
|
5287 | 319 |
nan isNil ifTrue:[ |
320 |
self errorUnsupported |
|
321 |
]. |
|
5011 | 322 |
NaN := nan |
4983 | 323 |
]. |
324 |
^ NaN |
|
325 |
! |
|
326 |
||
327 |
e |
|
328 |
"return the constant e as quadFloat" |
|
329 |
||
330 |
E isNil ifTrue:[ |
|
4991 | 331 |
"/ eDigits has enough digits for 128bit IEEE quads |
332 |
"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here... |
|
333 |
E := self readFrom:(Number eDigits) |
|
4983 | 334 |
]. |
335 |
^ E |
|
336 |
||
337 |
"Created: / 06-06-2019 / 17:01:54 / Claus Gittinger" |
|
338 |
! |
|
339 |
||
5017 | 340 |
infinity |
341 |
"return a quadFloat which represents +INF" |
|
342 |
||
343 |
|inf| |
|
344 |
||
345 |
PositiveInfinity isNil ifTrue:[ |
|
346 |
%{ /* NOCONTEXT */ |
|
5276 | 347 |
#ifdef xSUPPORT_QUADFLOAT |
5017 | 348 |
{ |
349 |
OBJ newFloat; |
|
350 |
struct uint128 uiZ; |
|
351 |
union ui128_f128 uZ; |
|
352 |
float128_t qf; |
|
353 |
||
354 |
uiZ.v64 = packToF128UI64( 0, 0x7FFF, 0 ); |
|
355 |
uiZ.v0 = 0; |
|
356 |
uZ.ui = uiZ; |
|
357 |
qf = uZ.f; |
|
358 |
__qMKQFLOAT(newFloat, qf); /* OBJECT ALLOCATION */ |
|
359 |
inf = newFloat; |
|
360 |
} |
|
361 |
#endif /* SUPPORT_QUADFLOAT */ |
|
362 |
%}. |
|
5287 | 363 |
inf isNil ifTrue:[ |
364 |
self errorUnsupported |
|
365 |
]. |
|
5017 | 366 |
PositiveInfinity := inf |
367 |
]. |
|
368 |
^ PositiveInfinity |
|
369 |
||
370 |
"Created: / 08-06-2019 / 14:05:26 / Claus Gittinger" |
|
371 |
! |
|
372 |
||
5012 | 373 |
negativeInfinity |
374 |
"return a quadFloat which represents -INF" |
|
375 |
||
376 |
|inf| |
|
377 |
||
378 |
NegativeInfinity isNil ifTrue:[ |
|
379 |
%{ /* NOCONTEXT */ |
|
5276 | 380 |
#ifdef xSUPPORT_QUADFLOAT |
5013 | 381 |
{ |
382 |
OBJ newFloat; |
|
383 |
struct uint128 uiZ; |
|
384 |
union ui128_f128 uZ; |
|
385 |
float128_t qf; |
|
5012 | 386 |
|
5013 | 387 |
uiZ.v64 = packToF128UI64( 1, 0x7FFF, 0 ); |
388 |
uiZ.v0 = 0; |
|
389 |
uZ.ui = uiZ; |
|
390 |
qf = uZ.f; |
|
391 |
__qMKQFLOAT(newFloat, qf); /* OBJECT ALLOCATION */ |
|
392 |
inf = newFloat; |
|
393 |
} |
|
5012 | 394 |
#endif /* SUPPORT_QUADFLOAT */ |
395 |
%}. |
|
5287 | 396 |
inf isNil ifTrue:[ |
397 |
self errorUnsupported |
|
398 |
]. |
|
5013 | 399 |
NegativeInfinity := inf |
5012 | 400 |
]. |
401 |
^ NegativeInfinity |
|
402 |
||
403 |
"Created: / 08-06-2019 / 14:05:50 / Claus Gittinger" |
|
404 |
! |
|
405 |
||
5264 | 406 |
phi |
407 |
"return the constant phi as quadFloat" |
|
408 |
||
409 |
Phi isNil ifTrue:[ |
|
5276 | 410 |
"/ phiDigits has enough digits for 128bit IEEE quads |
411 |
"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here... |
|
412 |
Phi := self readFrom:(Number phiDigits) |
|
5264 | 413 |
]. |
414 |
^ Phi |
|
415 |
! |
|
416 |
||
4983 | 417 |
pi |
418 |
"return the constant pi as quadFloat" |
|
419 |
||
420 |
Pi isNil ifTrue:[ |
|
4991 | 421 |
"/ piDigits has enough digits for 128bit IEEE quads |
422 |
"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here... |
|
423 |
Pi := self readFrom:(Number piDigits) |
|
4983 | 424 |
]. |
425 |
^ Pi |
|
426 |
||
427 |
"Created: / 06-06-2019 / 17:09:51 / Claus Gittinger" |
|
5006 | 428 |
! |
429 |
||
430 |
unity |
|
431 |
"return the neutral element for multiplication (1.0) as QuadFloat" |
|
432 |
||
433 |
QuadFloatOne isNil ifTrue:[ |
|
5007 | 434 |
QuadFloatOne := 1.0 asQuadFloat. |
5006 | 435 |
]. |
436 |
^ QuadFloatOne |
|
437 |
||
438 |
"Created: / 07-06-2019 / 03:26:38 / Claus Gittinger" |
|
5008 | 439 |
! |
440 |
||
441 |
zero |
|
442 |
"return the neutral element for addition (0.0) as QuadFloat" |
|
443 |
||
444 |
QuadFloatZero isNil ifTrue:[ |
|
5011 | 445 |
QuadFloatZero := 0.0 asQuadFloat |
5008 | 446 |
]. |
447 |
^ QuadFloatZero |
|
448 |
||
449 |
"Created: / 07-06-2019 / 09:22:56 / Claus Gittinger" |
|
4983 | 450 |
! ! |
451 |
||
5003 | 452 |
!QuadFloat class methodsFor:'error reportng'! |
4994 | 453 |
|
4997 | 454 |
errorUnsupported |
455 |
self error:'QuadFloats not supported on this patform' |
|
456 |
||
5003 | 457 |
"Created: / 07-06-2019 / 02:44:39 / Claus Gittinger" |
4994 | 458 |
! ! |
459 |
||
5005 | 460 |
!QuadFloat class methodsFor:'queries'! |
461 |
||
5017 | 462 |
epsilon |
463 |
"return the maximum relative spacing of instances of mySelf |
|
464 |
(i.e. the value-delta of the least significant bit)" |
|
465 |
||
466 |
Epsilon isNil ifTrue:[ |
|
5020 | 467 |
Epsilon := self computeEpsilon. |
5017 | 468 |
]. |
469 |
^ Epsilon |
|
470 |
||
471 |
" |
|
472 |
self epsilon |
|
473 |
" |
|
474 |
||
475 |
"Created: / 10-06-2019 / 21:21:18 / Claus Gittinger" |
|
476 |
! |
|
477 |
||
5018 | 478 |
exponentCharacter |
479 |
"return the character used to print between mantissa an exponent. |
|
480 |
Also used by the scanner when reading numbers." |
|
481 |
||
482 |
^ $Q |
|
483 |
||
484 |
"Created: / 10-06-2019 / 21:28:04 / Claus Gittinger" |
|
485 |
! |
|
486 |
||
5025 | 487 |
numBitsInExponent |
5276 | 488 |
"answer the number of bits in the exponent. |
489 |
This is an IEEE 128bit quadfloat, where 15 bits are available in the exponent: |
|
5287 | 490 |
seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm... |
5025 | 491 |
" |
492 |
||
493 |
^ 15 |
|
494 |
||
495 |
" |
|
496 |
1.0 class numBitsInExponent -> 11 |
|
497 |
1.0 asShortFloat class numBitsInExponent -> 8 |
|
498 |
1.0 asLongFloat class numBitsInExponent -> 15 |
|
499 |
1.0 asQuadFloat class numBitsInExponent -> 15 |
|
500 |
" |
|
501 |
||
502 |
"Created: / 11-06-2019 / 00:14:55 / Claus Gittinger" |
|
503 |
! |
|
504 |
||
5005 | 505 |
numBitsInMantissa |
506 |
"answer the number of bits in the mantissa |
|
507 |
the hidden bit is not counted here: |
|
508 |
||
509 |
This is an 128bit quadfloat, |
|
5007 | 510 |
where 112 bits are available in the mantissa: |
511 |
seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm... |
|
5005 | 512 |
" |
513 |
||
514 |
^ 112 |
|
515 |
||
516 |
" |
|
517 |
1.0 class numBitsInMantissa |
|
518 |
1.0 asShortFloat class numBitsInMantissa |
|
519 |
1.0 asLongFloat class numBitsInMantissa |
|
520 |
1.0 asQuadFloat class numBitsInMantissa |
|
521 |
" |
|
522 |
||
523 |
"Created: / 07-06-2019 / 03:24:20 / Claus Gittinger" |
|
5056 | 524 |
! |
525 |
||
526 |
radix |
|
527 |
"answer the radix of a QuadFloat's exponent |
|
528 |
This is an IEEE float, which is represented as binary" |
|
529 |
||
530 |
^ 2 "must be careful here, whenever ST/X is used on VAX or a 370" |
|
531 |
||
532 |
"Created: / 19-07-2019 / 17:28:00 / Claus Gittinger" |
|
5005 | 533 |
! ! |
534 |
||
4994 | 535 |
!QuadFloat methodsFor:'arithmetic'! |
536 |
||
537 |
* aNumber |
|
538 |
"return the product of the receiver and the argument." |
|
539 |
||
5074 | 540 |
aNumber class == QuadFloat ifTrue:[ |
5276 | 541 |
^ aNumber productFromQuadFloat:self |
5074 | 542 |
]. |
543 |
||
5075 | 544 |
thisContext isReallyRecursive ifTrue:[self error]. |
4994 | 545 |
^ aNumber productFromQuadFloat:self |
546 |
! |
|
547 |
||
548 |
+ aNumber |
|
549 |
"return the sum of the receiver and the argument, aNumber" |
|
550 |
||
551 |
^ aNumber sumFromQuadFloat:self |
|
552 |
! |
|
553 |
||
554 |
- aNumber |
|
555 |
"return the difference of the receiver and the argument, aNumber" |
|
556 |
||
557 |
^ aNumber differenceFromQuadFloat:self |
|
558 |
! |
|
559 |
||
560 |
/ aNumber |
|
561 |
"return the quotient of the receiver and the argument, aNumber" |
|
562 |
||
563 |
aNumber isZero ifTrue:[ |
|
564 |
" |
|
565 |
No, you shalt not divide by zero |
|
566 |
" |
|
567 |
^ ZeroDivide raiseRequestWith:thisContext. |
|
568 |
]. |
|
569 |
^ aNumber quotientFromQuadFloat:self |
|
570 |
! |
|
571 |
||
5276 | 572 |
abs |
573 |
"return the absolute value of the receiver |
|
574 |
reimplemented here for speed" |
|
575 |
||
576 |
%{ /* NOCONTEXT */ |
|
577 |
#ifdef SUPPORT_QUADFLOAT |
|
578 |
OBJ newFloat; |
|
579 |
float128_t result, myVal; |
|
580 |
||
581 |
myVal = __quadFloatVal(self); |
|
582 |
result = STX_absq(myVal); |
|
583 |
__qMKQFLOAT(newFloat, result); |
|
584 |
RETURN ( newFloat ); |
|
585 |
#endif |
|
586 |
%}. |
|
587 |
! |
|
588 |
||
589 |
ceiling |
|
590 |
"return the smallest integer which is greater or equal to the receiver." |
|
591 |
||
592 |
|val| |
|
593 |
||
594 |
%{ |
|
5287 | 595 |
#ifdef SUPPORT_QUADFLOAT |
5276 | 596 |
float128_t qVal; |
597 |
float128_t qMinInt; |
|
598 |
float128_t qMaxInt; |
|
599 |
||
600 |
qVal = __quadFloatVal(self); |
|
601 |
qVal = STX_ceilq(qVal); |
|
602 |
||
603 |
qMinInt = STX_dbltoq((double)_MIN_INT); |
|
604 |
qMaxInt = STX_dbltoq((double)_MAX_INT); |
|
605 |
if (STX_geq(qVal, qMinInt) && STX_leq(qVal, qMaxInt)) { |
|
606 |
double dVal = STX_qtodbl(qVal); |
|
607 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
|
608 |
} |
|
609 |
__qMKQFLOAT(val, qVal); |
|
5287 | 610 |
#endif |
5276 | 611 |
%}. |
612 |
^ val asInteger |
|
613 |
||
614 |
" |
|
615 |
0.5 asQuadFloat ceiling |
|
616 |
0.5 asQuadFloat ceilingAsFloat |
|
617 |
-0.5 asQuadFloat ceiling |
|
618 |
-0.5 asQuadFloat ceilingAsFloat |
|
619 |
" |
|
620 |
! |
|
621 |
||
622 |
ceilingAsFloat |
|
623 |
"return the smallest integer-valued float greater or equal to the receiver. |
|
624 |
This is much like #ceiling, but avoids a (possibly expensive) conversion |
|
625 |
of the result to an integer. |
|
626 |
It may be useful, if the result is to be further used in another float-operation." |
|
627 |
||
628 |
%{ /* NOCONTEXT */ |
|
629 |
#ifdef SUPPORT_QUADFLOAT |
|
630 |
OBJ newFloat; |
|
631 |
float128_t result, myVal; |
|
632 |
||
633 |
myVal = __quadFloatVal(self); |
|
634 |
result = STX_ceilq(myVal); |
|
635 |
__qMKQFLOAT(newFloat, result); |
|
636 |
RETURN ( newFloat ); |
|
637 |
#endif |
|
638 |
%}. |
|
639 |
! |
|
640 |
||
641 |
cos |
|
642 |
"return the cosine of the receiver (interpreted as radians)" |
|
643 |
||
644 |
%{ /* NOCONTEXT */ |
|
645 |
#ifdef SUPPORT_QUADFLOAT |
|
646 |
OBJ newFloat; |
|
647 |
float128_t result, myVal; |
|
648 |
||
649 |
myVal = __quadFloatVal(self); |
|
650 |
result = STX_cosq(myVal); |
|
651 |
__qMKQFLOAT(newFloat, result); |
|
652 |
RETURN ( newFloat ); |
|
653 |
#endif |
|
654 |
%}. |
|
655 |
! |
|
656 |
||
657 |
cosh |
|
658 |
"return the hyperbolic cosine of the receiver (interpreted as radians)" |
|
659 |
||
660 |
%{ /* NOCONTEXT */ |
|
661 |
#ifdef SUPPORT_QUADFLOAT |
|
662 |
OBJ newFloat; |
|
663 |
float128_t result, myVal; |
|
664 |
||
665 |
myVal = __quadFloatVal(self); |
|
666 |
result = STX_coshq(myVal); |
|
667 |
__qMKQFLOAT(newFloat, result); |
|
668 |
RETURN ( newFloat ); |
|
669 |
#endif |
|
670 |
%}. |
|
671 |
! |
|
672 |
||
673 |
exp |
|
674 |
"return e raised to the power of the receiver" |
|
675 |
||
676 |
%{ /* NOCONTEXT */ |
|
677 |
#ifdef SUPPORT_QUADFLOAT |
|
678 |
OBJ newFloat; |
|
679 |
float128_t result, myVal; |
|
680 |
||
681 |
myVal = __quadFloatVal(self); |
|
682 |
result = STX_expq(myVal); |
|
683 |
__qMKQFLOAT(newFloat, result); |
|
684 |
RETURN ( newFloat ); |
|
685 |
#endif |
|
686 |
%}. |
|
687 |
! |
|
688 |
||
689 |
exponent |
|
690 |
"extract a normalized float's (unbiased) exponent. |
|
691 |
The returned value depends on the float-representation of |
|
692 |
the underlying machine and is therefore highly unportable. |
|
693 |
This is not for general use. |
|
694 |
This assumes that the mantissa is normalized to |
|
695 |
0.5 .. 1.0 and the float's value is: mantissa * 2^exp" |
|
696 |
||
697 |
%{ /* NOCONTEXT */ |
|
5287 | 698 |
#ifdef SUPPORT_QUADFLOAT |
5276 | 699 |
float128_t myVal; |
700 |
float128_t frac; |
|
701 |
int exp; |
|
702 |
||
703 |
myVal = __quadFloatVal(self); |
|
704 |
#if 1 |
|
705 |
// should we? |
|
706 |
if (! (STX_isNanq(&myVal) || STX_isInfq(&myVal))) |
|
707 |
#endif |
|
708 |
{ |
|
5287 | 709 |
frac = STX_frexpq(myVal, &exp); |
710 |
RETURN (__mkSmallInteger(exp)); |
|
5276 | 711 |
} |
5287 | 712 |
#endif |
5276 | 713 |
%}. |
714 |
^ super exponent |
|
715 |
||
716 |
" |
|
717 |
1.0 exponent |
|
718 |
1.0 asQuadFloat exponent |
|
719 |
2.0 exponent |
|
720 |
2.0 asQuadFloat exponent |
|
721 |
3.0 exponent |
|
722 |
3.0 asQuadFloat exponent |
|
723 |
4.0 exponent |
|
724 |
4.0 asQuadFloat exponent |
|
725 |
0.5 exponent |
|
726 |
0.5 asQuadFloat exponent |
|
727 |
0.4 exponent |
|
728 |
0.4 asQuadFloat exponent |
|
729 |
0.25 exponent |
|
730 |
0.25 asQuadFloat exponent |
|
731 |
0.2 exponent |
|
732 |
0.2 asQuadFloat exponent |
|
733 |
0.00000011111 exponent |
|
734 |
0.00000011111 asQuadFloat exponent |
|
735 |
0.0 exponent |
|
736 |
0.0 asQuadFloat exponent |
|
737 |
||
738 |
1e1000 exponent -> error (INF) |
|
739 |
1e1000 asQuadFloat exponent -> error (INF) |
|
740 |
" |
|
741 |
! |
|
742 |
||
743 |
floor |
|
744 |
"return the integer nearest the receiver towards negative infinity." |
|
745 |
||
746 |
|val| |
|
747 |
||
748 |
%{ |
|
5287 | 749 |
#ifdef SUPPORT_QUADFLOAT |
5276 | 750 |
float128_t qVal; |
751 |
float128_t qMinInt; |
|
752 |
float128_t qMaxInt; |
|
753 |
||
754 |
qVal = __quadFloatVal(self); |
|
755 |
qVal = STX_floorq(qVal); |
|
756 |
||
757 |
qMinInt = STX_dbltoq((double)_MIN_INT); |
|
758 |
qMaxInt = STX_dbltoq((double)_MAX_INT); |
|
759 |
if (STX_geq(qVal, qMinInt) && STX_leq(qVal, qMaxInt)) { |
|
760 |
double dVal = STX_qtodbl(qVal); |
|
761 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
|
762 |
} |
|
763 |
__qMKQFLOAT(val, qVal); |
|
5287 | 764 |
#endif |
5276 | 765 |
%}. |
766 |
^ val asInteger |
|
767 |
||
768 |
" |
|
769 |
0.5 asQuadFloat floor |
|
770 |
0.5 asQuadFloat floorAsFloat |
|
771 |
-0.5 asQuadFloat floor |
|
772 |
-0.5 asQuadFloat floorAsFloat |
|
773 |
" |
|
774 |
! |
|
775 |
||
776 |
floorAsFloat |
|
777 |
"return the integer nearest the receiver towards negative infinity as a float. |
|
778 |
This is much like #floor, but avoids a (possibly expensive) conversion |
|
779 |
of the result to an integer. |
|
780 |
It may be useful, if the result is to be further used in another float-operation." |
|
781 |
||
782 |
%{ /* NOCONTEXT */ |
|
783 |
#ifdef SUPPORT_QUADFLOAT |
|
784 |
OBJ newFloat; |
|
785 |
float128_t result, myVal; |
|
786 |
||
787 |
myVal = __quadFloatVal(self); |
|
788 |
result = STX_floorq(myVal); |
|
789 |
__qMKQFLOAT(newFloat, result); |
|
790 |
RETURN ( newFloat ); |
|
791 |
#endif |
|
792 |
%}. |
|
793 |
! |
|
794 |
||
795 |
ln |
|
796 |
"return natural logarithm of the receiver." |
|
797 |
||
798 |
%{ /* NOCONTEXT */ |
|
799 |
#ifdef SUPPORT_QUADFLOAT |
|
800 |
OBJ newFloat; |
|
801 |
float128_t result, myVal; |
|
802 |
||
803 |
myVal = __quadFloatVal(self); |
|
804 |
result = STX_logq(myVal); |
|
805 |
__qMKQFLOAT(newFloat, result); |
|
806 |
RETURN ( newFloat ); |
|
807 |
#endif |
|
808 |
%}. |
|
809 |
! |
|
810 |
||
811 |
log |
|
812 |
"return log base 10 of the receiver. |
|
813 |
Alias for log:10." |
|
814 |
||
815 |
%{ /* NOCONTEXT */ |
|
816 |
#ifdef SUPPORT_QUADFLOAT |
|
817 |
OBJ newFloat; |
|
818 |
float128_t result, myVal; |
|
819 |
||
820 |
myVal = __quadFloatVal(self); |
|
821 |
result = STX_log10q(myVal); |
|
822 |
__qMKQFLOAT(newFloat, result); |
|
823 |
RETURN ( newFloat ); |
|
824 |
#endif |
|
825 |
%}. |
|
826 |
! |
|
827 |
||
828 |
log2 |
|
829 |
"return logarithm dualis of the receiver." |
|
830 |
||
831 |
%{ /* NOCONTEXT */ |
|
832 |
#ifdef SUPPORT_QUADFLOAT |
|
833 |
OBJ newFloat; |
|
834 |
float128_t result, myVal; |
|
835 |
||
836 |
myVal = __quadFloatVal(self); |
|
837 |
result = STX_log2q(myVal); |
|
838 |
__qMKQFLOAT(newFloat, result); |
|
839 |
RETURN ( newFloat ); |
|
840 |
#endif |
|
841 |
%}. |
|
842 |
! |
|
843 |
||
844 |
mantissa |
|
845 |
"extract a normalized float's mantissa. |
|
846 |
The returned value depends on the float-representation of |
|
847 |
the underlying machine and is therefore highly unportable. |
|
848 |
This is not for general use. |
|
849 |
This assumes that the mantissa is normalized to |
|
850 |
0.5 .. 1.0 and the float's value is mantissa * 2^exp" |
|
851 |
||
852 |
%{ /* NOCONTEXT */ |
|
5287 | 853 |
#ifdef SUPPORT_QUADFLOAT |
5276 | 854 |
float128_t myVal; |
855 |
float128_t frac; |
|
856 |
int exp; |
|
857 |
OBJ newFloat; |
|
858 |
||
859 |
myVal = __quadFloatVal(self); |
|
860 |
// ouch: math libs seem to not care for NaN here; |
|
861 |
#if 1 |
|
862 |
// should we? |
|
863 |
if (! (STX_isNanq(&myVal) || STX_isInfq(&myVal))) |
|
864 |
#endif |
|
865 |
{ |
|
866 |
frac = STX_frexpq(myVal, &exp); |
|
867 |
__qMKQFLOAT(newFloat, frac); |
|
868 |
RETURN ( newFloat ); |
|
869 |
} |
|
5287 | 870 |
#endif |
5276 | 871 |
%}. |
872 |
^ super mantissa |
|
873 |
||
874 |
" |
|
875 |
1.0 exponent |
|
876 |
1.0 asQuadFloat exponent |
|
877 |
1.0 mantissa |
|
878 |
1.0 asQuadFloat mantissa |
|
879 |
||
880 |
0.25 exponent |
|
881 |
0.25 asQuadFloat exponent |
|
882 |
0.25 mantissa |
|
883 |
0.25 asQuadFloat mantissa |
|
884 |
||
885 |
0.00000011111 exponent |
|
886 |
0.00000011111 mantissa |
|
887 |
||
888 |
1e1000 mantissa |
|
889 |
" |
|
890 |
||
891 |
"Modified: / 20-06-2017 / 11:37:13 / cg" |
|
892 |
"Modified (comment): / 26-05-2019 / 03:12:55 / Claus Gittinger" |
|
893 |
! |
|
894 |
||
5021 | 895 |
negated |
896 |
"return the receiver negated" |
|
897 |
||
898 |
%{ /* NOCONTEXT */ |
|
899 |
#ifdef SUPPORT_QUADFLOAT |
|
900 |
OBJ newFloat; |
|
901 |
float128_t result, myVal; |
|
902 |
||
903 |
myVal = __quadFloatVal(self); |
|
5276 | 904 |
result = STX_negq(myVal); |
5021 | 905 |
__qMKQFLOAT(newFloat, result); |
906 |
RETURN ( newFloat ); |
|
907 |
#endif |
|
908 |
%}. |
|
5025 | 909 |
! |
910 |
||
911 |
rem: aNumber |
|
912 |
"return the floating point remainder of the receiver and the argument, aNumber" |
|
913 |
||
914 |
aNumber isZero ifTrue:[ |
|
915 |
" |
|
916 |
No, you shalt not divide by zero |
|
917 |
" |
|
918 |
^ ZeroDivide raiseRequestWith:thisContext. |
|
919 |
]. |
|
920 |
^ aNumber remainderFromLongFloat:self |
|
5276 | 921 |
! |
922 |
||
923 |
sin |
|
924 |
"return the sine of the receiver (interpreted as radians)" |
|
925 |
||
926 |
%{ /* NOCONTEXT */ |
|
927 |
#ifdef SUPPORT_QUADFLOAT |
|
928 |
OBJ newFloat; |
|
929 |
float128_t result, myVal; |
|
930 |
||
931 |
myVal = __quadFloatVal(self); |
|
932 |
result = STX_sinq(myVal); |
|
933 |
__qMKQFLOAT(newFloat, result); |
|
934 |
RETURN ( newFloat ); |
|
935 |
#endif |
|
936 |
%}. |
|
937 |
! |
|
938 |
||
939 |
sinh |
|
940 |
"return the hyperbolic sine of the receiver (interpreted as radians)" |
|
941 |
||
942 |
%{ /* NOCONTEXT */ |
|
943 |
#ifdef SUPPORT_QUADFLOAT |
|
944 |
OBJ newFloat; |
|
945 |
float128_t result, myVal; |
|
946 |
||
947 |
myVal = __quadFloatVal(self); |
|
948 |
result = STX_sinhq(myVal); |
|
949 |
__qMKQFLOAT(newFloat, result); |
|
950 |
RETURN ( newFloat ); |
|
951 |
#endif |
|
952 |
%}. |
|
953 |
! |
|
954 |
||
955 |
tan |
|
956 |
"return the tangent of the receiver (interpreted as radians)" |
|
957 |
||
958 |
%{ /* NOCONTEXT */ |
|
959 |
#ifdef SUPPORT_QUADFLOAT |
|
960 |
OBJ newFloat; |
|
961 |
float128_t result, myVal; |
|
962 |
||
963 |
myVal = __quadFloatVal(self); |
|
964 |
result = STX_tanq(myVal); |
|
965 |
__qMKQFLOAT(newFloat, result); |
|
966 |
RETURN ( newFloat ); |
|
967 |
#endif |
|
968 |
%}. |
|
969 |
! |
|
970 |
||
971 |
tanh |
|
972 |
"return the hyperbolic tangent of the receiver (interpreted as radians)" |
|
973 |
||
974 |
%{ /* NOCONTEXT */ |
|
975 |
#ifdef SUPPORT_QUADFLOAT |
|
976 |
OBJ newFloat; |
|
977 |
float128_t result, myVal; |
|
978 |
||
979 |
myVal = __quadFloatVal(self); |
|
980 |
result = STX_tanhq(myVal); |
|
981 |
__qMKQFLOAT(newFloat, result); |
|
982 |
RETURN ( newFloat ); |
|
983 |
#endif |
|
984 |
%}. |
|
4994 | 985 |
! ! |
986 |
||
5008 | 987 |
!QuadFloat methodsFor:'coercing & converting'! |
988 |
||
5276 | 989 |
asFloat |
990 |
"return a Float with same value as the receiver. |
|
991 |
Raises an error if the receiver exceeds the float range." |
|
992 |
||
993 |
%{ /* NOCONTEXT */ |
|
994 |
#ifdef SUPPORT_QUADFLOAT |
|
995 |
OBJ newFloat; |
|
996 |
float128_t qVal = __quadFloatVal(self); |
|
997 |
double dVal = STX_qtodbl(qVal); |
|
998 |
||
999 |
if (isfinite(dVal) || !STX_isfiniteq(qVal)) { |
|
5287 | 1000 |
__qMKFLOAT(newFloat, dVal); |
1001 |
RETURN ( newFloat ); |
|
5276 | 1002 |
} |
1003 |
#endif |
|
1004 |
%}. |
|
1005 |
" |
|
1006 |
value out of range |
|
1007 |
if you need -INF for a zero receiver, try Number trapInfinity:[...] |
|
1008 |
" |
|
1009 |
^ self class |
|
5287 | 1010 |
raise:#infiniteResultSignal |
1011 |
receiver:self |
|
1012 |
selector:#asFloat |
|
1013 |
arguments:#() |
|
1014 |
errorString:'receiver is out of the double-precision float range' |
|
5276 | 1015 |
|
1016 |
" |
|
1017 |
1.0 asQuadFloat asFloat |
|
1018 |
" |
|
1019 |
! |
|
1020 |
||
5008 | 1021 |
generality |
1022 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
1023 |
||
1024 |
^ 93 |
|
1025 |
||
1026 |
"Created: / 07-06-2019 / 09:30:58 / Claus Gittinger" |
|
1027 |
! ! |
|
1028 |
||
1029 |
!QuadFloat methodsFor:'comparing'! |
|
1030 |
||
1031 |
< aNumber |
|
1032 |
"return true, if the argument is greater" |
|
1033 |
||
1034 |
^ aNumber lessFromQuadFloat:self |
|
1035 |
||
1036 |
"Created: / 07-06-2019 / 09:25:47 / Claus Gittinger" |
|
1037 |
! |
|
1038 |
||
1039 |
= aNumber |
|
1040 |
"return true, if the argument represents the same numeric value |
|
1041 |
as the receiver, false otherwise" |
|
1042 |
||
1043 |
^ aNumber equalFromQuadFloat:self |
|
1044 |
||
1045 |
"Created: / 07-06-2019 / 09:25:27 / Claus Gittinger" |
|
1046 |
! |
|
1047 |
||
1048 |
hash |
|
1049 |
"return a number for hashing; redefined, since floats compare |
|
1050 |
by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same |
|
1051 |
as 3 hash." |
|
1052 |
||
1053 |
|i| |
|
1054 |
||
1055 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
5011 | 1056 |
i := self asInteger. |
1057 |
self = i ifTrue:[ |
|
1058 |
^ i hash |
|
1059 |
]. |
|
5008 | 1060 |
]. |
1061 |
||
1062 |
^ self asFloat hash |
|
1063 |
||
1064 |
" |
|
1065 |
1.2345 hash |
|
1066 |
1.2345 asShortFloat hash |
|
1067 |
1.2345 asLongFloat hash |
|
1068 |
1.2345 asQuadFloat hash |
|
5011 | 1069 |
|
5008 | 1070 |
1.0 hash |
1071 |
1.0 asShortFloat hash |
|
1072 |
1.0 asLongFloat hash |
|
1073 |
1.0 asQuadFloat hash |
|
5011 | 1074 |
|
5008 | 1075 |
0.5 asShortFloat hash |
1076 |
0.5 asShortFloat hash |
|
1077 |
0.5 asLongFloat hash |
|
1078 |
0.5 asQuadFloat hash |
|
1079 |
||
1080 |
0.25 asShortFloat hash |
|
1081 |
0.25 asShortFloat hash |
|
1082 |
0.25 asLongFloat hash |
|
1083 |
0.25 asQuadFloat hash |
|
1084 |
" |
|
1085 |
||
1086 |
"Created: / 07-06-2019 / 09:28:07 / Claus Gittinger" |
|
1087 |
! ! |
|
1088 |
||
5003 | 1089 |
!QuadFloat methodsFor:'double dispatching'! |
1090 |
||
1091 |
differenceFromQuadFloat:aQuadFloat |
|
1092 |
%{ |
|
1093 |
#ifdef SUPPORT_QUADFLOAT |
|
1094 |
OBJ newFloat; |
|
1095 |
float128_t result, myVal, argVal; |
|
1096 |
||
1097 |
myVal = __quadFloatVal(self); |
|
1098 |
argVal = __quadFloatVal(aQuadFloat); |
|
5276 | 1099 |
result = STX_addq( argVal, myVal, 1 ); |
5003 | 1100 |
__qMKQFLOAT(newFloat, result); |
1101 |
RETURN ( newFloat ); |
|
1102 |
#endif // SUPPORT_QUADFLOAT |
|
1103 |
%}. |
|
1104 |
self errorUnsupported |
|
1105 |
! |
|
1106 |
||
5005 | 1107 |
equalFromQuadFloat:aQuadFloat |
1108 |
"sent when aQuadFloat does not know how to compare agaist the receiver, self" |
|
5003 | 1109 |
|
1110 |
%{ |
|
1111 |
#ifdef SUPPORT_QUADFLOAT |
|
1112 |
OBJ newFloat; |
|
1113 |
float128_t result, myVal, argVal; |
|
1114 |
||
1115 |
myVal = __quadFloatVal(self); |
|
1116 |
argVal = __quadFloatVal(aQuadFloat); |
|
5276 | 1117 |
RETURN (STX_eqq(argVal, myVal) ? true : false); |
5003 | 1118 |
#endif // SUPPORT_QUADFLOAT |
1119 |
%}. |
|
1120 |
self errorUnsupported |
|
5011 | 1121 |
|
1122 |
"Modified: / 08-06-2019 / 13:31:48 / Claus Gittinger" |
|
5004 | 1123 |
! |
1124 |
||
5005 | 1125 |
lessFromQuadFloat:aQuadFloat |
1126 |
"sent when aQuadFloat does not know how to compare agaist the receiver, self" |
|
1127 |
||
1128 |
%{ |
|
1129 |
#ifdef SUPPORT_QUADFLOAT |
|
1130 |
OBJ newFloat; |
|
1131 |
float128_t result, myVal, argVal; |
|
1132 |
||
1133 |
myVal = __quadFloatVal(self); |
|
1134 |
argVal = __quadFloatVal(aQuadFloat); |
|
5276 | 1135 |
RETURN (STX_ltq(argVal, myVal) ? true : false); |
5005 | 1136 |
#endif // SUPPORT_QUADFLOAT |
1137 |
%}. |
|
1138 |
self errorUnsupported |
|
1139 |
! |
|
1140 |
||
5004 | 1141 |
productFromQuadFloat:aQuadFloat |
1142 |
"sent when aQuadFloat does not know how to multiply the receiver, self" |
|
1143 |
||
1144 |
%{ |
|
1145 |
#ifdef SUPPORT_QUADFLOAT |
|
1146 |
OBJ newFloat; |
|
1147 |
float128_t result, myVal, argVal; |
|
1148 |
||
1149 |
myVal = __quadFloatVal(self); |
|
1150 |
argVal = __quadFloatVal(aQuadFloat); |
|
5276 | 1151 |
result = STX_mulq(myVal, argVal); |
5004 | 1152 |
__qMKQFLOAT(newFloat, result); |
1153 |
RETURN ( newFloat ); |
|
1154 |
#endif // SUPPORT_QUADFLOAT |
|
1155 |
%}. |
|
1156 |
self errorUnsupported |
|
1157 |
! |
|
1158 |
||
1159 |
quotientFromQuadFloat:aQuadFloat |
|
1160 |
"sent when aQuadFloat does not know how to multiply the receiver, self" |
|
1161 |
||
1162 |
%{ |
|
1163 |
#ifdef SUPPORT_QUADFLOAT |
|
1164 |
OBJ newFloat; |
|
1165 |
float128_t result, myVal, argVal; |
|
1166 |
||
1167 |
myVal = __quadFloatVal(self); |
|
1168 |
argVal = __quadFloatVal(aQuadFloat); |
|
5276 | 1169 |
result = STX_divq(argVal, myVal); |
5004 | 1170 |
__qMKQFLOAT(newFloat, result); |
1171 |
RETURN ( newFloat ); |
|
1172 |
#endif // SUPPORT_QUADFLOAT |
|
1173 |
%}. |
|
1174 |
self errorUnsupported |
|
1175 |
! |
|
1176 |
||
5005 | 1177 |
sumFromQuadFloat:aQuadFloat |
1178 |
"sent when aQuadFloat does not know how to add the receiver, self" |
|
5004 | 1179 |
|
1180 |
%{ |
|
1181 |
#ifdef SUPPORT_QUADFLOAT |
|
1182 |
OBJ newFloat; |
|
1183 |
float128_t result, myVal, argVal; |
|
1184 |
||
1185 |
myVal = __quadFloatVal(self); |
|
1186 |
argVal = __quadFloatVal(aQuadFloat); |
|
5276 | 1187 |
result = STX_addq( myVal, argVal, 0 ); |
5005 | 1188 |
__qMKQFLOAT(newFloat, result); |
5004 | 1189 |
RETURN ( newFloat ); |
1190 |
#endif // SUPPORT_QUADFLOAT |
|
1191 |
%}. |
|
1192 |
self errorUnsupported |
|
5003 | 1193 |
! ! |
1194 |
||
1195 |
!QuadFloat methodsFor:'error reportng'! |
|
1196 |
||
1197 |
errorUnsupported |
|
1198 |
self class errorUnsupported |
|
1199 |
||
1200 |
"Modified: / 07-06-2019 / 02:44:51 / Claus Gittinger" |
|
1201 |
! ! |
|
1202 |
||
5025 | 1203 |
!QuadFloat methodsFor:'printing'! |
1204 |
||
1205 |
printOn:aStream |
|
5269
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1206 |
|mantissa exponent| |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1207 |
|
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1208 |
mantissa := self mantissa. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1209 |
exponent := self exponent. |
5027 | 1210 |
|
5269
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1211 |
self exponent == 0 ifTrue:[ |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1212 |
mantissa printOn:aStream. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1213 |
aStream nextPutAll:'.0'. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1214 |
^ self |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1215 |
]. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1216 |
mantissa == 0 ifTrue:[ |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1217 |
"/ a zero mantissa is impossible - except for zero and a few others |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1218 |
exponent == 0 ifTrue:[ aStream nextPutAll:'0.0'. ^ self]. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1219 |
self == NaN ifTrue:[ aStream nextPutAll:'NAN'. ^ self ]. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1220 |
self == NegativeInfinity ifTrue:[ aStream nextPutAll:'-INF'. ^ self]. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1221 |
self == PositiveInfinity ifTrue:[ aStream nextPutAll:'INF'. ^ self]. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1222 |
|
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1223 |
self error:'invalid largeFloat' mayProceed:true. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1224 |
aStream nextPutAll:'Invalid'. ^ self. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1225 |
]. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1226 |
|
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1227 |
exponent >= 0 ifTrue:[ |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1228 |
(mantissa bitShift:exponent) printOn:aStream. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1229 |
aStream nextPutAll:'.0'. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1230 |
^ self |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1231 |
]. |
83163a7005f1
Fallback to version 1.36 - mingw couldn't compile
Stefan Vogel <sv@exept.de>
parents:
5268
diff
changeset
|
1232 |
((mantissa / (1 bitShift:exponent negated)) asFixedPoint:6) printOn:aStream. |
5025 | 1233 |
|
1234 |
"Created: / 11-06-2019 / 00:13:00 / Claus Gittinger" |
|
1235 |
! ! |
|
1236 |
||
5011 | 1237 |
!QuadFloat methodsFor:'queries'! |
1238 |
||
1239 |
isFinite |
|
5194 | 1240 |
"return true, if the receiver is a finite float (not NaN and not +/-INF)" |
5011 | 1241 |
|
1242 |
%{ /* NOCONTEXT */ |
|
5016 | 1243 |
#ifdef SUPPORT_QUADFLOAT |
5011 | 1244 |
float128_t myVal; |
1245 |
||
1246 |
myVal = __quadFloatVal(self); |
|
5276 | 1247 |
RETURN (STX_isfiniteq(myVal) ? true : false); |
5016 | 1248 |
#endif // SUPPORT_QUADFLOAT |
5011 | 1249 |
%}. |
1250 |
||
1251 |
" |
|
5276 | 1252 |
1.0 isFinite |
1253 |
self NaN isFinite |
|
1254 |
self infinity isFinite |
|
1255 |
self negativeInfinity isFinite |
|
1256 |
(0.0 uncheckedDivide: 0.0) isFinite |
|
1257 |
(1.0 uncheckedDivide: 0.0) isFinite |
|
5020 | 1258 |
" |
1259 |
! |
|
1260 |
||
1261 |
isInfinite |
|
5194 | 1262 |
"return true, if the receiver is an infinite float (+Inf or -Inf)." |
5020 | 1263 |
|
1264 |
%{ /* NOCONTEXT */ |
|
1265 |
#ifdef SUPPORT_QUADFLOAT |
|
1266 |
float128_t myVal; |
|
1267 |
||
1268 |
myVal = __quadFloatVal(self); |
|
5276 | 1269 |
RETURN (STX_isInfq(&myVal) ? true : false); |
5020 | 1270 |
#endif // SUPPORT_QUADFLOAT |
1271 |
%}. |
|
1272 |
||
1273 |
" |
|
5276 | 1274 |
1.0 asQuadFloat isFinite |
1275 |
1.0 asQuadFloat isInfinite |
|
1276 |
self NaN isFinite |
|
1277 |
self NaN isInfinite |
|
1278 |
self infinity isFinite |
|
1279 |
self infinity isInfinite |
|
1280 |
self negativeInfinity isFinite |
|
1281 |
self negativeInfinity isInfinite |
|
1282 |
(0.0 uncheckedDivide: 0.0) isFinite |
|
1283 |
(1.0 uncheckedDivide: 0.0) isFinite |
|
5011 | 1284 |
" |
1285 |
! |
|
1286 |
||
1287 |
isNaN |
|
5194 | 1288 |
"return true, if the receiver is an invalid float (NaN - not a number). |
1289 |
These are not created by ST/X float operations (they raise an exception); |
|
1290 |
however, inline C-code could produce them." |
|
5011 | 1291 |
|
1292 |
%{ /* NOCONTEXT */ |
|
5016 | 1293 |
#ifdef SUPPORT_QUADFLOAT |
5011 | 1294 |
float128_t myVal; |
1295 |
||
1296 |
myVal = __quadFloatVal(self); |
|
5276 | 1297 |
RETURN (STX_isNanq(&myVal) ? true : false); |
5016 | 1298 |
#endif // SUPPORT_QUADFLOAT |
5011 | 1299 |
%}. |
1300 |
||
1301 |
" |
|
5276 | 1302 |
1.0 asQuadFloat isFinite |
1303 |
self NaN isFinite |
|
1304 |
self infinity isFinite |
|
1305 |
(0.0 uncheckedDivide: 0.0) isFinite |
|
1306 |
(1.0 uncheckedDivide: 0.0) isFinite |
|
5011 | 1307 |
" |
1308 |
! ! |
|
1309 |
||
5276 | 1310 |
!QuadFloat methodsFor:'testing'! |
1311 |
||
1312 |
isQuadFloat |
|
1313 |
"return true, if the receiver is some kind of quad floating point number (iee quad precision)" |
|
1314 |
||
1315 |
^ true |
|
1316 |
! ! |
|
1317 |
||
4983 | 1318 |
!QuadFloat class methodsFor:'documentation'! |
1319 |
||
1320 |
version_CVS |
|
1321 |
^ '$Header$' |
|
1322 |
! ! |