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