author | Claus Gittinger <cg@exept.de> |
Mon, 16 Dec 2019 11:42:04 +0100 | |
changeset 25127 | 22ff3c08a076 |
parent 25088 | 3a9b967a1065 |
permissions | -rw-r--r-- |
25022 | 1 |
"{ Encoding: utf8 }" |
2 |
||
7382 | 3 |
" |
4 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
5 |
All Rights Reserved |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
6 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
7 |
This software is furnished under a license and may be used |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
8 |
only in accordance with the terms of that license and with the |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
9 |
inclusion of the above copyright notice. This software may not |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
10 |
be provided or otherwise made available to, or used by, any |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
11 |
other person. No title to or ownership of the software is |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
12 |
hereby transferred. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
13 |
" |
5411 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17381 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
18 |
LimitedPrecisionReal variableByteSubclass:#LongFloat |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
19 |
instanceVariableNames:'' |
25027 | 20 |
classVariableNames:'DefaultPrintFormat DefaultPrintfFormat DefaultPrintPrecision |
21 |
LongFloatZero LongFloatOne Pi E Epsilon NaN PositiveInfinity |
|
22 |
NegativeInfinity Halfpi HalfpiNegative Phi' |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
23 |
poolDictionaries:'' |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
24 |
category:'Magnitude-Numbers' |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
25 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
26 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
27 |
!LongFloat primitiveDefinitions! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
28 |
%{ |
14743 | 29 |
#include <stdio.h> |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
30 |
#include <errno.h> |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
31 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
32 |
#ifndef __OPTIMIZE__ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
33 |
# define __OPTIMIZE__ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
34 |
#endif |
4253
768802bc61a4
longFloat class falls back to float on systems that do not support them
Claus Gittinger <cg@exept.de>
parents:
4250
diff
changeset
|
35 |
|
4825 | 36 |
#define __USE_ISOC9X 1 |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
37 |
#define __USE_ISOC99 1 |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
38 |
#include <math.h> |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
39 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
40 |
/* |
19266 | 41 |
* on some systems, errno is a macro ... check for it here |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
42 |
*/ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
43 |
#ifndef errno |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
44 |
extern errno; |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
45 |
#endif |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
46 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
47 |
#if !defined (__win32__) |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
48 |
# include <locale.h> |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
49 |
#endif |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
50 |
|
25036 | 51 |
#include <float.h> |
4825 | 52 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
53 |
#if defined(__irix__) || defined(__solaris__) || defined(__sunos__) |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
54 |
# include <nan.h> |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
55 |
#endif |
4825 | 56 |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
57 |
#if defined(__osx__) |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
58 |
# include <math.h> |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
59 |
#endif |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
60 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
61 |
#if defined(__linux__) |
4825 | 62 |
# ifndef NAN |
5822
4e56f8aadda5
Get nan.h from bits/nan.h for Linux
Stefan Vogel <sv@exept.de>
parents:
5645
diff
changeset
|
63 |
# include <bits/nan.h> |
4825 | 64 |
# endif |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
65 |
#endif |
4825 | 66 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
67 |
#ifdef __win32__ |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
68 |
/* |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
69 |
* no finite(x) ? |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
70 |
* no isnan(x) ? |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
71 |
*/ |
7417 | 72 |
# ifndef isnanl |
73 |
# define isnanl(x) \ |
|
14931 | 74 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
75 |
(((unsigned int *)(&x))[1] == 0xC0000000) && \ |
|
25049 | 76 |
(((unsigned short *)(&x))[4] & 0x7FFF == 0x7FFF)) |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
77 |
# endif |
7417 | 78 |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
79 |
# ifndef isnan |
7417 | 80 |
# define isnan(x) \ |
25049 | 81 |
((((unsigned int *)(&x))[1] & 0x7FF80000) == 0x7FF80000) |
82 |
// old, invalid definition |
|
83 |
// # define isnan(x) \ |
|
84 |
// ((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
85 |
// (((unsigned int *)(&x))[1] == 0xFFF80000)) |
|
7417 | 86 |
# endif |
87 |
||
88 |
# ifndef isPositiveInfinity |
|
89 |
# define isPositiveInfinity(x) \ |
|
14931 | 90 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
91 |
(((unsigned int *)(&x))[1] == 0x7FF00000)) |
|
7417 | 92 |
# endif |
93 |
||
94 |
# ifndef isNegativeInfinity |
|
14931 | 95 |
# define isNegativeInfinity(x) \ |
96 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
97 |
(((unsigned int *)(&x))[1] == 0xFFF00000)) |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
98 |
# endif |
7417 | 99 |
|
100 |
# ifndef isinf |
|
101 |
# define isinf(x) \ |
|
14931 | 102 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
103 |
((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000)) |
|
7417 | 104 |
# endif |
105 |
||
8981
7c7b2a14c8b3
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8980
diff
changeset
|
106 |
# ifndef isfinite |
7c7b2a14c8b3
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8980
diff
changeset
|
107 |
# define isfinite(x) (!isinf(x) && !isnan(x)) |
7417 | 108 |
# endif |
109 |
||
110 |
# define NO_ASINH |
|
111 |
# define NO_ACOSH |
|
112 |
# define NO_ATANH |
|
14931 | 113 |
|
114 |
# ifdef __MINGW__ |
|
22491 | 115 |
# ifndef _STRING_H_INCLUDED_ |
116 |
# include <string.h> |
|
117 |
# define _STRING_H_INCLUDED_ |
|
118 |
# endif |
|
119 |
||
120 |
// sigh: the default ming setup uses the microsoft printf, |
|
121 |
// which does not support long doubles |
|
122 |
# define snprintf __mingw_snprintf |
|
19356 | 123 |
# endif /* __MINGW__ */ |
19329
52f5c0de20b4
LongFloat printing under mingw was broken (wrong printf called)
Claus Gittinger <cg@exept.de>
parents:
19324
diff
changeset
|
124 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
125 |
#endif /* __win32__ */ |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
126 |
|
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
127 |
#ifdef __solaris__ |
8984 | 128 |
# ifndef isfinite |
129 |
# define isfinite(f) finite((double)(f)) |
|
130 |
# endif |
|
131 |
#endif |
|
132 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
133 |
#ifdef __realIX__ |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
134 |
# ifndef isfinite |
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
135 |
# define isfinite(x) 1 |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
136 |
# endif |
4253
768802bc61a4
longFloat class falls back to float on systems that do not support them
Claus Gittinger <cg@exept.de>
parents:
4250
diff
changeset
|
137 |
#endif /* realIX */ |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
138 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
139 |
#if defined(__GNUC__) || defined(__MINGW__) || defined(__win32__) |
24267 | 140 |
# ifndef LONGFLOAT_t |
141 |
# define LONGFLOAT_t long double |
|
142 |
# endif |
|
8706 | 143 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
144 |
# if defined(__linux__) || defined(__osx__) || defined(__win32__) |
7397 | 145 |
# define LONG_ceil ceill |
146 |
# define LONG_floor floorl |
|
147 |
# define LONG_sqrt sqrtl |
|
148 |
# define LONG_sin sinl |
|
149 |
# define LONG_cos cosl |
|
150 |
# define LONG_tan tanl |
|
151 |
# define LONG_sinh sinhl |
|
152 |
# define LONG_cosh coshl |
|
153 |
# define LONG_tanh tanhl |
|
154 |
# define LONG_asin asinl |
|
155 |
# define LONG_acos acosl |
|
156 |
# define LONG_atan atanl |
|
157 |
# define LONG_exp expl |
|
158 |
# define LONG_frexp frexpl |
|
159 |
# define LONG_log logl |
|
160 |
# define LONG_log10 log10l |
|
14743 | 161 |
# define LONG_modf modfl |
19323 | 162 |
# define LONG_trunc truncl |
7397 | 163 |
# define LONG_pow powl |
17459 | 164 |
# ifdef __llvm__ |
165 |
# define LONG_isnan isnan |
|
166 |
# else |
|
167 |
# define LONG_isnan isnanl |
|
168 |
# endif |
|
22790 | 169 |
# if defined(__osx__) |
170 |
# define LONG_isfinite isfinite |
|
171 |
# else |
|
172 |
# define LONG_isfinite isfinitel |
|
173 |
# endif |
|
15263 | 174 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
175 |
# if !defined(__win32__) |
15263 | 176 |
# define LONG_asinh asinhl |
177 |
# define LONG_acosh acoshl |
|
178 |
# define LONG_atanh atanhl |
|
179 |
# endif /* linux */ |
|
180 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
181 |
# endif /* defined(__linux__) || defined(__win32__) */ |
8706 | 182 |
|
8981
7c7b2a14c8b3
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8980
diff
changeset
|
183 |
# if !defined(LONG_isnan) |
7c7b2a14c8b3
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8980
diff
changeset
|
184 |
/* This should be true for ISO C99 systems - even for newer linux systems */ |
8706 | 185 |
# define LONG_isnan isnan |
186 |
# define LONG_isfinite isfinite |
|
8982
015dc40e3582
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8981
diff
changeset
|
187 |
# endif /* !defined(LONG_isnan) */ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
188 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
189 |
#endif /* defined(__GNUC__) || defined(__win32__) */ |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
190 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
191 |
%} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
192 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
193 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
194 |
!LongFloat class methodsFor:'documentation'! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
195 |
|
7382 | 196 |
copyright |
197 |
" |
|
198 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
199 |
All Rights Reserved |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
200 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
201 |
This software is furnished under a license and may be used |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
202 |
only in accordance with the terms of that license and with the |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
203 |
inclusion of the above copyright notice. This software may not |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
204 |
be provided or otherwise made available to, or used by, any |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
205 |
other person. No title to or ownership of the software is |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
206 |
hereby transferred. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
207 |
" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
208 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
209 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
210 |
documentation |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
211 |
" |
7382 | 212 |
LongFloats represent rational numbers with limited precision. |
24948 | 213 |
They use the C-compiler's 'long double' format, |
214 |
which is either mapped to the IEEE extended precision (80bit) |
|
24460 | 215 |
or IEEE quadruple precision format (128bit). |
10333 | 216 |
|
7380 | 217 |
In contrast to Floats (which use the C-compilers 64bit 'double' format), |
25027 | 218 |
LongFloats give you one of 80 bit extended floats, 96 bit extended floats or 128 bit quadruple floats, |
24263 | 219 |
depending on the underlying CPU. |
25027 | 220 |
Thus, code using longFloats is not guaranteed to be portable from one architecture to another, |
221 |
but faster than software emulations. |
|
222 |
||
223 |
NOTE: |
|
25036 | 224 |
on systems which do not support 'long doubles', LongFloats are (silently) |
225 |
represented as 'doubles'. |
|
10333 | 226 |
|
7380 | 227 |
Representation: |
25036 | 228 |
gcc-x86: |
229 |
80bit extended IEEE floats stored in in 96bits (12bytes); |
|
230 |
1 bit integer part, |
|
231 |
64 bit mantissa, |
|
232 |
16 bit exponent, |
|
233 |
19 decimal digits (approx.) |
|
234 |
||
235 |
borland-x86 (WIN32): |
|
236 |
80bit extended IEEE floats stored in in 80bits (10bytes); |
|
237 |
1 bit integer part, |
|
238 |
64 bit mantissa, |
|
239 |
16 bit exponent, |
|
240 |
19 decimal digits (approx.) |
|
241 |
||
242 |
gcc-x86_64: (WIN64) |
|
243 |
like gcc-x86 |
|
244 |
||
245 |
gcc-sparc: |
|
246 |
128bit quadruple IEEE floats (16bytes); |
|
247 |
112 bit mantissa, |
|
248 |
16 bit exponent, |
|
249 |
34 decimal digits (approx.) |
|
10333 | 250 |
|
7380 | 251 |
Mixed mode arithmetic: |
25036 | 252 |
longFloat op longFloat -> longFloat |
253 |
longFloat op fix -> longFloat |
|
254 |
longFloat op fraction -> longFloat |
|
255 |
longFloat op integer -> longFloat |
|
256 |
longFloat op shortFloat -> longFloat |
|
257 |
longFloat op float -> longFloat |
|
258 |
longFloat op complex -> complex |
|
21973 | 259 |
|
260 |
Range and precision of storage formats: see LimitedPrecisionReal >> documentation |
|
7405 | 261 |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
262 |
[author:] |
25036 | 263 |
Claus Gittinger |
10333 | 264 |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
265 |
[see also:] |
25036 | 266 |
Number |
267 |
Float ShortFloat Fraction FixedPoint Integer Complex |
|
268 |
FloatArray DoubleArray |
|
269 |
https://en.wikipedia.org/wiki/Extended_precision |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
270 |
" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
271 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
272 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
273 |
!LongFloat class methodsFor:'instance creation'! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
274 |
|
7382 | 275 |
basicNew |
276 |
"return a new longFloat - here we return 0.0 |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
277 |
- LongFloats are usually NOT created this way ... |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
278 |
Its implemented here to allow things like binary store & load |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
279 |
of longFloats. (but even this support will go away eventually, its not |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
280 |
a good idea to store the bits of a float - the reader might have a |
10333 | 281 |
totally different representation - so floats will eventually be |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
282 |
binary stored in a device independent format." |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
283 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
284 |
%{ /* NOCONTEXT */ |
18363 | 285 |
#ifdef __SCHTEAM__ |
286 |
return __c__._RETURN( new STDouble(0.0) ); |
|
287 |
#else |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
288 |
OBJ newFloat; |
24267 | 289 |
if (sizeof(LONGFLOAT_t) == sizeof(double)) { |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
290 |
__qMKFLOAT(newFloat, 0.0); /* OBJECT ALLOCATION */ |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
291 |
} else { |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
292 |
__qMKLFLOAT(newFloat, 0.0); /* OBJECT ALLOCATION */ |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
293 |
} |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
294 |
RETURN (newFloat); |
18363 | 295 |
#endif /* not SCHTEAM */ |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
296 |
%} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
297 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
298 |
|
24973 | 299 |
fastFromString:aString at:startIndex |
300 |
"return the next LongFloat from the string starting at startIndex. |
|
301 |
No spaces are skipped. |
|
302 |
Raises an exception, if the startIndex is not valid. |
|
303 |
Returns garbage if the argument string is not a valid double float number. |
|
304 |
||
305 |
This is a specially tuned entry (using a low-level C-call to strtold). |
|
306 |
It has been added to allow high speed string decomposition |
|
307 |
into numbers, especially for mass-data (reading millions of floats)." |
|
308 |
||
309 |
%{ /* NOCONTEXT */ |
|
310 |
int idx = __intVal(startIndex) - 1; |
|
311 |
||
312 |
if (__isStringLike(aString) && __isSmallInteger(startIndex)) { |
|
24985 | 313 |
char *cp = (char *)(__stringVal(aString)); |
314 |
OBJ newFloat; |
|
315 |
||
316 |
if ((unsigned)idx < __stringSize(aString)) { |
|
317 |
#ifndef NO_STRTOLD |
|
318 |
long double strtold(const char *, char**); |
|
319 |
LONGFLOAT_t val = strtold(cp+idx, NULL); |
|
25088 | 320 |
__qMKLFLOAT(newFloat, val); |
321 |
RETURN (newFloat); |
|
24985 | 322 |
#else |
323 |
# ifndef NO_SSCANF_LONGFLOAT |
|
324 |
LONGFLOAT_t val; |
|
325 |
sscanf(cp+idx, "%Lf", &val); |
|
326 |
__qMKLFLOAT(newFloat, val); |
|
327 |
RETURN (newFloat); |
|
24989 | 328 |
# endif |
24985 | 329 |
#endif |
330 |
} |
|
24973 | 331 |
} |
332 |
%}. |
|
333 |
^ self readFromString:(startIndex == 1 ifTrue:[aString] ifFalse:[aString from:startIndex]) |
|
334 |
||
335 |
" |
|
24985 | 336 |
LongFloat fastFromString:'123.45' at:1 |
337 |
LongFloat fastFromString:'123.45' at:2 |
|
338 |
LongFloat fastFromString:'123.45' at:3 |
|
339 |
LongFloat fastFromString:'123.45' at:4 |
|
340 |
LongFloat fastFromString:'123.45' at:5 |
|
341 |
LongFloat fastFromString:'123.45' at:6 |
|
342 |
||
343 |
LongFloat fastFromString:'123.45E4' at:1 |
|
344 |
LongFloat fastFromString:'hello123.45E4' at:6 |
|
24973 | 345 |
LongFloat fastFromString:'12345' at:1 |
346 |
LongFloat fastFromString:'12345' at:2 |
|
347 |
LongFloat fastFromString:'12345' at:3 |
|
348 |
LongFloat fastFromString:'12345' at:4 |
|
349 |
LongFloat fastFromString:'12345' at:5 |
|
350 |
||
351 |
LongFloat fastFromString:'12345' at:6 -> error |
|
352 |
LongFloat fastFromString:'12345' at:0 -> error |
|
353 |
||
354 |
LongFloat fastFromString:'hello123.45E4' at:1 -> 0 |
|
355 |
||
24985 | 356 |
LongFloat fastFromString:'1.7976931348623157e+308' |
357 |
LongFloat fastFromString:'Nan' |
|
24973 | 358 |
LongFloat fastFromString:'+Inf' |
359 |
LongFloat fastFromString:'-Inf' |
|
360 |
" |
|
361 |
||
362 |
" |
|
363 |
Time millisecondsToRun:[ |
|
24985 | 364 |
1000000 timesRepeat:[ |
365 |
LongFloat readFrom:'123.45' |
|
366 |
] |
|
24973 | 367 |
] |
368 |
" |
|
369 |
||
370 |
" |
|
371 |
Time millisecondsToRun:[ |
|
24985 | 372 |
1000000 timesRepeat:[ |
373 |
LongFloat fastFromString:'123.45' at:1 |
|
374 |
] |
|
24973 | 375 |
] |
376 |
" |
|
377 |
||
378 |
"Modified (comment): / 21-06-2017 / 09:24:32 / cg" |
|
379 |
"Modified (comment): / 20-03-2019 / 13:45:12 / Claus Gittinger" |
|
380 |
! |
|
381 |
||
7382 | 382 |
fromFloat:aFloat |
383 |
"return a new longFloat, given a float value" |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
384 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
385 |
%{ /* NOCONTEXT */ |
18363 | 386 |
#ifdef __SCHTEAM__ |
387 |
if (aFloat.isDouble()) { |
|
388 |
return __c__._RETURN(aFloat); |
|
389 |
} |
|
390 |
if (aFloat.isFloat()) { |
|
391 |
return __c__._RETURN( new STDouble(aFloat.floatValue()) ); |
|
392 |
} |
|
393 |
#else |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
394 |
OBJ newFloat; |
24267 | 395 |
LONGFLOAT_t f; |
396 |
||
397 |
if (sizeof(LONGFLOAT_t) == sizeof(double)) { |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
398 |
RETURN (aFloat); |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
399 |
} |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
400 |
|
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
401 |
if (__isFloatLike(aFloat)) { |
24267 | 402 |
f = (LONGFLOAT_t)(__floatVal(aFloat)); |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
403 |
__qMKLFLOAT(newFloat, f); /* OBJECT ALLOCATION */ |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
404 |
RETURN (newFloat); |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
405 |
} |
18363 | 406 |
#endif |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
407 |
%}. |
24275 | 408 |
ArgumenError raise |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
409 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
410 |
" |
10333 | 411 |
LongFloat fromFloat:123.0 |
412 |
123.0 asLongFloat |
|
413 |
123 asLongFloat |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
414 |
" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
415 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
416 |
|
17219 | 417 |
fromIEEE32Bit: anInteger |
418 |
"creates a long float, given the four native float bytes as an integer" |
|
419 |
||
420 |
%{ /* NOCONTEXT */ |
|
421 |
OBJ newFloat; |
|
422 |
||
423 |
REGISTER union { |
|
22790 | 424 |
unsigned int i; |
425 |
float f; |
|
17219 | 426 |
} r; |
24989 | 427 |
LONGFLOAT_t f; |
17219 | 428 |
|
429 |
r.i = __unsignedLongIntVal( anInteger ); |
|
24989 | 430 |
f = (LONGFLOAT_t)r.f; |
431 |
__qMKLFLOAT(newFloat, f); |
|
17219 | 432 |
RETURN( newFloat ); |
18363 | 433 |
%}. |
434 |
^ Float fromIEEE32Bit: anInteger |
|
17219 | 435 |
|
436 |
" |
|
21874 | 437 |
LongFloat fromIEEE32Bit:((ShortFloat pi digitBytesMSB:true) asIntegerMSB:true) |
17584 | 438 |
" |
21874 | 439 |
|
440 |
"Modified: / 21-06-2017 / 09:35:58 / cg" |
|
17584 | 441 |
! |
442 |
||
443 |
fromIEEE64Bit: anInteger |
|
21874 | 444 |
"creates a long double, given the eight native double bytes as an integer" |
17584 | 445 |
|
446 |
%{ /* NOCONTEXT */ |
|
19268 | 447 |
extern int __unsignedLong64IntVal(OBJ o, __uint64__ *pI); |
17584 | 448 |
|
449 |
REGISTER union { |
|
22790 | 450 |
__uint64__ u64; |
451 |
double d; |
|
17584 | 452 |
} r; |
453 |
||
454 |
if (__unsignedLong64IntVal(anInteger, &r.u64)) { |
|
22790 | 455 |
OBJ newFloat; |
25036 | 456 |
LONGFLOAT_t f = (LONGFLOAT_t)r.d; |
24989 | 457 |
|
458 |
__qMKLFLOAT(newFloat, f); |
|
22790 | 459 |
RETURN( newFloat ); |
17584 | 460 |
} |
461 |
%}. |
|
18363 | 462 |
^ Float fromIEEE32Bit: anInteger |
17584 | 463 |
|
464 |
" |
|
22790 | 465 |
LongFloat fromIEEE64Bit:((Float pi digitBytesMSB:true) asIntegerMSB:true) |
17219 | 466 |
" |
21874 | 467 |
|
468 |
"Modified (comment): / 21-06-2017 / 09:36:34 / cg" |
|
17219 | 469 |
! |
470 |
||
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
471 |
fromInteger:anInteger |
19360 | 472 |
"return a new longFloat, given an integer value" |
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
473 |
|
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
474 |
%{ /* NOCONTEXT */ |
18363 | 475 |
#ifdef __SCHTEAM__ |
476 |
if (anInteger.isSmallInteger()) { |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19360
diff
changeset
|
477 |
return __c__._RETURN( STDouble._new( (double)(anInteger.longValue()) )); |
18363 | 478 |
} |
479 |
#else |
|
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
480 |
OBJ newFloat; |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
481 |
|
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
482 |
if (__isSmallInteger(anInteger)) { |
24267 | 483 |
LONGFLOAT_t f = (LONGFLOAT_t)__smallIntegerVal(anInteger); |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19360
diff
changeset
|
484 |
__qMKLFLOAT(newFloat, f); /* OBJECT ALLOCATION */ |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19360
diff
changeset
|
485 |
RETURN (newFloat); |
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
486 |
} |
18363 | 487 |
#endif /* not SCHTEAM */ |
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
488 |
%}. |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
489 |
^ super fromInteger:anInteger |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
490 |
|
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
491 |
" |
10333 | 492 |
LongFloat fromInteger:123 |
493 |
LongFloat fromInteger:(100 factorial) |
|
19360 | 494 |
(100 factorial) asLongFloat |
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
495 |
" |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
496 |
! |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
497 |
|
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
498 |
fromShortFloat:aFloat |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
499 |
"return a new longFloat, given a shortFloat value" |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
500 |
|
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
501 |
%{ /* NOCONTEXT */ |
18363 | 502 |
#ifdef __SCHTEAM__ |
503 |
if (aFloat.isFloat()) { |
|
504 |
return __c__._RETURN( new STDouble(aFloat.floatValue()) ); |
|
505 |
} |
|
506 |
if (aFloat.isDouble()) { |
|
507 |
return __c__._RETURN( aFloat ); |
|
508 |
} |
|
509 |
#else |
|
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
510 |
OBJ newFloat; |
24267 | 511 |
LONGFLOAT_t f; |
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
512 |
|
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
513 |
if (__isShortFloat(aFloat)) { |
24267 | 514 |
f = (LONGFLOAT_t)(__shortFloatVal(aFloat)); |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
515 |
__qMKLFLOAT(newFloat, f); /* OBJECT ALLOCATION */ |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
516 |
RETURN (newFloat); |
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
517 |
} |
18363 | 518 |
#endif /* not SCHTEAM */ |
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
519 |
%}. |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
520 |
self error:'invalid argumnet' |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
521 |
|
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
522 |
" |
10333 | 523 |
LongFloat fromShortFloat:(123.0 asShortFloat) |
524 |
LongFloat fromShortFloat:122 |
|
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
525 |
" |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
526 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
527 |
|
12914
802070da5c65
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12476
diff
changeset
|
528 |
!LongFloat class methodsFor:'accessing'! |
802070da5c65
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12476
diff
changeset
|
529 |
|
802070da5c65
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12476
diff
changeset
|
530 |
defaultPrintFormat |
24952 | 531 |
"/ by default, I will print 19 digits |
24985 | 532 |
"/ ShortFloat pi -> 3.141593 |
533 |
"/ Float pi -> 3.14159265358979 |
|
534 |
"/ LongFloat pi -> 3.141592653589793239 |
|
535 |
"/ QuadFloat pi -> 3.141592653589793239 |
|
24952 | 536 |
|
12914
802070da5c65
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12476
diff
changeset
|
537 |
^ DefaultPrintFormat |
802070da5c65
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12476
diff
changeset
|
538 |
! |
802070da5c65
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12476
diff
changeset
|
539 |
|
802070da5c65
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12476
diff
changeset
|
540 |
defaultPrintFormat:something |
802070da5c65
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12476
diff
changeset
|
541 |
DefaultPrintFormat := something. |
802070da5c65
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12476
diff
changeset
|
542 |
! ! |
802070da5c65
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12476
diff
changeset
|
543 |
|
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
544 |
!LongFloat class methodsFor:'class initialization'! |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
545 |
|
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
546 |
initialize |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19360
diff
changeset
|
547 |
DefaultPrintFormat := '.19'. "/ 19 valid digits |
21868 | 548 |
DefaultPrintfFormat := '%19f'. |
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
549 |
|
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
550 |
" |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
551 |
self initialize |
10333 | 552 |
" |
553 |
||
554 |
" |
|
555 |
DefaultPrintFormat := '.19'. |
|
556 |
LongFloat pi printString. |
|
557 |
||
558 |
DefaultPrintFormat := '.9'. |
|
559 |
LongFloat pi printString. |
|
560 |
||
561 |
DefaultPrintFormat := '.6'. |
|
562 |
LongFloat pi printString. |
|
7448
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
563 |
" |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
564 |
! ! |
d1aaa52b463e
double dispatching, printing NaN and INF
Claus Gittinger <cg@exept.de>
parents:
7417
diff
changeset
|
565 |
|
21874 | 566 |
!LongFloat class methodsFor:'coercing & converting'! |
567 |
||
568 |
coerce:aNumber |
|
25013 | 569 |
"convert the argument aNumber into an instance of the receiver (class) and return it." |
21874 | 570 |
|
571 |
^ aNumber asLongFloat. |
|
572 |
! ! |
|
573 |
||
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
574 |
!LongFloat class methodsFor:'constants'! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
575 |
|
21857 | 576 |
NaN |
577 |
"return a longFloat which represents not-a-Number (i.e. an invalid number)" |
|
578 |
||
579 |
NaN isNil ifTrue:[ |
|
21868 | 580 |
NaN := super NaN |
21857 | 581 |
]. |
582 |
^ NaN |
|
583 |
||
584 |
" |
|
585 |
LongFloat NaN |
|
586 |
" |
|
587 |
||
588 |
"Created: / 20-06-2017 / 13:52:58 / cg" |
|
589 |
! |
|
590 |
||
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
591 |
e |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
592 |
"return the constant e as LongFloat" |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
593 |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19360
diff
changeset
|
594 |
E isNil ifTrue:[ |
24267 | 595 |
"/ eDigits has enough digits for 128bit IEEE quads |
596 |
"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here... |
|
597 |
E := self readFrom:(Number eDigits) |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19360
diff
changeset
|
598 |
]. |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
599 |
^ E |
24263 | 600 |
|
601 |
"Modified (format): / 06-06-2019 / 17:02:27 / Claus Gittinger" |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
602 |
! |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
603 |
|
22724 | 604 |
halfpi |
605 |
"return the constant pi/2 as LongFloat" |
|
606 |
||
607 |
Halfpi isNil ifTrue:[ |
|
22790 | 608 |
"/ enough digits for 128bit IEEE quads |
609 |
"/ do not write as a literal constant here - we cannot depend on the underlying C-compiler here... |
|
610 |
||
611 |
Halfpi := (self readFrom:'1.570796326794896619231321691639751442098584699687552910'). |
|
22724 | 612 |
]. |
613 |
^ Halfpi |
|
614 |
||
615 |
" |
|
616 |
self halfpi |
|
617 |
" |
|
618 |
! |
|
619 |
||
620 |
halfpiNegative |
|
621 |
"return the constant -pi/2 as LongFloat" |
|
622 |
||
623 |
HalfpiNegative isNil ifTrue:[ |
|
22790 | 624 |
HalfpiNegative := (self readFrom:'-1.570796326794896619231321691639751442098584699687552910') |
22724 | 625 |
]. |
626 |
^ HalfpiNegative |
|
627 |
||
628 |
" |
|
629 |
self halfpiNegative |
|
630 |
" |
|
631 |
! |
|
632 |
||
21857 | 633 |
infinity |
24305 | 634 |
"return a longFloat which represents positive infinity (for my instances). |
635 |
Warning: do not compare equal against infinities; |
|
636 |
instead, check using isFinite or isInfinite" |
|
21857 | 637 |
|
638 |
PositiveInfinity isNil ifTrue:[ |
|
24948 | 639 |
PositiveInfinity := Float infinity asLongFloat |
21857 | 640 |
]. |
641 |
^ PositiveInfinity |
|
642 |
||
643 |
" |
|
644 |
LongFloat infinity |
|
645 |
" |
|
646 |
||
647 |
"Created: / 20-06-2017 / 13:53:45 / cg" |
|
24305 | 648 |
"Modified (comment): / 09-06-2019 / 12:52:58 / Claus Gittinger" |
21857 | 649 |
! |
650 |
||
651 |
negativeInfinity |
|
24305 | 652 |
"return a longFloat which represents positive infinity (for my instances). |
653 |
Warning: do not compare equal against infinities; |
|
654 |
instead, check using isFinite or isInfinite" |
|
21857 | 655 |
|
656 |
NegativeInfinity isNil ifTrue:[ |
|
24948 | 657 |
NegativeInfinity := Float negativeInfinity asLongFloat |
21857 | 658 |
]. |
659 |
^ NegativeInfinity |
|
660 |
||
661 |
" |
|
662 |
LongFloat negativeInfinity |
|
663 |
" |
|
664 |
||
665 |
"Created: / 20-06-2017 / 13:54:19 / cg" |
|
24305 | 666 |
"Modified (comment): / 09-06-2019 / 12:53:25 / Claus Gittinger" |
21857 | 667 |
! |
668 |
||
24932 | 669 |
phi |
670 |
"return the constant phi as LongFloat" |
|
671 |
||
672 |
Phi isNil ifTrue:[ |
|
24985 | 673 |
"/ phiDigits has enough digits for 128bit IEEE quads |
674 |
"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here... |
|
675 |
Phi := self readFrom:(Number phiDigits) |
|
24932 | 676 |
]. |
677 |
^ Phi |
|
678 |
||
679 |
"Modified (format): / 06-06-2019 / 17:10:22 / Claus Gittinger" |
|
680 |
! |
|
681 |
||
7382 | 682 |
pi |
683 |
"return the constant pi as LongFloat" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
684 |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19360
diff
changeset
|
685 |
Pi isNil ifTrue:[ |
24267 | 686 |
"/ piDigits has enough digits for 128bit IEEE quads |
687 |
"/ do not use as a literal constant here - we cannot depend on the underlying C-compiler here... |
|
688 |
Pi := self readFrom:(Number piDigits) |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19360
diff
changeset
|
689 |
]. |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
690 |
^ Pi |
24263 | 691 |
|
692 |
"Modified (format): / 06-06-2019 / 17:10:22 / Claus Gittinger" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
693 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
694 |
|
7382 | 695 |
unity |
696 |
"return the neutral element for multiplication (1.0) as LongFloat" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
697 |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
698 |
LongFloatOne isNil ifTrue:[ |
7372 | 699 |
LongFloatOne := 1.0 asLongFloat. |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
700 |
]. |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
701 |
^ LongFloatOne |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
702 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
703 |
"Modified: 23.4.1996 / 09:26:51 / cg" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
704 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
705 |
|
7382 | 706 |
zero |
707 |
"return the neutral element for addition (0.0) as LongFloat" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
708 |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
709 |
LongFloatZero isNil ifTrue:[ |
7372 | 710 |
LongFloatZero := 0.0 asLongFloat |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
711 |
]. |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
712 |
^ LongFloatZero |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
713 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
714 |
"Modified: 23.4.1996 / 09:26:45 / cg" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
715 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
716 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
717 |
!LongFloat class methodsFor:'queries'! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
718 |
|
21826 | 719 |
defaultPrintPrecision |
720 |
"return the number of decimal digits printed by default" |
|
721 |
||
25027 | 722 |
^ DefaultPrintPrecision ? 8 |
21826 | 723 |
|
724 |
" |
|
24292 | 725 |
LongFloat defaultPrintPrecision |
21868 | 726 |
ShortFloat defaultPrintPrecision |
727 |
Float defaultPrintPrecision |
|
21826 | 728 |
" |
729 |
||
730 |
"Created: / 17-06-2017 / 02:58:42 / cg" |
|
24292 | 731 |
"Modified (comment): / 08-06-2019 / 14:33:50 / Claus Gittinger" |
21826 | 732 |
! |
733 |
||
25013 | 734 |
emax |
735 |
"The largest exponent value allowed by instances of this class." |
|
736 |
||
25022 | 737 |
^ 16383 |
25013 | 738 |
|
739 |
" |
|
740 |
1.0 asLongFloat fmax -> 1.189731495357231765E+4932 |
|
741 |
1.0 asLongFloat fmin -> 3.362103143112093506E-4932 |
|
25027 | 742 |
1.0 asLongFloat emin -> -16382 |
743 |
1.0 asLongFloat emax -> 16383 |
|
744 |
1.0 asLongFloat eBias -> 16383 |
|
25013 | 745 |
" |
746 |
! |
|
747 |
||
748 |
emin |
|
749 |
"The smallest exponent value allowed by instances of this class." |
|
750 |
||
25036 | 751 |
^ -16382 |
25013 | 752 |
|
753 |
" |
|
754 |
1.0 asLongFloat fmax -> 1.189731495357231765E+4932 |
|
755 |
1.0 asLongFloat fmin -> 3.362103143112093506E-4932 |
|
25027 | 756 |
1.0 asLongFloat emin -> -16382 |
25013 | 757 |
" |
758 |
! |
|
759 |
||
24321 | 760 |
epsilon |
761 |
"return the maximum relative spacing of instances of mySelf |
|
762 |
(i.e. the value-delta of the least significant bit)" |
|
763 |
||
764 |
Epsilon isNil ifTrue:[ |
|
765 |
Epsilon := self computeEpsilon. |
|
766 |
]. |
|
767 |
^ Epsilon |
|
768 |
||
769 |
"Modified (comment): / 21-06-2017 / 13:57:03 / cg" |
|
770 |
"Modified (comment): / 10-05-2018 / 01:09:07 / stefan" |
|
771 |
! |
|
772 |
||
7382 | 773 |
exponentCharacter |
24325 | 774 |
"return the character used to print between mantissa an exponent. |
775 |
Also used by the scanner when reading numbers." |
|
776 |
||
7382 | 777 |
^ $q |
24325 | 778 |
|
779 |
"Modified (comment): / 10-06-2019 / 21:27:49 / Claus Gittinger" |
|
6898 | 780 |
! |
781 |
||
25013 | 782 |
fmax |
783 |
"The largest value allowed by instances of this class." |
|
784 |
||
785 |
%{ /* NOCONTEXT */ |
|
25036 | 786 |
#if defined(LDBL_MAX) && !defined(__BORLANDC__) |
25013 | 787 |
{ |
25036 | 788 |
OBJ newFloat; |
789 |
__qMKLFLOAT(newFloat, LDBL_MAX); |
|
790 |
RETURN(newFloat); |
|
25013 | 791 |
} |
792 |
#endif |
|
793 |
%}. |
|
794 |
^ super fmax |
|
795 |
||
25036 | 796 |
" |
25013 | 797 |
1.0 asLongFloat fmax -> 1.189731495357231765E+4932 |
798 |
" |
|
799 |
! |
|
800 |
||
801 |
fmin |
|
802 |
"The smallest non-zero value allowed by instances of this class." |
|
803 |
||
804 |
%{ /* NOCONTEXT */ |
|
25036 | 805 |
#if defined(LDBL_MIN) && !defined(__BORLANDC__) |
25013 | 806 |
{ |
25036 | 807 |
OBJ newFloat; |
808 |
__qMKLFLOAT(newFloat, LDBL_MIN); |
|
809 |
RETURN(newFloat); |
|
25013 | 810 |
} |
811 |
#endif |
|
812 |
%}. |
|
813 |
^ super fmin |
|
814 |
||
815 |
" |
|
816 |
1.0 asLongFloat fmax -> 1.189731495357231765E+4932 |
|
817 |
1.0 asLongFloat fmin -> 3.362103143112093506E-4932 |
|
818 |
" |
|
819 |
! |
|
820 |
||
7382 | 821 |
isBuiltInClass |
822 |
"return true if this class is known by the run-time-system. |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
823 |
Here, true is returned for myself, false for subclasses." |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
824 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
825 |
^ self == LongFloat |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
826 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
827 |
"Modified: 23.4.1996 / 16:00:23 / cg" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
828 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
829 |
|
7382 | 830 |
numBitsInExponent |
831 |
"answer the number of bits in the exponent |
|
10333 | 832 |
i386: This is an 80bit longfloat stored in 96 bits (upper 16 bits are unused), |
25036 | 833 |
where 15 bits are available in the exponent (i bit is ignored): |
834 |
00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
|
15327 | 835 |
x86_64: This is an 80bit longfloat stored in 128 bits (upper 48 bits are unused), |
25036 | 836 |
where 15 bits are available in the exponent: |
837 |
00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
|
16780 | 838 |
sparc & others: This is an 128bit longfloat, |
25036 | 839 |
where 15 bits are available in the exponent: |
840 |
seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm... |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
841 |
" |
16780 | 842 |
%{ /* NOCONTEXT */ |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
843 |
#if defined(__x86__) || defined(__x86_64__) |
24267 | 844 |
if (sizeof(LONGFLOAT_t) == 10) { /* x86 - WIN32: 80bit floats */ |
25036 | 845 |
RETURN (__mkSmallInteger(15)); |
15263 | 846 |
} |
24267 | 847 |
if (sizeof(LONGFLOAT_t) == 12) { /* x86 - some unixes: 96bit floats */ |
25036 | 848 |
RETURN (__mkSmallInteger(15)); |
7413
9c78545361b3
more LongFloat definitions for Win32
Claus Gittinger <cg@exept.de>
parents:
7405
diff
changeset
|
849 |
} |
24267 | 850 |
if (sizeof(LONGFLOAT_t) == 16) { /* amd64, x86_64 */ |
25036 | 851 |
RETURN (__mkSmallInteger(15)); |
16780 | 852 |
} |
853 |
#else |
|
24267 | 854 |
if (sizeof(LONGFLOAT_t) == 16) { |
25036 | 855 |
RETURN (__mkSmallInteger(15)); /* sparc */ |
16780 | 856 |
} |
15263 | 857 |
#endif |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
858 |
%}. |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
859 |
"systems without longFloat support use doubles instead" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
860 |
self basicNew basicSize == Float basicNew basicSize ifTrue:[ |
25036 | 861 |
^ Float numBitsInExponent |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
862 |
]. |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
863 |
self error:'missing definition' "ifdef missing in above primitive code for this architecture" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
864 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
865 |
" |
25027 | 866 |
1.0 asLongFloat numBitsInExponent -> 15 |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
867 |
" |
24205 | 868 |
|
869 |
"Modified (comment): / 28-05-2019 / 09:02:06 / Claus Gittinger" |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
870 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
871 |
|
7382 | 872 |
numBitsInIntegerPart |
25027 | 873 |
"answer the number of bits in the integer part of the mantissa. |
874 |
This will return 0 or 1; 1 if there is no hidden bit, 0 if there is. |
|
875 |
See https://en.wikipedia.org/wiki/Extended_precision. |
|
876 |
||
10333 | 877 |
i386: This is an 80bit longfloat stored in 96 bits (upper 16 bits are unused), |
25036 | 878 |
where 1 bit is used for the integer part in the mantissa: |
879 |
00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
|
15327 | 880 |
x86_64: This is an 80bit longfloat stored in 128 bits (upper 48 bits are unused), |
25036 | 881 |
where 1+63 bits are available in the mantissa: |
882 |
00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
|
16780 | 883 |
sparc & others: This is an 128bit longfloat, |
25036 | 884 |
where 112 bits are available in the mantissa: |
885 |
seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm... |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
886 |
" |
16780 | 887 |
%{ /* NOCONTEXT */ |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
888 |
#if defined(__x86__) || defined(__x86_64__) |
24267 | 889 |
if (sizeof(LONGFLOAT_t) == 10) { /* x86 - WIN32: 80bit floats */ |
25036 | 890 |
RETURN (__mkSmallInteger(1)); |
15263 | 891 |
} |
24267 | 892 |
if (sizeof(LONGFLOAT_t) == 12) { /* x86 - some other unixes: 96bit floats*/ |
25036 | 893 |
RETURN (__mkSmallInteger(1)); |
7413
9c78545361b3
more LongFloat definitions for Win32
Claus Gittinger <cg@exept.de>
parents:
7405
diff
changeset
|
894 |
} |
24267 | 895 |
if (sizeof(LONGFLOAT_t) == 16) { |
25036 | 896 |
RETURN (__mkSmallInteger(1)); /* amd64, x86_64 */ |
16780 | 897 |
} |
15263 | 898 |
#else |
24267 | 899 |
if (sizeof(LONGFLOAT_t) == 16) { |
25036 | 900 |
RETURN (__mkSmallInteger(0)); /* sparc */ |
16780 | 901 |
} |
15263 | 902 |
#endif |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
903 |
%}. |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
904 |
"systems without longFloat support use doubles instead" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
905 |
self basicNew basicSize == Float basicNew basicSize ifTrue:[ |
25036 | 906 |
^ Float numBitsInIntegerPart |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
907 |
]. |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
908 |
self error:'missing definition' "ifdef missing in above primitive code for this architecture" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
909 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
910 |
" |
16659 | 911 |
self numBitsInIntegerPart |
24205 | 912 |
1.0 asLongFloat numBitsInIntegerPart |
913 |
1.0 asFloat numBitsInIntegerPart |
|
914 |
1.0 asShortFloat numBitsInIntegerPart |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
915 |
" |
24205 | 916 |
|
24470 | 917 |
"Modified: / 24-07-2019 / 10:33:11 / Claus Gittinger" |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
918 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
919 |
|
7382 | 920 |
numBitsInMantissa |
25027 | 921 |
"answer the number of bits in the mantissa (the significant) |
24190 | 922 |
the hidden bit is not counted here: |
923 |
||
10333 | 924 |
i386: This is an 80bit longfloat stored in 96 bits (upper 16 bits are unused), |
25036 | 925 |
where 1+63 bits are available in the mantissa: |
926 |
00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
|
15327 | 927 |
x86_64: This is an 80bit longfloat stored in 128 bits (upper 48 bits are unused), |
25036 | 928 |
where 1+63 bits are available in the mantissa: |
929 |
00000000 00000000 seeeeeee eeeeeeee immmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
|
10333 | 930 |
sparc: This is an 128bit longfloat, |
25036 | 931 |
where 112 bits are available in the mantissa: |
932 |
seeeeeee eeeeeeee mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm... |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
933 |
" |
16780 | 934 |
%{ /* NOCONTEXT */ |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
935 |
#if defined(__x86__) || defined(__x86_64__) |
24267 | 936 |
if (sizeof(LONGFLOAT_t) == 10) { /* x86 - WIN32: 80bit */ |
25036 | 937 |
RETURN (__mkSmallInteger(64)); |
15263 | 938 |
} |
24267 | 939 |
if (sizeof(LONGFLOAT_t) == 12) { /* x86 some unixes: 96bit */ |
25036 | 940 |
RETURN (__mkSmallInteger(64)); |
7413
9c78545361b3
more LongFloat definitions for Win32
Claus Gittinger <cg@exept.de>
parents:
7405
diff
changeset
|
941 |
} |
24267 | 942 |
if (sizeof(LONGFLOAT_t) == 16) { |
25036 | 943 |
RETURN (__mkSmallInteger(64)); /* amd64, x86_64 */ |
16780 | 944 |
} |
15263 | 945 |
#else |
24267 | 946 |
if (sizeof(LONGFLOAT_t) == 16) { |
25036 | 947 |
RETURN (__mkSmallInteger(112)); /* sparc */ |
16780 | 948 |
} |
15263 | 949 |
#endif |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
950 |
%}. |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
951 |
"systems without longFloat support use doubles instead" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
952 |
self basicNew basicSize == Float basicNew basicSize ifTrue:[ |
25036 | 953 |
^ Float numBitsInMantissa |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
954 |
]. |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
955 |
self error:'missing definition' "ifdef missing in above primitive code for this architecture" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
956 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
957 |
" |
19329
52f5c0de20b4
LongFloat printing under mingw was broken (wrong printf called)
Claus Gittinger <cg@exept.de>
parents:
19324
diff
changeset
|
958 |
1.0 class numBitsInMantissa |
52f5c0de20b4
LongFloat printing under mingw was broken (wrong printf called)
Claus Gittinger <cg@exept.de>
parents:
19324
diff
changeset
|
959 |
1.0 asShortFloat class numBitsInMantissa |
52f5c0de20b4
LongFloat printing under mingw was broken (wrong printf called)
Claus Gittinger <cg@exept.de>
parents:
19324
diff
changeset
|
960 |
1.0 asLongFloat class numBitsInMantissa |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
961 |
" |
24190 | 962 |
|
25013 | 963 |
" |
964 |
1.0 asLongFloat numBitsInExponent 15 |
|
965 |
1.0 asLongFloat numBitsInMantissa 64 |
|
966 |
1.0 asLongFloat precision 64 |
|
967 |
1.0 asLongFloat decimalPrecision 19 |
|
968 |
1.0 asLongFloat eBias 16383 |
|
969 |
1.0 asLongFloat emin -16382 |
|
970 |
1.0 asLongFloat emax 16383 |
|
25036 | 971 |
1.0 asLongFloat fmin |
25013 | 972 |
1.0 asLongFloat fmax 1.189731495357231765E+4932 |
973 |
" |
|
974 |
||
24190 | 975 |
"Modified: / 27-05-2019 / 15:28:04 / Claus Gittinger" |
24205 | 976 |
"Modified (comment): / 28-05-2019 / 09:02:36 / Claus Gittinger" |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
977 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
978 |
|
7382 | 979 |
radix |
24438 | 980 |
"answer the radix of a LongFloat's exponent |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
981 |
This is an IEEE float, which is represented as binary" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
982 |
|
8635 | 983 |
^ 2 "must be careful here, whenever ST/X is used on VAX or a 370" |
24438 | 984 |
|
985 |
"Modified (comment): / 19-07-2019 / 17:28:16 / Claus Gittinger" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
986 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
987 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
988 |
!LongFloat methodsFor:'arithmetic'! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
989 |
|
7382 | 990 |
* aNumber |
11729 | 991 |
"return the product of the receiver and the argument." |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
992 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
993 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
994 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
995 |
OBJ newFloat; |
24267 | 996 |
LONGFLOAT_t result, val; |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
997 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
998 |
if (__isSmallInteger(aNumber)) { |
24267 | 999 |
val = (LONGFLOAT_t)(__intVal(aNumber)); |
10333 | 1000 |
doMul: |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1001 |
result = __longFloatVal(self) * val; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1002 |
__qMKLFLOAT(newFloat, result); |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1003 |
RETURN ( newFloat ); |
10333 | 1004 |
} |
7372 | 1005 |
if (aNumber != nil) { |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1006 |
if (__qIsLongFloat(aNumber)) { |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1007 |
val = __longFloatVal(aNumber); |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1008 |
goto doMul; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1009 |
} |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1010 |
if (__qIsFloatLike(aNumber)) { |
24267 | 1011 |
val = (LONGFLOAT_t)(__floatVal(aNumber)); |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1012 |
goto doMul; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1013 |
} |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1014 |
if (__qIsShortFloat(aNumber)) { |
24267 | 1015 |
val = (LONGFLOAT_t)(__shortFloatVal(aNumber)); |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1016 |
goto doMul; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1017 |
} |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1018 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1019 |
%}. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1020 |
^ aNumber productFromLongFloat:self |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1021 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1022 |
|
7382 | 1023 |
+ aNumber |
1024 |
"return the sum of the receiver and the argument, aNumber" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1025 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1026 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1027 |
OBJ newFloat; |
24267 | 1028 |
LONGFLOAT_t result, val; |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1029 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1030 |
if (__isSmallInteger(aNumber)) { |
24267 | 1031 |
val = (LONGFLOAT_t)(__intVal(aNumber)); |
10333 | 1032 |
doAdd: |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1033 |
result = __longFloatVal(self) + val; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1034 |
__qMKLFLOAT(newFloat, result); |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1035 |
RETURN ( newFloat ); |
10333 | 1036 |
} |
7372 | 1037 |
if (aNumber != nil) { |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1038 |
if (__qIsLongFloat(aNumber)) { |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1039 |
val = __longFloatVal(aNumber); |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1040 |
goto doAdd; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1041 |
} |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1042 |
if (__qIsFloatLike(aNumber)) { |
24267 | 1043 |
val = (LONGFLOAT_t)(__floatVal(aNumber)); |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1044 |
goto doAdd; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1045 |
} |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1046 |
if (__qIsShortFloat(aNumber)) { |
24267 | 1047 |
val = (LONGFLOAT_t)(__shortFloatVal(aNumber)); |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1048 |
goto doAdd; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1049 |
} |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1050 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1051 |
%}. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1052 |
^ aNumber sumFromLongFloat:self |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1053 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1054 |
|
7382 | 1055 |
- aNumber |
1056 |
"return the difference of the receiver and the argument, aNumber" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1057 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1058 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1059 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1060 |
OBJ newFloat; |
24267 | 1061 |
LONGFLOAT_t result, val; |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1062 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1063 |
if (__isSmallInteger(aNumber)) { |
24267 | 1064 |
val = (LONGFLOAT_t)(__intVal(aNumber)); |
10333 | 1065 |
doSub: |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1066 |
result = __longFloatVal(self) - val; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1067 |
__qMKLFLOAT(newFloat, result); |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1068 |
RETURN ( newFloat ); |
10333 | 1069 |
} |
7372 | 1070 |
if (aNumber != nil) { |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1071 |
if (__qIsLongFloat(aNumber)) { |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1072 |
val = __longFloatVal(aNumber); |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1073 |
goto doSub; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1074 |
} |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1075 |
if (__qIsFloatLike(aNumber)) { |
24267 | 1076 |
val = (LONGFLOAT_t)(__floatVal(aNumber)); |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1077 |
goto doSub; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1078 |
} |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1079 |
if (__qIsShortFloat(aNumber)) { |
24267 | 1080 |
val = (LONGFLOAT_t)(__shortFloatVal(aNumber)); |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1081 |
goto doSub; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1082 |
} |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1083 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1084 |
%}. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1085 |
^ aNumber differenceFromLongFloat:self |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1086 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1087 |
|
7382 | 1088 |
/ aNumber |
1089 |
"return the quotient of the receiver and the argument, aNumber" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1090 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1091 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1092 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1093 |
OBJ newFloat; |
24267 | 1094 |
LONGFLOAT_t result, val; |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1095 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1096 |
if (__isSmallInteger(aNumber)) { |
24267 | 1097 |
val = (LONGFLOAT_t)(__intVal(aNumber)); |
10333 | 1098 |
doDiv: |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1099 |
if (val == 0.0) goto badArg; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1100 |
|
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1101 |
result = __longFloatVal(self) / val; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1102 |
__qMKLFLOAT(newFloat, result); |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1103 |
RETURN ( newFloat ); |
10333 | 1104 |
} |
7372 | 1105 |
if (aNumber != nil) { |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1106 |
if (__qIsLongFloat(aNumber)) { |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1107 |
val = __longFloatVal(aNumber); |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1108 |
goto doDiv; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1109 |
} |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1110 |
if (__qIsFloatLike(aNumber)) { |
24267 | 1111 |
val = (LONGFLOAT_t)(__floatVal(aNumber)); |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1112 |
goto doDiv; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1113 |
} |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1114 |
if (__qIsShortFloat(aNumber)) { |
24267 | 1115 |
val = (LONGFLOAT_t)(__shortFloatVal(aNumber)); |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1116 |
goto doDiv; |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1117 |
} |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1118 |
} |
10333 | 1119 |
badArg: ; |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1120 |
%}. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1121 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1122 |
" |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1123 |
No, you shalt not divide by zero |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1124 |
" |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
1125 |
^ ZeroDivide raiseRequestWith:thisContext. |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1126 |
]. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1127 |
^ aNumber quotientFromLongFloat:self |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1128 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1129 |
|
14743 | 1130 |
abs |
1131 |
"return the absolute value of the receiver |
|
1132 |
reimplemented here for speed" |
|
1133 |
||
1134 |
%{ /* NOCONTEXT */ |
|
1135 |
||
1136 |
OBJ newFloat; |
|
24267 | 1137 |
LONGFLOAT_t val = __longFloatVal(self); |
1138 |
||
1139 |
if (val < (LONGFLOAT_t)0.0) { |
|
14743 | 1140 |
__qMKLFLOAT(newFloat, -val); |
1141 |
RETURN ( newFloat ); |
|
1142 |
} |
|
1143 |
RETURN (self); |
|
1144 |
%}. |
|
1145 |
||
1146 |
" |
|
1147 |
3.0 asLongFloat abs |
|
1148 |
-3.0 asLongFloat abs |
|
1149 |
" |
|
1150 |
! |
|
1151 |
||
1152 |
negated |
|
1153 |
"return myself negated" |
|
1154 |
||
1155 |
%{ /* NOCONTEXT */ |
|
1156 |
OBJ newFloat; |
|
24267 | 1157 |
LONGFLOAT_t rslt = - __longFloatVal(self); |
14743 | 1158 |
|
1159 |
__qMKLFLOAT(newFloat, rslt); |
|
1160 |
RETURN ( newFloat ); |
|
1161 |
%}. |
|
1162 |
! |
|
1163 |
||
14691 | 1164 |
rem: aNumber |
1165 |
"return the floating point remainder of the receiver and the argument, aNumber" |
|
1166 |
||
1167 |
%{ /* NOCONTEXT */ |
|
1168 |
||
1169 |
/* |
|
1170 |
* notice: |
|
1171 |
* the following inline code handles some common cases, |
|
1172 |
* and exists as an optimization, to speed up those cases. |
|
1173 |
* |
|
1174 |
* Conceptionally, (and for most other argument types), |
|
1175 |
* mixed arithmetic is implemented by double dispatching |
|
1176 |
* (see the message send at the bottom) |
|
1177 |
*/ |
|
1178 |
OBJ newFloat; |
|
24267 | 1179 |
LONGFLOAT_t result, val; |
14691 | 1180 |
|
1181 |
if (__isSmallInteger(aNumber)) { |
|
1182 |
if (aNumber != __mkSmallInteger(0)) { |
|
24267 | 1183 |
val = (LONGFLOAT_t)__intVal(aNumber); |
14691 | 1184 |
if (val == 0.0) goto badArg; |
1185 |
computeResult: |
|
1186 |
result = fmodl(__longFloatVal(self), val) ; |
|
1187 |
__qMKLFLOAT(newFloat, result); |
|
1188 |
RETURN ( newFloat ); |
|
1189 |
} |
|
1190 |
} else if (__isFloatLike(aNumber)) { |
|
24267 | 1191 |
val = (LONGFLOAT_t)__floatVal(aNumber); |
14691 | 1192 |
goto computeResult; |
1193 |
} else if (__isShortFloat(aNumber)) { |
|
24267 | 1194 |
val = (LONGFLOAT_t)__shortFloatVal(aNumber); |
14691 | 1195 |
goto computeResult; |
1196 |
} else if (__isLongFloat(aNumber)) { |
|
1197 |
val = __longFloatVal(aNumber); |
|
1198 |
goto computeResult; |
|
1199 |
} |
|
1200 |
badArg: ; |
|
1201 |
%}. |
|
1202 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
|
1203 |
" |
|
1204 |
No, you shalt not divide by zero |
|
1205 |
" |
|
1206 |
^ ZeroDivide raiseRequestWith:thisContext. |
|
1207 |
]. |
|
1208 |
^ aNumber remainderFromLongFloat:self |
|
1209 |
! |
|
1210 |
||
7382 | 1211 |
uncheckedDivide:aNumber |
1212 |
"return the quotient of the receiver and the argument, aNumber. |
|
7471 | 1213 |
Do not check for divide by zero (return NaN or Infinity). |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1214 |
This operation is provided for emulators of other languages/semantics, |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1215 |
where no exception is raised for these results (i.e. Java). |
18842 | 1216 |
It is only defined if the argument's type is the same as the receiver's." |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1217 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1218 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1219 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1220 |
OBJ newFloat; |
24267 | 1221 |
LONGFLOAT_t result, val; |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1222 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1223 |
if (__isSmallInteger(aNumber)) { |
24267 | 1224 |
val = (LONGFLOAT_t)(__intVal(aNumber)); |
10333 | 1225 |
doDiv: |
19266 | 1226 |
result = __longFloatVal(self) / val; |
1227 |
__qMKLFLOAT(newFloat, result); |
|
1228 |
RETURN ( newFloat ); |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1229 |
} |
7372 | 1230 |
if (aNumber != nil) { |
19266 | 1231 |
if (__qIsLongFloat(aNumber)) { |
1232 |
val = __longFloatVal(aNumber); |
|
1233 |
goto doDiv; |
|
1234 |
} |
|
1235 |
if (__qIsShortFloat(aNumber)) { |
|
24267 | 1236 |
val = (LONGFLOAT_t)(__shortFloatVal(aNumber)); |
19266 | 1237 |
goto doDiv; |
1238 |
} |
|
1239 |
if (__qIsFloatLike(aNumber)) { |
|
24267 | 1240 |
val = (LONGFLOAT_t)(__floatVal(aNumber)); |
19266 | 1241 |
goto doDiv; |
1242 |
} |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1243 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1244 |
%}. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1245 |
^ aNumber quotientFromLongFloat:self |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1246 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1247 |
" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1248 |
0.0 asLongFloat uncheckedDivide:0 |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1249 |
1.0 asLongFloat uncheckedDivide:0.0 |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1250 |
-1.0 asLongFloat uncheckedDivide:0.0 |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1251 |
" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1252 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1253 |
|
5257 | 1254 |
!LongFloat methodsFor:'coercing & converting'! |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1255 |
|
7382 | 1256 |
asFloat |
1257 |
"return a Float with same value as the receiver. |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1258 |
Raises an error if the receiver exceeds the float range." |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1259 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1260 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1261 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1262 |
OBJ newFloat; |
24267 | 1263 |
LONGFLOAT_t lVal = __longFloatVal(self); |
24255 | 1264 |
double dVal = (double)lVal; |
1265 |
||
1266 |
if (isfinite(dVal) || !isfinite(lVal)) { |
|
24948 | 1267 |
__qMKFLOAT(newFloat, dVal); |
1268 |
RETURN ( newFloat ); |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1269 |
} |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1270 |
%}. |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1271 |
" |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1272 |
value out of range |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1273 |
if you need -INF for a zero receiver, try Number trapInfinity:[...] |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1274 |
" |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1275 |
^ self class |
24948 | 1276 |
raise:#infiniteResultSignal |
1277 |
receiver:self |
|
1278 |
selector:#asFloat |
|
1279 |
arguments:#() |
|
1280 |
errorString:'receiver is out of the double-precision float range' |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1281 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1282 |
" |
10333 | 1283 |
1.0 asLongFloat |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1284 |
" |
24292 | 1285 |
|
1286 |
"Modified: / 08-06-2019 / 14:33:10 / Claus Gittinger" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1287 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1288 |
|
7382 | 1289 |
asInteger |
1290 |
"return an integer with same value - might truncate" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1291 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1292 |
%{ /* NOCONTEXT */ |
24267 | 1293 |
LONGFLOAT_t fVal; |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1294 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1295 |
fVal = __longFloatVal(self); |
24267 | 1296 |
if (!LONG_isnan(fVal) && (fVal >= (LONGFLOAT_t)_MIN_INT) && (fVal <= (LONGFLOAT_t)_MAX_INT)) { |
10333 | 1297 |
RETURN ( __mkSmallInteger( (INT)fVal) ); |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1298 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1299 |
%}. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1300 |
^ super asInteger |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1301 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1302 |
" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1303 |
12345.0 asLongFloat asInteger |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1304 |
1e15 asLongFloat asInteger |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1305 |
" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1306 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1307 |
|
7382 | 1308 |
asLongFloat |
15021 | 1309 |
"return a LongFloat with same value as the receiver - that's me" |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1310 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1311 |
^ self |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1312 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1313 |
|
7382 | 1314 |
asShortFloat |
1315 |
"return a ShortFloat with same value as the receiver. |
|
24292 | 1316 |
Raises an error if the receiver exceeds the short float range." |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4305
diff
changeset
|
1317 |
|
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4305
diff
changeset
|
1318 |
%{ /* NOCONTEXT */ |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4305
diff
changeset
|
1319 |
|
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4305
diff
changeset
|
1320 |
OBJ newFloat; |
24267 | 1321 |
LONGFLOAT_t lVal = __longFloatVal(self); |
24255 | 1322 |
float fVal = (float)lVal; |
1323 |
||
1324 |
if (isfinite(fVal) || !isfinite(lVal)) { |
|
24948 | 1325 |
__qMKSFLOAT(newFloat, fVal); |
1326 |
RETURN ( newFloat ); |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1327 |
} |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1328 |
%}. |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1329 |
" |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1330 |
value out of range |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1331 |
if you need -INF for a zero receiver, try Number trapInfinity:[...] |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1332 |
" |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1333 |
^ self class |
24948 | 1334 |
raise:#infiniteResultSignal |
1335 |
receiver:self |
|
1336 |
selector:#asShortFloat |
|
1337 |
arguments:#() |
|
1338 |
errorString:'receiver is out of the single-precision float range' |
|
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4305
diff
changeset
|
1339 |
|
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4305
diff
changeset
|
1340 |
" |
10333 | 1341 |
1.0 asLongFloat asShortFloat |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1342 |
|
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1343 |
out of range: |
24948 | 1344 |
3.5028234664e+38 asShortFloat |
1345 |
-3.5028234664e+38 asShortFloat |
|
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4305
diff
changeset
|
1346 |
" |
24292 | 1347 |
|
1348 |
"Modified: / 08-06-2019 / 14:33:23 / Claus Gittinger" |
|
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4305
diff
changeset
|
1349 |
! |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4305
diff
changeset
|
1350 |
|
7382 | 1351 |
coerce:aNumber |
18833 | 1352 |
"convert the argument aNumber into an instance of the receiver's class and return it." |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1353 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1354 |
^ aNumber asLongFloat |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1355 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1356 |
|
7382 | 1357 |
generality |
1358 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1359 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1360 |
^ 90 |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1361 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1362 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1363 |
!LongFloat methodsFor:'comparing'! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1364 |
|
7382 | 1365 |
< aNumber |
1366 |
"return true, if the argument is greater" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1367 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1368 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1369 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1370 |
if (__isSmallInteger(aNumber)) { |
24267 | 1371 |
RETURN ( (__longFloatVal(self) < (LONGFLOAT_t)(__intVal(aNumber))) ? true : false ); |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1372 |
} |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1373 |
if (aNumber != nil) { |
7372 | 1374 |
if (__qIsLongFloat(aNumber)) { |
1375 |
RETURN ( (__longFloatVal(self) < __longFloatVal(aNumber)) ? true : false ); |
|
1376 |
} |
|
1377 |
if (__qIsFloatLike(aNumber)) { |
|
24267 | 1378 |
RETURN ( (__longFloatVal(self) < (LONGFLOAT_t)(__floatVal(aNumber))) ? true : false ); |
7372 | 1379 |
} |
1380 |
if (__qIsShortFloat(aNumber)) { |
|
24267 | 1381 |
RETURN ( (__longFloatVal(self) < (LONGFLOAT_t)(__shortFloatVal(aNumber))) ? true : false ); |
7372 | 1382 |
} |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1383 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1384 |
%}. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1385 |
^ aNumber lessFromLongFloat:self |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1386 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1387 |
" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1388 |
1.0 asLongFloat > (1/3) |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1389 |
1.0 asLongFloat > (1/3) asLongFloat |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1390 |
" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1391 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1392 |
|
7382 | 1393 |
<= aNumber |
1394 |
"return true, if the argument is greater or equal" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1395 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1396 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1397 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1398 |
if (__isSmallInteger(aNumber)) { |
24267 | 1399 |
RETURN ( (__longFloatVal(self) <= (LONGFLOAT_t)(__intVal(aNumber))) ? true : false ); |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1400 |
} |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1401 |
if (aNumber != nil) { |
7372 | 1402 |
if (__qIsLongFloat(aNumber)) { |
1403 |
RETURN ( (__longFloatVal(self) <= __longFloatVal(aNumber)) ? true : false ); |
|
1404 |
} |
|
1405 |
if (__qIsFloatLike(aNumber)) { |
|
24267 | 1406 |
RETURN ( (__longFloatVal(self) <= (LONGFLOAT_t)(__floatVal(aNumber))) ? true : false ); |
7372 | 1407 |
} |
1408 |
if (__qIsShortFloat(aNumber)) { |
|
24267 | 1409 |
RETURN ( (__longFloatVal(self) <= (LONGFLOAT_t)(__shortFloatVal(aNumber))) ? true : false ); |
7372 | 1410 |
} |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1411 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1412 |
%}. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1413 |
^ self retry:#<= coercing:aNumber |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1414 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1415 |
|
7382 | 1416 |
= aNumber |
1417 |
"return true, if the argument represents the same numeric value |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1418 |
as the receiver, false otherwise" |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1419 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1420 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1421 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1422 |
if (__isSmallInteger(aNumber)) { |
24267 | 1423 |
RETURN ( (__longFloatVal(self) == (LONGFLOAT_t)(__intVal(aNumber))) ? true : false ); |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1424 |
} |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1425 |
if (aNumber != nil) { |
7372 | 1426 |
if (__qIsLongFloat(aNumber)) { |
1427 |
RETURN ( (__longFloatVal(self) == __longFloatVal(aNumber)) ? true : false ); |
|
1428 |
} |
|
1429 |
if (__qIsFloatLike(aNumber)) { |
|
24267 | 1430 |
RETURN ( (__longFloatVal(self) == (LONGFLOAT_t)(__floatVal(aNumber))) ? true : false ); |
7372 | 1431 |
} |
1432 |
if (__qIsShortFloat(aNumber)) { |
|
24267 | 1433 |
RETURN ( (__longFloatVal(self) == (LONGFLOAT_t)(__shortFloatVal(aNumber))) ? true : false ); |
7372 | 1434 |
} |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1435 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1436 |
%}. |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1437 |
^ aNumber equalFromLongFloat:self |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1438 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1439 |
|
7382 | 1440 |
> aNumber |
1441 |
"return true, if the argument is less" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1442 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1443 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1444 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1445 |
if (__isSmallInteger(aNumber)) { |
24267 | 1446 |
RETURN ( (__longFloatVal(self) > (LONGFLOAT_t)(__intVal(aNumber))) ? true : false ); |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1447 |
} |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1448 |
if (aNumber != nil) { |
7372 | 1449 |
if (__qIsLongFloat(aNumber)) { |
1450 |
RETURN ( (__longFloatVal(self) > __longFloatVal(aNumber)) ? true : false ); |
|
1451 |
} |
|
1452 |
if (__qIsFloatLike(aNumber)) { |
|
24267 | 1453 |
RETURN ( (__longFloatVal(self) > (LONGFLOAT_t)(__floatVal(aNumber))) ? true : false ); |
7372 | 1454 |
} |
1455 |
if (__qIsShortFloat(aNumber)) { |
|
24267 | 1456 |
RETURN ( (__longFloatVal(self) > (LONGFLOAT_t)(__shortFloatVal(aNumber))) ? true : false ); |
7372 | 1457 |
} |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1458 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1459 |
%}. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1460 |
^ self retry:#> coercing:aNumber |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1461 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1462 |
|
7382 | 1463 |
>= aNumber |
1464 |
"return true, if the argument is less or equal" |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1465 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1466 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1467 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1468 |
if (__isSmallInteger(aNumber)) { |
24267 | 1469 |
RETURN ( (__longFloatVal(self) >= (LONGFLOAT_t)(__intVal(aNumber))) ? true : false ); |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1470 |
} |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1471 |
if (aNumber != nil) { |
7372 | 1472 |
if (__qIsLongFloat(aNumber)) { |
1473 |
RETURN ( (__longFloatVal(self) >= __longFloatVal(aNumber)) ? true : false ); |
|
1474 |
} |
|
1475 |
if (__qIsFloatLike(aNumber)) { |
|
24267 | 1476 |
RETURN ( (__longFloatVal(self) >= (LONGFLOAT_t)(__floatVal(aNumber))) ? true : false ); |
7372 | 1477 |
} |
1478 |
if (__qIsShortFloat(aNumber)) { |
|
24267 | 1479 |
RETURN ( (__longFloatVal(self) >= (LONGFLOAT_t)(__shortFloatVal(aNumber))) ? true : false ); |
7372 | 1480 |
} |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1481 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1482 |
%}. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1483 |
^ self retry:#>= coercing:aNumber |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1484 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1485 |
|
7382 | 1486 |
hash |
1487 |
"return a number for hashing; redefined, since floats compare |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1488 |
by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1489 |
as 3 hash." |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1490 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1491 |
|i| |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1492 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1493 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
7372 | 1494 |
i := self asInteger. |
1495 |
self = i ifTrue:[ |
|
1496 |
^ i hash |
|
1497 |
]. |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1498 |
]. |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1499 |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1500 |
^ self asFloat hash |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1501 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1502 |
" |
10333 | 1503 |
1.2345 hash |
1504 |
1.2345 asLongFloat hash |
|
1505 |
1 hash |
|
1506 |
1.0 hash |
|
1507 |
1.0 asLongFloat hash |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1508 |
" |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1509 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1510 |
|
22855 | 1511 |
isAlmostEqualTo:aNumber nEpsilon:nE |
1512 |
"return true, if the argument, aNumber represents almost the same numeric value |
|
1513 |
as the receiver, false otherwise. |
|
1514 |
||
1515 |
nE is the number of minimal float distances, that the numbers may differ and |
|
1516 |
still be considered equal. |
|
1517 |
||
1518 |
For background information why floats need this |
|
1519 |
read: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ |
|
1520 |
" |
|
1521 |
||
1522 |
Epsilon isNil ifTrue:[ |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1523 |
Epsilon := self class computeEpsilon. |
22855 | 1524 |
]. |
1525 |
||
1526 |
%{ /* NOCONTEXT */ |
|
1527 |
#ifdef INT128 |
|
1528 |
/* |
|
1529 |
* notice: |
|
1530 |
* the following inline code handles some common cases, |
|
1531 |
* and exists as an optimization, to speed up those cases. |
|
1532 |
* |
|
1533 |
* Conceptionally, (and for most other argument types), |
|
1534 |
* mixed arithmetic is implemented by double dispatching |
|
1535 |
* (see the message send at the bottom) |
|
1536 |
*/ |
|
1537 |
||
1538 |
INT128 ulpDiff; |
|
1539 |
union { |
|
24267 | 1540 |
LONGFLOAT_t f; |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1541 |
INT128 i; |
22855 | 1542 |
} myself, otherFloat; |
1543 |
int nEpsilon; |
|
24267 | 1544 |
LONGFLOAT_t scaledEpsilon; |
22855 | 1545 |
|
1546 |
if (!__isSmallInteger(nE)) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1547 |
goto tryHarder; |
22855 | 1548 |
} |
1549 |
||
1550 |
nEpsilon = __intVal(nE); |
|
1551 |
scaledEpsilon = nEpsilon *__longFloatVal(@global(Epsilon)); |
|
1552 |
||
1553 |
if (__isSmallInteger(aNumber)) { |
|
24267 | 1554 |
otherFloat.f = (LONGFLOAT_t)(__intVal(aNumber)); |
22855 | 1555 |
} else if (aNumber == nil) { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1556 |
RETURN(false) |
22855 | 1557 |
} else if (__qIsLongFloat(aNumber)) { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1558 |
otherFloat.f = __longFloatVal(aNumber); |
22855 | 1559 |
} else if (__qIsFloatLike(aNumber)) { |
24267 | 1560 |
otherFloat.f = (LONGFLOAT_t)(__floatVal(aNumber)); |
22855 | 1561 |
} else if (__qIsShortFloat(aNumber)) { |
24267 | 1562 |
otherFloat.f = (LONGFLOAT_t)(__shortFloatVal(aNumber)); |
22855 | 1563 |
} else { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1564 |
goto tryHarder; |
22855 | 1565 |
} |
1566 |
||
1567 |
myself.f = __longFloatVal(self); |
|
1568 |
||
1569 |
// Check if the numbers are really close -- needed |
|
1570 |
// when comparing numbers near zero (ULP method below fails for numbers near 0!). |
|
1571 |
if (fabsl(myself.f - otherFloat.f) <= scaledEpsilon) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1572 |
RETURN(true); |
22855 | 1573 |
} |
1574 |
||
1575 |
// if the signs differ, the numbers are different |
|
1576 |
if ((myself.f >= 0) != (otherFloat.f >= 0)) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1577 |
RETURN(false); |
22855 | 1578 |
} |
1579 |
||
1580 |
// compute the difference of the 'units in the last place" ULP |
|
1581 |
// (if ulpDiff == 1, two floats are adjecant) |
|
1582 |
ulpDiff = myself.i - otherFloat.i; |
|
1583 |
if (ulpDiff < 0) ulpDiff = -ulpDiff; |
|
1584 |
if (ulpDiff <= nEpsilon) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1585 |
RETURN(true); |
22855 | 1586 |
} else { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1587 |
RETURN(false) |
22855 | 1588 |
} |
1589 |
||
1590 |
tryHarder:; |
|
1591 |
#endif // INT128 |
|
1592 |
%}. |
|
1593 |
^ super isAlmostEqualTo:aNumber nEpsilon:nE. |
|
1594 |
||
1595 |
" |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1596 |
67329.234q isAlmostEqualTo:67329.234q + self epsilon nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1597 |
1.0 asLongFloat isAlmostEqualTo:1.0001 nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1598 |
1.0 asLongFloat isAlmostEqualTo:-1.0 nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1599 |
1.0 asLongFloat isAlmostEqualTo:1 nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1600 |
0.0 asLongFloat isAlmostEqualTo:0 nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24205
diff
changeset
|
1601 |
0.0 asLongFloat isAlmostEqualTo:self epsilon nEpsilon:1 |
22855 | 1602 |
" |
1603 |
||
1604 |
"Created: / 09-05-2018 / 23:31:18 / stefan" |
|
1605 |
"Modified: / 10-05-2018 / 01:03:24 / stefan" |
|
1606 |
! |
|
1607 |
||
7382 | 1608 |
~= aNumber |
1609 |
"return true, if the arguments value are not equal." |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1610 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1611 |
%{ /* NOCONTEXT */ |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1612 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1613 |
if (__isSmallInteger(aNumber)) { |
24267 | 1614 |
RETURN ( (__longFloatVal(self) != (LONGFLOAT_t)(__intVal(aNumber))) ? true : false ); |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1615 |
} |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1616 |
if (aNumber != nil) { |
7372 | 1617 |
if (__isLongFloat(aNumber)) { |
1618 |
RETURN ( (__longFloatVal(self) != __longFloatVal(aNumber)) ? true : false ); |
|
1619 |
} |
|
1620 |
if (__qIsFloatLike(aNumber)) { |
|
24267 | 1621 |
RETURN ( (__longFloatVal(self) != (LONGFLOAT_t)(__floatVal(aNumber))) ? true : false ); |
7372 | 1622 |
} |
1623 |
if (__qIsShortFloat(aNumber)) { |
|
24267 | 1624 |
RETURN ( (__longFloatVal(self) != (LONGFLOAT_t)(__shortFloatVal(aNumber))) ? true : false ); |
7372 | 1625 |
} |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1626 |
} else { |
7372 | 1627 |
RETURN ( true ); |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1628 |
} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1629 |
%}. |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1630 |
^ super ~= aNumber |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1631 |
! ! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1632 |
|
24190 | 1633 |
!LongFloat methodsFor:'copying'! |
1634 |
||
1635 |
deepCopy |
|
1636 |
"return a deep copy of myself |
|
1637 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
1638 |
||
1639 |
^ self |
|
1640 |
! |
|
1641 |
||
1642 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
1643 |
"return a deep copy of myself |
|
1644 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
1645 |
||
1646 |
^ self |
|
1647 |
! |
|
1648 |
||
1649 |
shallowCopy |
|
1650 |
"return a shallow copy of the receiver" |
|
1651 |
||
1652 |
^ self |
|
1653 |
! |
|
1654 |
||
1655 |
simpleDeepCopy |
|
1656 |
"return a deep copy of the receiver |
|
1657 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
1658 |
||
1659 |
^ self |
|
1660 |
! ! |
|
1661 |
||
10319 | 1662 |
!LongFloat methodsFor:'double dispatching'! |
1663 |
||
1664 |
productFromInteger:anInteger |
|
24276 | 1665 |
"sent when an integer does not know how to multiply the receiver, self" |
10319 | 1666 |
|
1667 |
%{ /* NOCONTEXT */ |
|
1668 |
||
1669 |
OBJ newFloat; |
|
24267 | 1670 |
LONGFLOAT_t result; |
10319 | 1671 |
|
1672 |
if (__isSmallInteger(anInteger)) { |
|
24267 | 1673 |
result = __longFloatVal(self) * (LONGFLOAT_t)(__intVal(anInteger)); |
10319 | 1674 |
retResult: |
10333 | 1675 |
__qMKLFLOAT(newFloat, result); |
1676 |
RETURN ( newFloat ); |
|
1677 |
} |
|
10319 | 1678 |
%}. |
1679 |
^ super productFromInteger:anInteger |
|
1680 |
! |
|
1681 |
||
1682 |
sumFromInteger:anInteger |
|
24276 | 1683 |
"sent when an integer does not know how to add the receiver, self" |
10319 | 1684 |
|
1685 |
%{ /* NOCONTEXT */ |
|
1686 |
||
1687 |
OBJ newFloat; |
|
24267 | 1688 |
LONGFLOAT_t result; |
10319 | 1689 |
|
1690 |
if (__isSmallInteger(anInteger)) { |
|
24267 | 1691 |
result = __longFloatVal(self) + (LONGFLOAT_t)(__intVal(anInteger)); |
10319 | 1692 |
retResult: |
10333 | 1693 |
__qMKLFLOAT(newFloat, result); |
1694 |
RETURN ( newFloat ); |
|
1695 |
} |
|
10319 | 1696 |
%}. |
1697 |
^ super sumFromInteger:anInteger |
|
1698 |
! ! |
|
1699 |
||
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1700 |
!LongFloat methodsFor:'mathematical functions'! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1701 |
|
7382 | 1702 |
exp |
1703 |
"return e raised to the power of the receiver" |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1704 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1705 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1706 |
|
10333 | 1707 |
%{ |
7374 | 1708 |
#if defined(LONG_exp) |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1709 |
|
24267 | 1710 |
LONGFLOAT_t rslt; |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1711 |
OBJ newFloat; |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1712 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1713 |
__threadErrno = 0; |
7374 | 1714 |
rslt = LONG_exp(__longFloatVal(self)); |
7383 | 1715 |
# ifdef LONG_isnan |
1716 |
if (! LONG_isnan(rslt)) |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1717 |
# endif |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1718 |
if (__threadErrno == 0) { |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1719 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1720 |
RETURN ( newFloat ); |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1721 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1722 |
#else |
7395 | 1723 |
useFallBack = true; |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1724 |
#endif |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1725 |
%}. |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1726 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1727 |
^ super exp |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1728 |
]. |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1729 |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1730 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1731 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1732 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1733 |
selector:#exp |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1734 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1735 |
errorString:'bad receiver in exp' |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1736 |
! |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1737 |
|
7382 | 1738 |
ln |
1739 |
"return the natural logarithm of myself. |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1740 |
Raises an exception, if the receiver is less or equal to zero." |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1741 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1742 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1743 |
|
10333 | 1744 |
%{ |
7374 | 1745 |
#if defined(LONG_log) |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1746 |
|
24267 | 1747 |
LONGFLOAT_t val, rslt; |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1748 |
OBJ newFloat; |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1749 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1750 |
val = __longFloatVal(self); |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1751 |
|
22790 | 1752 |
/* |
1753 |
* to suppress the warnBox opened by win32 |
|
21951 | 1754 |
* to avoid returning -INF from some unix math libs (__osx__) |
1755 |
*/ |
|
1756 |
if (val > 0.0) { |
|
22790 | 1757 |
__threadErrno = 0; |
1758 |
rslt = LONG_log(val); |
|
7382 | 1759 |
# ifdef LONG_isnan |
22790 | 1760 |
if (! LONG_isnan(rslt)) |
7372 | 1761 |
# endif |
22790 | 1762 |
{ |
1763 |
if (__threadErrno == 0) { |
|
1764 |
__qMKLFLOAT(newFloat, rslt); |
|
1765 |
RETURN ( newFloat ); |
|
1766 |
} |
|
1767 |
} |
|
7372 | 1768 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1769 |
#else |
7395 | 1770 |
useFallBack = true; |
7372 | 1771 |
#endif |
1772 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1773 |
useFallBack notNil ifTrue:[ |
22790 | 1774 |
^ super ln |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1775 |
]. |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1776 |
|
7372 | 1777 |
" |
1778 |
an invalid value for logarithm |
|
21971 | 1779 |
if you need -INF for a zero receiver, try Number trapInfinity:[...] |
7372 | 1780 |
" |
1781 |
^ self class |
|
22790 | 1782 |
raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal]) |
1783 |
receiver:self |
|
1784 |
selector:#ln |
|
1785 |
arguments:#() |
|
1786 |
errorString:'bad receiver in ln (not strictly positive)' |
|
21951 | 1787 |
|
21971 | 1788 |
"Modified (comment): / 03-07-2017 / 15:57:57 / cg" |
7372 | 1789 |
! |
1790 |
||
1791 |
log10 |
|
21826 | 1792 |
"return the base-10 logarithm of the receiver. |
7372 | 1793 |
Raises an exception, if the receiver is less or equal to zero." |
1794 |
||
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1795 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1796 |
|
10333 | 1797 |
%{ |
7374 | 1798 |
#if defined(LONG_log10) |
7372 | 1799 |
|
24267 | 1800 |
LONGFLOAT_t val, rslt; |
7372 | 1801 |
OBJ newFloat; |
1802 |
||
1803 |
val = __longFloatVal(self); |
|
1804 |
||
22790 | 1805 |
/* |
1806 |
* to suppress the warnBox opened by win32 |
|
21954 | 1807 |
* to avoid returning -INF from some unix math libs (__osx__) |
1808 |
*/ |
|
1809 |
if (val > 0.0) { |
|
22790 | 1810 |
__threadErrno = 0; |
1811 |
rslt = LONG_log10(val); |
|
7382 | 1812 |
# ifdef LONG_isnan |
22790 | 1813 |
if (! LONG_isnan(rslt)) |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1814 |
# endif |
22790 | 1815 |
{ |
1816 |
if (__threadErrno == 0) { |
|
1817 |
__qMKLFLOAT(newFloat, rslt); |
|
1818 |
RETURN ( newFloat ); |
|
1819 |
} |
|
1820 |
} |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1821 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1822 |
#else |
7395 | 1823 |
useFallBack = true; |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1824 |
#endif |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1825 |
%}. |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1826 |
useFallBack notNil ifTrue:[ |
22790 | 1827 |
^ super log10 |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1828 |
]. |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1829 |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1830 |
" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1831 |
an invalid value for logarithm |
21971 | 1832 |
if you need -INF for a zero receiver, try Number trapInfinity:[...] |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1833 |
" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1834 |
^ self class |
22790 | 1835 |
raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal]) |
1836 |
receiver:self |
|
1837 |
selector:#log10 |
|
1838 |
arguments:#() |
|
1839 |
errorString:'bad receiver in log10 (not strictly positive)' |
|
21954 | 1840 |
|
21971 | 1841 |
"Modified (comment): / 03-07-2017 / 15:58:06 / cg" |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1842 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1843 |
|
7382 | 1844 |
raisedTo:aNumber |
1845 |
"return self raised to the power of aNumber" |
|
1846 |
||
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1847 |
|n useFallBack| |
7382 | 1848 |
|
1849 |
n := aNumber asFloat. |
|
1850 |
%{ |
|
1851 |
#if defined(LONG_pow) |
|
24267 | 1852 |
LONGFLOAT_t rslt; |
7382 | 1853 |
OBJ newFloat; |
1854 |
||
1855 |
if (__isFloatLike(n)) { |
|
22790 | 1856 |
__threadErrno = 0; |
1857 |
rslt = LONG_pow(__longFloatVal(self), __floatVal(n)); |
|
7382 | 1858 |
# ifdef LONG_isnan |
22790 | 1859 |
if (! LONG_isnan(rslt)) |
7382 | 1860 |
# endif |
22790 | 1861 |
{ |
1862 |
if (__threadErrno == 0) { |
|
1863 |
__qMKLFLOAT(newFloat, rslt); |
|
1864 |
RETURN ( newFloat ); |
|
1865 |
} |
|
1866 |
} |
|
7382 | 1867 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1868 |
#else |
7395 | 1869 |
useFallBack = true; |
7382 | 1870 |
#endif |
1871 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1872 |
useFallBack notNil ifTrue:[ |
22790 | 1873 |
^ super raisedTo:aNumber |
19090 | 1874 |
]. |
1875 |
||
21914 | 1876 |
"/ the c-library pow function, has a bug: |
19266 | 1877 |
"/ it does not deal correctly with negative numbers. |
19090 | 1878 |
"/ I.e. it raises an error on -8^(1/3) instead of returning a negative -2 |
1879 |
"/ work around with a kludge: |
|
1880 |
self < 0 ifTrue:[ |
|
22790 | 1881 |
^ (self negated raisedTo:n) negated |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1882 |
]. |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1883 |
|
7382 | 1884 |
" |
1885 |
an invalid argument (not convertable to float ?) |
|
1886 |
" |
|
1887 |
^ self class |
|
22790 | 1888 |
raise:#domainErrorSignal |
1889 |
receiver:self |
|
1890 |
selector:#raisedTo: |
|
1891 |
arguments:(Array with:aNumber) |
|
1892 |
errorString:'bad receiver/arg in raisedTo:' |
|
21914 | 1893 |
|
1894 |
"Modified: / 22-06-2017 / 15:54:59 / cg" |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1895 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1896 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1897 |
sqrt |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1898 |
"return the square root of myself. |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1899 |
Raises an exception, if the receiver is less than zero." |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1900 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1901 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1902 |
|
10333 | 1903 |
%{ |
7374 | 1904 |
#if defined(LONG_sqrt) |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1905 |
|
24267 | 1906 |
LONGFLOAT_t val, rslt; |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1907 |
OBJ newFloat; |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1908 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1909 |
val = __longFloatVal(self); |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1910 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
1911 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1912 |
if (val >= 0.0) |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1913 |
# endif |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1914 |
{ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1915 |
__threadErrno = 0; |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1916 |
rslt = LONG_sqrt(val); |
7382 | 1917 |
# ifdef LONG_isnan |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1918 |
if (! LONG_isnan(rslt)) |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1919 |
# endif |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1920 |
{ |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1921 |
if (__threadErrno == 0) { |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1922 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1923 |
RETURN ( newFloat ); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1924 |
} |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1925 |
} |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1926 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1927 |
#else |
7395 | 1928 |
useFallBack = true; |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1929 |
#endif |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1930 |
%}. |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1931 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1932 |
^ super sqrt |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1933 |
]. |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1934 |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1935 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1936 |
raise:#imaginaryResultSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1937 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1938 |
selector:#sqrt |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1939 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
1940 |
errorString:'bad (negative) receiver in sqrt' |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1941 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1942 |
" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1943 |
10 asLongFloat sqrt |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1944 |
-10 asLongFloat sqrt |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1945 |
" |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1946 |
|
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
1947 |
"Modified: / 16.11.2001 / 14:14:43 / cg" |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1948 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1949 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1950 |
!LongFloat methodsFor:'printing & storing'! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
1951 |
|
22300 | 1952 |
printOn:aStream |
1953 |
"append a printed representation of the receiver to |
|
1954 |
the argument, aStream. |
|
1955 |
||
1956 |
I use #printString instead of #printOn: as basic print mechanism." |
|
1957 |
||
1958 |
aStream nextPutAll:self printString |
|
1959 |
||
1960 |
"Created: / 10-10-2017 / 14:05:22 / cg" |
|
1961 |
! |
|
1962 |
||
7382 | 1963 |
printString |
1964 |
"return a printed representation of the receiver |
|
1965 |
LimitedPrecisonReal and its subclasses use #printString instead of |
|
1966 |
#printOn: as basic print mechanism." |
|
1967 |
||
18137 | 1968 |
^ self printStringWithFormat:DefaultPrintFormat |
1969 |
||
1970 |
" |
|
24818 | 1971 |
LongFloat pi printString. |
1972 |
1.234 asLongFloat printString. |
|
1973 |
1.0 asLongFloat printString. |
|
1974 |
1e10 asLongFloat printString. |
|
1975 |
1.2e3 asLongFloat printString. |
|
1976 |
1.2e30 asLongFloat printString. |
|
1977 |
(1.0 uncheckedDivide:0) asLongFloat printString. |
|
1978 |
(0.0 uncheckedDivide:0) asLongFloat printString. |
|
1979 |
self pi printString. |
|
1980 |
||
1981 |
DecimalPointCharacterForPrinting := $,. |
|
1982 |
1.234 asLongFloat printString. |
|
1983 |
1.0 asLongFloat printString. |
|
1984 |
1e10 asLongFloat printString. |
|
1985 |
1.2e3 asLongFloat printString. |
|
1986 |
1.2e30 asLongFloat printString. |
|
1987 |
(1.0 uncheckedDivide:0) asLongFloat printString. |
|
1988 |
(0.0 uncheckedDivide:0) asLongFloat printString. |
|
1989 |
DecimalPointCharacterForPrinting := $. |
|
18137 | 1990 |
" |
1991 |
! |
|
1992 |
||
1993 |
printStringWithFormat:format |
|
1994 |
"return a printed representation of the receiver; |
|
1995 |
fmt must be of the form: .nn, where nn is the number of digits. |
|
1996 |
To print 6 valid digits, use printStringWithFormat:'.6' |
|
1997 |
For Floats, the default used in printString, is 15 (because its a double); |
|
1998 |
for ShortFloats, it is 6 (because it is a float)" |
|
1999 |
||
7382 | 2000 |
%{ /* NOCONTEXT */ |
2001 |
||
2002 |
char buffer[64]; |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2003 |
char fmtBuffer[20]; |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2004 |
char *fmt; |
7382 | 2005 |
REGISTER char *cp; |
2006 |
OBJ s; |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2007 |
int len ; |
7382 | 2008 |
|
18137 | 2009 |
if (__isStringLike(format)) { |
18363 | 2010 |
fmt = (char *) __stringVal(format); |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2011 |
} else { |
18363 | 2012 |
fmt = ".19"; |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2013 |
} |
7382 | 2014 |
/* |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2015 |
* build a printf format string |
7382 | 2016 |
*/ |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2017 |
fmtBuffer[0] = '%'; |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2018 |
strncpy(fmtBuffer+1, fmt, 10); |
24267 | 2019 |
if (sizeof(LONGFLOAT_t) == sizeof(double)) { |
7382 | 2020 |
#ifdef SYSV |
18363 | 2021 |
strcat(fmtBuffer, "lg"); |
7382 | 2022 |
#else |
18363 | 2023 |
strcat(fmtBuffer, "G"); |
7382 | 2024 |
#endif |
2025 |
} else { |
|
18363 | 2026 |
strcat(fmtBuffer, "LG"); |
7382 | 2027 |
} |
2028 |
||
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2029 |
/* |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2030 |
* actually only needed on sparc: since thisContext is |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2031 |
* in a global register, which gets destroyed by printf, |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2032 |
* manually save it here - very stupid ... |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2033 |
*/ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2034 |
__BEGIN_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2035 |
len = snprintf(buffer, sizeof(buffer), fmtBuffer, __longFloatVal(self)); |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2036 |
__END_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2037 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2038 |
if (len >= 0 && len < sizeof(buffer)-3) { |
18363 | 2039 |
/* |
2040 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
|
2041 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
|
2042 |
*/ |
|
2043 |
for (cp = buffer; *cp; cp++) { |
|
2044 |
if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break; |
|
2045 |
} |
|
2046 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
|
2047 |
if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
|
2048 |
*cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
|
2049 |
} else { |
|
2050 |
*cp++ = '.'; |
|
2051 |
} |
|
2052 |
*cp++ = '0'; |
|
2053 |
*cp = '\0'; |
|
2054 |
} else { |
|
2055 |
if (cp && (*cp == '.')) { |
|
2056 |
if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
|
2057 |
*cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
|
2058 |
} |
|
2059 |
} |
|
2060 |
} |
|
2061 |
||
2062 |
s = __MKSTRING(buffer); |
|
2063 |
if (s != nil) { |
|
2064 |
RETURN (s); |
|
2065 |
} |
|
7382 | 2066 |
} |
2067 |
%}. |
|
2068 |
" |
|
2069 |
memory allocation (for the new string) failed. |
|
2070 |
When we arrive here, there was no memory, even after a garbage collect. |
|
2071 |
This means, that the VM wanted to get some more memory from the |
|
2072 |
OS, which was not kind enough to give it. |
|
2073 |
Bad luck - you should increase the swap space on your machine. |
|
2074 |
" |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20419
diff
changeset
|
2075 |
^ AllocationFailure raise. |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2076 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2077 |
" |
18363 | 2078 |
1.234 asLongFloat printString. |
2079 |
1.0 asLongFloat printString. |
|
2080 |
1e10 asLongFloat printString. |
|
2081 |
1.2e3 asLongFloat printString. |
|
2082 |
1.2e30 asLongFloat printString. |
|
19329
52f5c0de20b4
LongFloat printing under mingw was broken (wrong printf called)
Claus Gittinger <cg@exept.de>
parents:
19324
diff
changeset
|
2083 |
(1.0 uncheckedDivide:0) isInfinite. |
52f5c0de20b4
LongFloat printing under mingw was broken (wrong printf called)
Claus Gittinger <cg@exept.de>
parents:
19324
diff
changeset
|
2084 |
(0.0 uncheckedDivide:0) isNaN. |
52f5c0de20b4
LongFloat printing under mingw was broken (wrong printf called)
Claus Gittinger <cg@exept.de>
parents:
19324
diff
changeset
|
2085 |
(1.0 uncheckedDivide:0) asLongFloat isInfinite. |
52f5c0de20b4
LongFloat printing under mingw was broken (wrong printf called)
Claus Gittinger <cg@exept.de>
parents:
19324
diff
changeset
|
2086 |
(0.0 uncheckedDivide:0) asLongFloat isNaN. |
18363 | 2087 |
(1.0 uncheckedDivide:0) asLongFloat printString. |
2088 |
(0.0 uncheckedDivide:0) asLongFloat printString. |
|
2089 |
self pi printString. |
|
2090 |
||
2091 |
DecimalPointCharacterForPrinting := $,. |
|
2092 |
1.234 asLongFloat printString. |
|
2093 |
1.0 asLongFloat printString. |
|
2094 |
1e10 asLongFloat printString. |
|
2095 |
1.2e3 asLongFloat printString. |
|
2096 |
1.2e30 asLongFloat printString. |
|
2097 |
(1.0 uncheckedDivide:0) asLongFloat printString. |
|
2098 |
(0.0 uncheckedDivide:0) asLongFloat printString. |
|
2099 |
DecimalPointCharacterForPrinting := $. |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2100 |
" |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
2101 |
! |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2102 |
|
7382 | 2103 |
printfPrintString:formatString |
24691 | 2104 |
<unsave> |
2105 |
||
7746 | 2106 |
"non-standard: return a printed representation of the receiver |
7382 | 2107 |
as specified by formatString, which is defined by printf. |
21951 | 2108 |
|
7382 | 2109 |
If you use this, be aware, that specifying long doubles differs on |
10333 | 2110 |
systems; on Linux/gnuc machines you have to give something like %LF/%LG. |
7382 | 2111 |
Also, the resulting string may not be longer than 255 bytes - |
20419 | 2112 |
since that's the (static) size of the buffer. |
22790 | 2113 |
|
11925
6c93ef7cb9ff
changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents:
11729
diff
changeset
|
2114 |
This method is NONSTANDARD and may be removed without notice. |
24691 | 2115 |
|
2116 |
WARNING: this goes directly to the C-printf function and may therefore me inherently unsafe. |
|
11925
6c93ef7cb9ff
changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents:
11729
diff
changeset
|
2117 |
Please use the printf: method, which is safe as it is completely implemented in Smalltalk." |
7382 | 2118 |
|
25013 | 2119 |
%{ /* STACK: 16000 */ |
24691 | 2120 |
#ifndef __SCHTEAM__ |
25013 | 2121 |
char buffer[1024]; |
7382 | 2122 |
OBJ s; |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2123 |
int len; |
7382 | 2124 |
|
12476
66b5104cedc9
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11925
diff
changeset
|
2125 |
if (__isStringLike(formatString)) { |
25036 | 2126 |
/* |
2127 |
* actually only needed on sparc: since thisContext is |
|
2128 |
* in a global register, which gets destroyed by printf, |
|
2129 |
* manually save it here - very stupid ... |
|
2130 |
*/ |
|
2131 |
__BEGIN_PROTECT_REGISTERS__ |
|
2132 |
||
2133 |
len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __longFloatVal(self)); |
|
2134 |
||
2135 |
__END_PROTECT_REGISTERS__ |
|
2136 |
||
2137 |
if (len < 0) goto fail; |
|
2138 |
if (len >= sizeof(buffer)) goto fail; |
|
2139 |
||
2140 |
s = __MKSTRING_L(buffer, len); |
|
2141 |
if (s != nil) { |
|
2142 |
RETURN (s); |
|
2143 |
} |
|
7382 | 2144 |
} |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7831
diff
changeset
|
2145 |
fail: ; |
24691 | 2146 |
#endif /* not __SCHTEAM__ */ |
7382 | 2147 |
%}. |
21907 | 2148 |
^ super printfPrintString:formatString |
7382 | 2149 |
|
2150 |
" |
|
10333 | 2151 |
Float pi asLongFloat printfPrintString:'%%LG -> %LG' |
2152 |
Float pi asLongFloat printfPrintString:'%%LF -> %LF' |
|
2153 |
Float pi asLongFloat printfPrintString:'%%7.15LG -> %7.15LG' |
|
2154 |
Float pi asLongFloat printfPrintString:'%%7.15LF -> %7.15LF' |
|
7382 | 2155 |
" |
21907 | 2156 |
|
21951 | 2157 |
"Modified (comment): / 03-07-2017 / 15:11:48 / cg" |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2158 |
! |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2159 |
|
22300 | 2160 |
storeOn:aStream |
2161 |
"append a printed representation of the receiver to |
|
2162 |
the argument, aStream. |
|
2163 |
||
2164 |
I use #storeString instead of #storeOn: as basic store mechanism." |
|
2165 |
||
2166 |
aStream nextPutAll:self storeString |
|
2167 |
||
2168 |
"Created: / 10-10-2017 / 14:06:46 / cg" |
|
2169 |
! |
|
2170 |
||
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2171 |
storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2172 |
"return a printed representation of the receiver; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2173 |
all valid digits are printed. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2174 |
LimitedPrecisonReal and its subclasses use #storeString instead of |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2175 |
#storeOn: as basic print mechanism." |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2176 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2177 |
%{ /* NOCONTEXT */ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2178 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2179 |
char buffer[64]; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2180 |
REGISTER char *cp; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2181 |
OBJ s; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2182 |
int len; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2183 |
char *fmtBuffer; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2184 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2185 |
/* |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2186 |
* build a printf format string |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2187 |
*/ |
24267 | 2188 |
if (sizeof(LONGFLOAT_t) == sizeof(double)) { |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
2189 |
#ifdef SYSV |
18363 | 2190 |
fmtBuffer = "%.17lg"; |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
2191 |
#else |
18363 | 2192 |
fmtBuffer = "%.17G"; |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
2193 |
#endif |
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
2194 |
} else { |
18363 | 2195 |
fmtBuffer = "%.20LG"; |
14673
d3c91be01e96
setlocale only once and for all in stxmain
Claus Gittinger <cg@exept.de>
parents:
14600
diff
changeset
|
2196 |
} |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2197 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2198 |
__BEGIN_PROTECT_REGISTERS__ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2199 |
len = snprintf(buffer, sizeof(buffer), fmtBuffer, __longFloatVal(self)); |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2200 |
__END_PROTECT_REGISTERS__ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2201 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2202 |
if (len >= 0 && len < sizeof(buffer)-3) { |
18363 | 2203 |
/* |
2204 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
|
2205 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
|
2206 |
*/ |
|
2207 |
for (cp = buffer; *cp; cp++) { |
|
2208 |
if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break; |
|
2209 |
} |
|
2210 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
|
2211 |
*cp++ = '.'; |
|
2212 |
*cp++ = '0'; |
|
2213 |
*cp = '\0'; |
|
2214 |
} |
|
2215 |
||
2216 |
s = __MKSTRING(buffer); |
|
2217 |
if (s != nil) { |
|
2218 |
RETURN (s); |
|
2219 |
} |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2220 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2221 |
%}. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2222 |
" |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2223 |
memory allocation (for the new string) failed. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2224 |
When we arrive here, there was no memory, even after a garbage collect. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2225 |
This means, that the VM wanted to get some more memory from the |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2226 |
OS, which was not kind enough to give it. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2227 |
Bad luck - you should increase the swap space on your machine. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2228 |
" |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20419
diff
changeset
|
2229 |
^ AllocationFailure raise. |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2230 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2231 |
" |
18363 | 2232 |
1.0 asLongFloat storeString |
2233 |
1.234 asLongFloat storeString |
|
2234 |
1e10 asLongFloat storeString |
|
2235 |
1.2e3 asLongFloat storeString |
|
2236 |
1.2e30 asLongFloat storeString |
|
2237 |
LongFloat pi asLongFloat storeString |
|
2238 |
(1.0 uncheckedDivide:0) asLongFloat storeString |
|
2239 |
(0.0 uncheckedDivide:0) asLongFloat storeString |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2240 |
|
9122
858a4118a135
comment; decimalPoint classVars renamed
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
2241 |
notice that the storeString is NOT affected by DecimalPointCharacterForPrinting: |
858a4118a135
comment; decimalPoint classVars renamed
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
2242 |
|
18363 | 2243 |
DecimalPointCharacterForPrinting := $,. |
2244 |
1.234 asLongFloat storeString. |
|
2245 |
1.0 asLongFloat storeString. |
|
2246 |
1e10 asLongFloat storeString. |
|
2247 |
1.2e3 asLongFloat storeString. |
|
2248 |
1.2e30 asLongFloat storeString. |
|
2249 |
(1.0 uncheckedDivide:0) asLongFloat storeString. |
|
2250 |
(0.0 uncheckedDivide:0) asLongFloat storeString. |
|
2251 |
DecimalPointCharacterForPrinting := $. |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2252 |
" |
5885
91ff479e693b
added #defaultNumberOfDigits
Claus Gittinger <cg@exept.de>
parents:
5822
diff
changeset
|
2253 |
! ! |
91ff479e693b
added #defaultNumberOfDigits
Claus Gittinger <cg@exept.de>
parents:
5822
diff
changeset
|
2254 |
|
7415 | 2255 |
!LongFloat methodsFor:'private-accessing'! |
2256 |
||
2257 |
basicAt:index |
|
2258 |
"return an internal byte of the float. |
|
2259 |
The value returned here depends on byte order, float representation etc. |
|
2260 |
Therefore, this method should be used strictly private. |
|
2261 |
||
10333 | 2262 |
Notice: |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2263 |
the need to redefine this method here is due to the |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2264 |
inability of many machines to store floats in non-double aligned memory. |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2265 |
Therefore, on some machines, the first <nPad> bytes of a float are left unused, |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2266 |
and the actual float is stored at index <nPad>+1 ... |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2267 |
To hide this at one place, this method knows about that, and returns |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2268 |
values as if this filler wasnt present." |
7415 | 2269 |
|
2270 |
%{ /* NOCONTEXT */ |
|
2271 |
||
2272 |
register int indx; |
|
2273 |
unsigned char *cp; |
|
2274 |
||
2275 |
/* |
|
2276 |
* notice the missing test for self being a nonNilObject - |
|
2277 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
2278 |
* and SmallInteger |
|
2279 |
*/ |
|
2280 |
if (__isSmallInteger(index)) { |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2281 |
indx = __intVal(index) - 1; |
24267 | 2282 |
if (((unsigned)(indx)) < sizeof(LONGFLOAT_t)) { |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2283 |
cp = (unsigned char *)(& (__LongFloatInstPtr(self)->f_longfloatvalue)); |
8913 | 2284 |
RETURN ( __mkSmallInteger(cp[indx] & 0xFF) ); |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2285 |
} |
7415 | 2286 |
} |
2287 |
%}. |
|
2288 |
^ self indexNotIntegerOrOutOfBounds:index |
|
2289 |
! |
|
2290 |
||
2291 |
basicAt:index put:value |
|
2292 |
"set an internal byte of the float. |
|
2293 |
The value to be stored here depends on byte order, float representation etc. |
|
2294 |
Therefore, this method should be used strictly private. |
|
2295 |
||
10333 | 2296 |
Notice: |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2297 |
the need to redefine this method here is due to the |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2298 |
inability of many machines to store floats in non-double aligned memory. |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2299 |
Therefore, on some machines, the first <nPad> bytes of a float are left unused, |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2300 |
and the actual float is stored at index <nPad>+1 .. . |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2301 |
To hide this at one place, this method knows about that, and returns |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2302 |
values as if this filler wasnt present." |
7415 | 2303 |
|
2304 |
%{ /* NOCONTEXT */ |
|
2305 |
register int indx, val; |
|
2306 |
unsigned char *cp; |
|
2307 |
||
2308 |
/* |
|
2309 |
* notice the missing test for self being a nonNilObject - |
|
2310 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
2311 |
* and SmallInteger |
|
2312 |
*/ |
|
2313 |
if (__bothSmallInteger(index, value)) { |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2314 |
val = __intVal(value); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2315 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2316 |
indx = __intVal(index) - 1; |
24267 | 2317 |
if (((unsigned)(indx)) < sizeof(LONGFLOAT_t)) { |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2318 |
cp = (unsigned char *)(& (__LongFloatInstPtr(self)->f_longfloatvalue)); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2319 |
cp[indx] = val; |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2320 |
RETURN ( value ); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2321 |
} |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2322 |
} |
7415 | 2323 |
} |
2324 |
%}. |
|
2325 |
value isInteger ifFalse:[ |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2326 |
" |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2327 |
the object to store should be an integer number |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2328 |
" |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2329 |
^ self elementNotInteger |
7415 | 2330 |
]. |
2331 |
(value between:0 and:255) ifFalse:[ |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2332 |
" |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2333 |
the object to store must be a bytes value |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2334 |
" |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2335 |
^ self elementBoundsError:value |
7415 | 2336 |
]. |
2337 |
^ self indexNotIntegerOrOutOfBounds:index |
|
2338 |
! |
|
2339 |
||
2340 |
basicSize |
|
2341 |
"return the size in bytes of the float. |
|
2342 |
||
10333 | 2343 |
Notice: |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2344 |
the need to redefine this method here is due to the |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2345 |
inability of many machines to store floats in non-double aligned memory. |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2346 |
Therefore, on some machines, the first <nPad> bytes of a float are left unused, |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2347 |
and the actual float is stored at index <nPad>+1 ... |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2348 |
To hide this at one place, this method knows about that, and returns |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2349 |
values as if this filler wasnt present." |
7415 | 2350 |
|
2351 |
%{ /* NOCONTEXT */ |
|
2352 |
||
24267 | 2353 |
RETURN (__mkSmallInteger(sizeof(LONGFLOAT_t))); |
7415 | 2354 |
%}. |
22258 | 2355 |
! |
2356 |
||
2357 |
byteAt:index |
|
2358 |
^ self basicAt:index |
|
2359 |
! |
|
2360 |
||
2361 |
byteAt:index put:newByte |
|
2362 |
self shouldNotImplement |
|
7415 | 2363 |
! ! |
2364 |
||
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2365 |
!LongFloat methodsFor:'special access'! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2366 |
|
7382 | 2367 |
exponent |
24965 | 2368 |
"extract a normalized float's (unbiased) exponent. |
7382 | 2369 |
The returned value depends on the float-representation of |
2370 |
the underlying machine and is therefore highly unportable. |
|
2371 |
This is not for general use. |
|
2372 |
This assumes that the mantissa is normalized to |
|
21851 | 2373 |
0.5 .. 1.0 and the float's value is mantissa * 2^exp" |
7382 | 2374 |
|
2375 |
%{ /* NOCONTEXT */ |
|
2376 |
||
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2377 |
#if defined(LONG_frexp) |
8913 | 2378 |
int exp; |
7382 | 2379 |
|
2380 |
LONG_frexp( __longFloatVal(self), &exp); |
|
14743 | 2381 |
RETURN (__mkSmallInteger(exp)); |
7382 | 2382 |
#endif |
2383 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2384 |
^ super exponent |
7382 | 2385 |
|
2386 |
" |
|
14745 | 2387 |
4.0q exponent |
2388 |
2.0q exponent |
|
2389 |
1.0q exponent |
|
2390 |
0.5q exponent |
|
2391 |
0.25q exponent |
|
2392 |
0.00000011111q exponent |
|
21851 | 2393 |
1.0q1000 exponent |
7382 | 2394 |
" |
21851 | 2395 |
|
2396 |
"Modified (comment): / 20-06-2017 / 11:20:40 / cg" |
|
14743 | 2397 |
! |
2398 |
||
2399 |
mantissa |
|
24151 | 2400 |
"extract a normalized float's mantissa. |
14743 | 2401 |
The returned value depends on the float-representation of |
2402 |
the underlying machine and is therefore highly unportable. |
|
2403 |
This is not for general use. |
|
2404 |
This assumes that the mantissa is normalized to |
|
24151 | 2405 |
0.5 .. 1.0 and the float's value is mantissa * 2^exp" |
14743 | 2406 |
|
2407 |
%{ /* NOCONTEXT */ |
|
2408 |
#if defined(LONG_frexp) |
|
24267 | 2409 |
LONGFLOAT_t frac; |
14743 | 2410 |
int exp; |
2411 |
OBJ v; |
|
2412 |
||
2413 |
frac = LONG_frexp( __longFloatVal(self), &exp); |
|
2414 |
__qMKLFLOAT(v, frac); |
|
2415 |
RETURN (v); |
|
2416 |
#endif |
|
2417 |
%}. |
|
21851 | 2418 |
^ super mantissa |
14743 | 2419 |
|
2420 |
" |
|
14745 | 2421 |
1.0q exponent |
2422 |
1.0q asLongFloat mantissa |
|
2423 |
||
2424 |
0.5q exponent |
|
2425 |
0.5q mantissa |
|
2426 |
||
2427 |
0.25q exponent |
|
2428 |
0.25q mantissa |
|
2429 |
||
2430 |
0.00000011111q exponent |
|
2431 |
0.00000011111q mantissa |
|
25013 | 2432 |
|
2433 |
self assert:(1.0 asLongFloat mantissa * (2 raisedTo:1.0 asLongFloat exponent)) = 1.0 asLongFloat. |
|
2434 |
self assert:(100.0 asLongFloat mantissa * (2 raisedTo:100.0 asLongFloat exponent)) = 100.0 asLongFloat. |
|
2435 |
self assert:(10e15 asLongFloat mantissa * (2 raisedTo:10e15 asLongFloat exponent)) = 10e15 asLongFloat. |
|
2436 |
self assert:(10e-15 asLongFloat mantissa * (2 raisedTo:10e-15 asLongFloat exponent)) = 10e-15 asLongFloat. |
|
14743 | 2437 |
" |
21851 | 2438 |
|
2439 |
"Modified: / 20-06-2017 / 11:33:24 / cg" |
|
24151 | 2440 |
"Modified (comment): / 26-05-2019 / 03:13:08 / Claus Gittinger" |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2441 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2442 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2443 |
!LongFloat methodsFor:'testing'! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2444 |
|
7382 | 2445 |
isFinite |
24704 | 2446 |
"return true, if the receiver is a finite float (not NaN and not +/-INF)" |
7382 | 2447 |
|
2448 |
%{ /* NOCONTEXT */ |
|
2449 |
||
7396 | 2450 |
#ifdef LONG_finite |
24267 | 2451 |
LONGFLOAT_t lV = __longFloatVal(self); |
7396 | 2452 |
|
2453 |
if (LONG_finite(lV)) { |
|
24948 | 2454 |
RETURN (true); |
7396 | 2455 |
} else { |
24948 | 2456 |
RETURN (false); |
7396 | 2457 |
} |
2458 |
#else |
|
7382 | 2459 |
double dV = (double) __longFloatVal(self); |
2460 |
||
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2461 |
if (isfinite(dV)) { |
24948 | 2462 |
RETURN (true); |
7396 | 2463 |
} else { |
24948 | 2464 |
RETURN (false); |
7396 | 2465 |
} |
7382 | 2466 |
#endif |
7396 | 2467 |
%} |
7382 | 2468 |
|
2469 |
" |
|
24948 | 2470 |
1.0 asLongFloat isFinite |
2471 |
(0.0 asLongFloat uncheckedDivide: 0.0) isFinite |
|
2472 |
(1.0 asLongFloat uncheckedDivide: 0.0) isFinite |
|
2473 |
(-1.0 asLongFloat uncheckedDivide: 0.0) isFinite |
|
7382 | 2474 |
" |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2475 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2476 |
|
22100 | 2477 |
isInfinite |
24704 | 2478 |
"return true, if the receiver is an infinite float (+Inf or -Inf). |
22100 | 2479 |
These are not created by ST/X float operations (they raise an exception); |
24704 | 2480 |
however, inline C-code could produce them." |
22100 | 2481 |
|
2482 |
%{ /* NOCONTEXT */ |
|
2483 |
||
2484 |
#ifdef LONG_infinite |
|
24267 | 2485 |
LONGFLOAT_t lV = __longFloatVal(self); |
22100 | 2486 |
|
2487 |
if (LONG_infinite(lV)) { RETURN (true); } |
|
2488 |
RETURN (false); |
|
2489 |
#else |
|
2490 |
# if defined(LONG_finite) && defined(LONG_isnan) |
|
24267 | 2491 |
LONGFLOAT_t lV = __longFloatVal(self); |
22100 | 2492 |
|
2493 |
if (!LONG_finite(lV) && !LONG_isnan(lV) ) { RETURN (true); } |
|
2494 |
RETURN (false); |
|
2495 |
# endif |
|
2496 |
#endif |
|
2497 |
%}. |
|
2498 |
^ self isFinite not and:[self isNaN not] |
|
2499 |
||
2500 |
" |
|
24948 | 2501 |
1.0 asLongFloat isFinite -> true |
2502 |
1.0 asLongFloat isInfinite -> false |
|
2503 |
||
2504 |
(0.0 asLongFloat uncheckedDivide: 0.0) isFinite -> false |
|
2505 |
(0.0 asLongFloat uncheckedDivide: 0.0) isInfinite -> false |
|
2506 |
(0.0 asLongFloat uncheckedDivide: 0.0) isNaN -> true |
|
2507 |
||
2508 |
(1.0 asLongFloat uncheckedDivide: 0.0) isFinite -> false |
|
2509 |
(1.0 asLongFloat uncheckedDivide: 0.0) isInfinite -> true |
|
2510 |
(1.0 asLongFloat uncheckedDivide: 0.0) isNaN -> false |
|
2511 |
||
2512 |
(-1.0 asLongFloat uncheckedDivide: 0.0) isFinite -> false |
|
2513 |
(-1.0 asLongFloat uncheckedDivide: 0.0) isInfinite -> true |
|
2514 |
(-1.0 asLongFloat uncheckedDivide: 0.0) isNaN -> false |
|
22100 | 2515 |
" |
2516 |
||
2517 |
"Created: / 25-07-2017 / 17:04:04 / cg" |
|
2518 |
! |
|
2519 |
||
24946 | 2520 |
isLongFloat |
2521 |
"return true, if the receiver is some kind of long floating point number (iee extended precision)" |
|
2522 |
||
2523 |
^ true |
|
2524 |
||
2525 |
||
2526 |
! |
|
2527 |
||
7382 | 2528 |
isNaN |
2529 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
2530 |
These are not created by ST/X float operations (they raise an exception); |
|
24704 | 2531 |
however, inline C-code could produce them." |
7382 | 2532 |
|
2533 |
%{ /* NOCONTEXT */ |
|
2534 |
||
7396 | 2535 |
#ifdef LONG_isnan |
24267 | 2536 |
LONGFLOAT_t lV = __longFloatVal(self); |
10333 | 2537 |
if (LONG_isnan(lV)) { |
24948 | 2538 |
RETURN (true); |
7396 | 2539 |
} else { |
24948 | 2540 |
RETURN (false); |
7396 | 2541 |
} |
2542 |
#else |
|
7382 | 2543 |
double dV = (double)(__longFloatVal(self)); |
2544 |
||
7396 | 2545 |
if (isnan(dV)) { |
24948 | 2546 |
RETURN (true); |
7396 | 2547 |
} else { |
24948 | 2548 |
RETURN (false); |
7396 | 2549 |
} |
7382 | 2550 |
#endif |
7396 | 2551 |
%} |
7382 | 2552 |
|
2553 |
" |
|
24948 | 2554 |
1.0 asLongFloat isNaN |
2555 |
(0.0 asLongFloat uncheckedDivide: 0.0) isNaN |
|
7382 | 2556 |
" |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2557 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2558 |
|
17381 | 2559 |
isNegativeZero |
2560 |
"many systems have two float.Pnt zeros" |
|
2561 |
||
17395 | 2562 |
%{ /* NOCONTEXT */ |
17393 | 2563 |
#if defined(__BORLANDC__) |
24267 | 2564 |
union { LONGFLOAT_t ld; int i[3]; } __u; |
17393 | 2565 |
__u.ld = __longFloatVal(self); |
2566 |
RETURN ( (__u.ld == 0.0 && (__u.i[2] & 0x8000)) ? true : false ); |
|
17390 | 2567 |
#else |
17381 | 2568 |
RETURN ( (__longFloatVal(self) == 0.0 && signbit(__longFloatVal(self)) != 0) ? true : false ); |
17390 | 2569 |
#endif |
17381 | 2570 |
%}. |
2571 |
||
2572 |
" |
|
2573 |
0.0 asLongFloat isNegativeZero |
|
2574 |
-0.0 asLongFloat isNegativeZero |
|
2575 |
" |
|
2576 |
! |
|
2577 |
||
24329 | 2578 |
isZero |
2579 |
"return true, if the receiver is zero" |
|
2580 |
||
2581 |
^ self = 0.0 |
|
2582 |
||
2583 |
"Created: / 10-06-2019 / 22:00:23 / Claus Gittinger" |
|
2584 |
! |
|
2585 |
||
7382 | 2586 |
negative |
17381 | 2587 |
"return true if the receiver is less than zero. |
2588 |
-0.0 is positive for now." |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2589 |
|
7382 | 2590 |
%{ /* NOCONTEXT */ |
2591 |
||
17381 | 2592 |
RETURN ( __longFloatVal(self) < 0.0 ? true : false ); |
2593 |
// RETURN ( signbit(__longFloatVal(self)) != 0 ? true : false ); |
|
5411 | 2594 |
%}. |
17381 | 2595 |
|
2596 |
" |
|
18363 | 2597 |
0.0 asLongFloat negative |
2598 |
-0.0 asLongFloat negative |
|
2599 |
1.0 asLongFloat negative |
|
2600 |
-1.0 asLongFloat negative |
|
2601 |
(1.0 uncheckedDivide: 0.0) asLongFloat negative |
|
2602 |
(-1.0 uncheckedDivide: 0.0) asLongFloat negative |
|
17381 | 2603 |
" |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2604 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2605 |
|
7382 | 2606 |
numberOfBits |
2607 |
"return the size (in bits) of the real; |
|
2608 |
typically, 80 or 96 is returned here, |
|
2609 |
but who knows ..." |
|
2610 |
||
2611 |
%{ /* NOCONTEXT */ |
|
2612 |
||
24267 | 2613 |
RETURN (__mkSmallInteger (sizeof(LONGFLOAT_t) * 8)); |
7382 | 2614 |
%} |
2615 |
||
2616 |
" |
|
10333 | 2617 |
LongFloat basicNew numberOfBits |
2618 |
1.2 asLongFloat numberOfBits |
|
2619 |
1.2 asShortFloat numberOfBits |
|
2620 |
1.2 numberOfBits |
|
7382 | 2621 |
" |
5357 | 2622 |
! |
2623 |
||
7382 | 2624 |
positive |
18853 | 2625 |
"return true if the receiver is greater or equal to zero (not negative) |
17381 | 2626 |
0.0 and -0.0 are positive for now." |
7382 | 2627 |
|
2628 |
%{ /* NOCONTEXT */ |
|
2629 |
||
17381 | 2630 |
RETURN ( __longFloatVal(self) >= 0.0 ? true : false ); |
2631 |
// RETURN ( (signbit(__longFloatVal(self)) == 0 ? true : false ) ); |
|
2632 |
%}. |
|
2633 |
||
2634 |
" |
|
19266 | 2635 |
0.0 asLongFloat positive |
2636 |
-0.0 asLongFloat positive |
|
2637 |
1.0 asLongFloat positive |
|
2638 |
-1.0 asLongFloat positive |
|
2639 |
(1.0 uncheckedDivide: 0.0) asLongFloat positive |
|
2640 |
(-1.0 uncheckedDivide: 0.0) asLongFloat positive |
|
17381 | 2641 |
" |
7382 | 2642 |
! |
2643 |
||
2644 |
strictlyPositive |
|
2645 |
"return true if the receiver is greater than zero" |
|
2646 |
||
2647 |
%{ /* NOCONTEXT */ |
|
2648 |
||
2649 |
RETURN ( (__longFloatVal(self) > 0.0) ? true : false ); |
|
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2650 |
%} |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2651 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
2652 |
|
7385 | 2653 |
!LongFloat methodsFor:'trigonometric'! |
2654 |
||
2655 |
arcCos |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2656 |
"return the arccosine of the receiver (as radians). |
7385 | 2657 |
Raises an exception, if the receiver is not in -1..1" |
2658 |
||
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2659 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2660 |
|
10333 | 2661 |
%{ |
7385 | 2662 |
#if defined(LONG_acos) |
2663 |
||
24267 | 2664 |
LONGFLOAT_t val, rslt; |
7385 | 2665 |
OBJ newFloat; |
2666 |
||
2667 |
val = __longFloatVal(self); |
|
2668 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
2669 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7385 | 2670 |
if ((val >= -1.0) && (val <= 1.0)) |
2671 |
# endif |
|
2672 |
{ |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2673 |
__threadErrno = 0; |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2674 |
rslt = LONG_acos(val); |
7385 | 2675 |
# ifdef LONG_isnan |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2676 |
if (! LONG_isnan(rslt)) |
7385 | 2677 |
# endif |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2678 |
{ |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2679 |
if (__threadErrno == 0) { |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2680 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2681 |
RETURN ( newFloat ); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2682 |
} |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2683 |
} |
7385 | 2684 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2685 |
#else |
7395 | 2686 |
useFallBack = true; |
7385 | 2687 |
#endif |
2688 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2689 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2690 |
^ super arcCos |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2691 |
]. |
7385 | 2692 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2693 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2694 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2695 |
selector:#arcCos |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2696 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2697 |
errorString:'bad receiver in arcCos' |
7385 | 2698 |
|
2699 |
" |
|
2700 |
-10 asLongFloat arcCos |
|
10333 | 2701 |
1 asLongFloat arcCos |
2702 |
0.5 asLongFloat arcCos |
|
7385 | 2703 |
" |
2704 |
! |
|
2705 |
||
2706 |
arcCosh |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2707 |
"return the hyperbolic arccosine of the receiver." |
10333 | 2708 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2709 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2710 |
|
10333 | 2711 |
%{ |
7385 | 2712 |
#if defined(LONG_acosh) |
10333 | 2713 |
|
24267 | 2714 |
LONGFLOAT_t val, rslt; |
7385 | 2715 |
OBJ newFloat; |
10333 | 2716 |
|
7385 | 2717 |
val = __longFloatVal(self); |
10333 | 2718 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
2719 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2720 |
if (val >= 1.0) |
7385 | 2721 |
# endif |
2722 |
{ |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2723 |
__threadErrno = 0; |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2724 |
rslt = LONG_acosh(val); |
7385 | 2725 |
# ifdef LONG_isnan |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2726 |
if (! LONG_isnan(rslt)) |
7385 | 2727 |
# endif |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2728 |
{ |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2729 |
if (__threadErrno == 0) { |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2730 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2731 |
RETURN ( newFloat ); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2732 |
} |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2733 |
} |
7385 | 2734 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2735 |
#else |
7395 | 2736 |
useFallBack = true; |
7385 | 2737 |
#endif |
2738 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2739 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2740 |
^ super arcCosh |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2741 |
]. |
7385 | 2742 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2743 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2744 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2745 |
selector:#arcCosh |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2746 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2747 |
errorString:'bad receiver in arcCosh' |
10333 | 2748 |
|
7385 | 2749 |
" |
2750 |
-10 asLongFloat arcCosh |
|
2751 |
1 asLongFloat arcCosh |
|
2752 |
0.5 asLongFloat arcCosh |
|
2753 |
" |
|
2754 |
! |
|
2755 |
||
2756 |
arcSin |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2757 |
"return the arcsine of the receiver (as radians). |
7385 | 2758 |
Raises an exception, if the receiver is not in -1..1" |
2759 |
||
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2760 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2761 |
|
10333 | 2762 |
%{ |
7385 | 2763 |
#if defined(LONG_asin) |
2764 |
||
24267 | 2765 |
LONGFLOAT_t val, rslt; |
7385 | 2766 |
OBJ newFloat; |
2767 |
||
2768 |
val = __longFloatVal(self); |
|
2769 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
2770 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7385 | 2771 |
if ((val >= -1.0) && (val <= 1.0)) |
2772 |
# endif |
|
2773 |
{ |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2774 |
__threadErrno = 0; |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2775 |
rslt = LONG_asin(val); |
7385 | 2776 |
# ifdef LONG_isnan |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2777 |
if (! LONG_isnan(rslt)) |
7385 | 2778 |
# endif |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2779 |
{ |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2780 |
if (__threadErrno == 0) { |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2781 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2782 |
RETURN ( newFloat ); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2783 |
} |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2784 |
} |
7385 | 2785 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2786 |
#else |
7395 | 2787 |
useFallBack = true; |
7385 | 2788 |
#endif |
2789 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2790 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2791 |
^ super arcSin |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2792 |
]. |
7385 | 2793 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2794 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2795 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2796 |
selector:#arcSin |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2797 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2798 |
errorString:'bad receiver in arcSin' |
7385 | 2799 |
|
2800 |
" |
|
2801 |
-10 asLongFloat arcSin |
|
10333 | 2802 |
1 asLongFloat arcSin |
2803 |
0.5 asLongFloat arcSin |
|
7385 | 2804 |
" |
2805 |
! |
|
2806 |
||
2807 |
arcSinh |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2808 |
"return the hyperbolic arcsine of the receiver." |
10333 | 2809 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2810 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2811 |
|
10333 | 2812 |
%{ |
7385 | 2813 |
#if defined(LONG_asinh) |
10333 | 2814 |
|
24267 | 2815 |
LONGFLOAT_t val, rslt; |
7385 | 2816 |
OBJ newFloat; |
10333 | 2817 |
|
7385 | 2818 |
val = __longFloatVal(self); |
10333 | 2819 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
2820 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2821 |
if (val >= 1.0) |
7385 | 2822 |
# endif |
2823 |
{ |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2824 |
__threadErrno = 0; |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2825 |
rslt = LONG_asinh(val); |
7385 | 2826 |
# ifdef LONG_isnan |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2827 |
if (! LONG_isnan(rslt)) |
7385 | 2828 |
# endif |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2829 |
{ |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2830 |
if (__threadErrno == 0) { |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2831 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2832 |
RETURN ( newFloat ); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2833 |
} |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2834 |
} |
7385 | 2835 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2836 |
#else |
7395 | 2837 |
useFallBack = true; |
7385 | 2838 |
#endif |
2839 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2840 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2841 |
^ super arcSinh |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2842 |
]. |
7385 | 2843 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2844 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2845 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2846 |
selector:#arcSinh |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2847 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2848 |
errorString:'bad receiver in arcSinh' |
10333 | 2849 |
|
7385 | 2850 |
" |
2851 |
-10 asLongFloat arcSinh |
|
2852 |
1 asLongFloat arcSinh |
|
2853 |
0.5 asLongFloat arcSinh |
|
2854 |
" |
|
2855 |
! |
|
2856 |
||
2857 |
arcTan |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2858 |
"return the arctangent of the receiver (as radians)" |
7385 | 2859 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2860 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2861 |
|
10333 | 2862 |
%{ |
7385 | 2863 |
#if defined(LONG_atan) |
2864 |
||
24267 | 2865 |
LONGFLOAT_t rslt; |
7385 | 2866 |
OBJ newFloat; |
2867 |
||
2868 |
__threadErrno = 0; |
|
2869 |
rslt = LONG_atan(__longFloatVal(self)); |
|
2870 |
# ifdef LONG_isnan |
|
2871 |
if (! LONG_isnan(rslt)) |
|
2872 |
# endif |
|
2873 |
{ |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2874 |
if (__threadErrno == 0) { |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2875 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2876 |
RETURN ( newFloat ); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2877 |
} |
7385 | 2878 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2879 |
#else |
7395 | 2880 |
useFallBack = true; |
7385 | 2881 |
#endif |
2882 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2883 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2884 |
^ super arcTan |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2885 |
]. |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2886 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2887 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2888 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2889 |
selector:#arcTan |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2890 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2891 |
errorString:'bad receiver in arcTan' |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2892 |
! |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2893 |
|
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2894 |
arcTanh |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2895 |
"return the hyperbolic arctangent of the receiver." |
10333 | 2896 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2897 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2898 |
|
10333 | 2899 |
%{ |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2900 |
#if defined(LONG_atanh) |
10333 | 2901 |
|
24267 | 2902 |
LONGFLOAT_t val, rslt; |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2903 |
OBJ newFloat; |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2904 |
|
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2905 |
val = __longFloatVal(self); |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2906 |
__threadErrno = 0; |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19570
diff
changeset
|
2907 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2908 |
if ((val >= -1.0) && (val <= 1.0)) |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2909 |
# endif |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2910 |
{ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2911 |
rslt = LONG_atanh(val); |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2912 |
# ifdef LONG_isnan |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2913 |
if (! LONG_isnan(rslt)) |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2914 |
# endif |
22790 | 2915 |
# if defined( __osx__ ) |
2916 |
if (LONG_isfinite(rslt)) |
|
2917 |
# endif |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2918 |
{ |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2919 |
if (__threadErrno == 0) { |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2920 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2921 |
RETURN ( newFloat ); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2922 |
} |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2923 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2924 |
} |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2925 |
#else |
7395 | 2926 |
useFallBack = true; |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2927 |
#endif |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2928 |
%}. |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2929 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2930 |
^ super arcTanh |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2931 |
]. |
7385 | 2932 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2933 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2934 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2935 |
selector:#arcTanh |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2936 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2937 |
errorString:'bad receiver in arcTanh' |
7385 | 2938 |
! |
2939 |
||
2940 |
cos |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2941 |
"return the cosine of the receiver (interpreted as radians)" |
7385 | 2942 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2943 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2944 |
|
10333 | 2945 |
%{ |
7385 | 2946 |
#if defined(LONG_cos) |
2947 |
||
24267 | 2948 |
LONGFLOAT_t rslt; |
7385 | 2949 |
OBJ newFloat; |
2950 |
||
2951 |
__threadErrno = 0; |
|
2952 |
rslt = LONG_cos(__longFloatVal(self)); |
|
2953 |
# ifdef LONG_isnan |
|
2954 |
if (! LONG_isnan(rslt)) |
|
2955 |
# endif |
|
2956 |
if (__threadErrno == 0) { |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2957 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2958 |
RETURN ( newFloat ); |
7385 | 2959 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2960 |
#else |
7395 | 2961 |
useFallBack = true; |
7385 | 2962 |
#endif |
2963 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2964 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2965 |
^ super cos |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2966 |
]. |
7385 | 2967 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2968 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2969 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2970 |
selector:#cos |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2971 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2972 |
errorString:'bad receiver in cos' |
7385 | 2973 |
! |
2974 |
||
2975 |
cosh |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2976 |
"return the hyperbolic cosine of the receiver" |
10333 | 2977 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2978 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2979 |
|
10333 | 2980 |
%{ |
7385 | 2981 |
#if defined(LONG_cosh) |
10333 | 2982 |
|
24267 | 2983 |
LONGFLOAT_t rslt; |
7385 | 2984 |
OBJ newFloat; |
10333 | 2985 |
|
7385 | 2986 |
__threadErrno = 0; |
2987 |
rslt = LONG_cosh(__longFloatVal(self)); |
|
2988 |
# ifdef LONG_isnan |
|
2989 |
if (! LONG_isnan(rslt)) |
|
2990 |
# endif |
|
2991 |
if (__threadErrno == 0) { |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2992 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
2993 |
RETURN ( newFloat ); |
7385 | 2994 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2995 |
#else |
7395 | 2996 |
useFallBack = true; |
7385 | 2997 |
#endif |
2998 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2999 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3000 |
^ super cosh |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3001 |
]. |
7385 | 3002 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3003 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3004 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3005 |
selector:#cosh |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3006 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3007 |
errorString:'bad receiver in cosh' |
7385 | 3008 |
! |
3009 |
||
3010 |
sin |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3011 |
"return the sine of the receiver (interpreted as radians)" |
7385 | 3012 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3013 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3014 |
|
10333 | 3015 |
%{ |
7385 | 3016 |
#if defined(LONG_sin) |
3017 |
||
24267 | 3018 |
LONGFLOAT_t rslt; |
7385 | 3019 |
OBJ newFloat; |
3020 |
||
3021 |
__threadErrno = 0; |
|
3022 |
rslt = LONG_sin(__longFloatVal(self)); |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3023 |
# ifdef LONG_isnan |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3024 |
if (! LONG_isnan(rslt)) |
7385 | 3025 |
# endif |
3026 |
if (__threadErrno == 0) { |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3027 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3028 |
RETURN ( newFloat ); |
7385 | 3029 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3030 |
#else |
7395 | 3031 |
useFallBack = true; |
7385 | 3032 |
#endif |
3033 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3034 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3035 |
^ super sin |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3036 |
]. |
7385 | 3037 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3038 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3039 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3040 |
selector:#sin |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3041 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3042 |
errorString:'bad receiver in sin' |
7385 | 3043 |
! |
3044 |
||
3045 |
sinh |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3046 |
"return the hyperbolic sine of the receiver" |
10333 | 3047 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3048 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3049 |
|
10333 | 3050 |
%{ |
7385 | 3051 |
#if defined(LONG_sinh) |
10333 | 3052 |
|
24267 | 3053 |
LONGFLOAT_t rslt; |
7385 | 3054 |
OBJ newFloat; |
10333 | 3055 |
|
7385 | 3056 |
__threadErrno = 0; |
3057 |
rslt = LONG_sinh(__longFloatVal(self)); |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3058 |
# ifdef LONG_isnan |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3059 |
if (! LONG_isnan(rslt)) |
7385 | 3060 |
# endif |
3061 |
if (__threadErrno == 0) { |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3062 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3063 |
RETURN ( newFloat ); |
7385 | 3064 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3065 |
#else |
7395 | 3066 |
useFallBack = true; |
7385 | 3067 |
#endif |
3068 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3069 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3070 |
^ super sinh |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3071 |
]. |
7385 | 3072 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3073 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3074 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3075 |
selector:#sinh |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3076 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3077 |
errorString:'bad receiver in sinh' |
7385 | 3078 |
! |
3079 |
||
3080 |
tan |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3081 |
"return the tangens of the receiver (interpreted as radians)" |
7385 | 3082 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3083 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3084 |
|
10333 | 3085 |
%{ |
7385 | 3086 |
#if defined(LONG_tan) |
3087 |
||
24267 | 3088 |
LONGFLOAT_t rslt; |
7385 | 3089 |
OBJ newFloat; |
3090 |
||
3091 |
__threadErrno = 0; |
|
3092 |
rslt = LONG_tan(__longFloatVal(self)); |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3093 |
# ifdef LONG_isnan |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3094 |
if (! LONG_isnan(rslt)) |
7385 | 3095 |
# endif |
3096 |
if (__threadErrno == 0) { |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3097 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3098 |
RETURN ( newFloat ); |
7385 | 3099 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3100 |
#else |
7395 | 3101 |
useFallBack = true; |
7385 | 3102 |
#endif |
3103 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3104 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3105 |
^ super tan |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3106 |
]. |
7385 | 3107 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3108 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3109 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3110 |
selector:#tan |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3111 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3112 |
errorString:'bad receiver in tan' |
7385 | 3113 |
! |
3114 |
||
3115 |
tanh |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3116 |
"return the hyperbolic tangens of the receiver" |
10333 | 3117 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3118 |
|useFallBack| |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3119 |
|
10333 | 3120 |
%{ |
7385 | 3121 |
#if defined(LONG_tanh) |
24267 | 3122 |
LONGFLOAT_t rslt; |
7385 | 3123 |
OBJ newFloat; |
10333 | 3124 |
|
7385 | 3125 |
__threadErrno = 0; |
3126 |
rslt = LONG_tanh(__longFloatVal(self)); |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3127 |
# ifdef LONG_isnan |
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3128 |
if (! LONG_isnan(rslt)) |
7385 | 3129 |
# endif |
3130 |
if (__threadErrno == 0) { |
|
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3131 |
__qMKLFLOAT(newFloat, rslt); |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3132 |
RETURN ( newFloat ); |
7385 | 3133 |
} |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3134 |
#else |
7395 | 3135 |
useFallBack = true; |
7385 | 3136 |
#endif |
3137 |
%}. |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3138 |
useFallBack notNil ifTrue:[ |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3139 |
^ super tanh |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3140 |
]. |
7385 | 3141 |
^ self class |
7731
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3142 |
raise:#domainErrorSignal |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3143 |
receiver:self |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3144 |
selector:#tanh |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3145 |
arguments:#() |
abbf80b3913b
Enable C library functions for windows
Stefan Vogel <sv@exept.de>
parents:
7728
diff
changeset
|
3146 |
errorString:'bad receiver in tanh' |
7385 | 3147 |
! ! |
3148 |
||
5552 | 3149 |
!LongFloat methodsFor:'truncation & rounding'! |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3150 |
|
7382 | 3151 |
ceiling |
3152 |
"return the smallest integer which is greater or equal to the receiver." |
|
3153 |
||
3154 |
|val| |
|
3155 |
||
3156 |
%{ |
|
3157 |
#if defined(LONG_ceil) |
|
24267 | 3158 |
LONGFLOAT_t lVal; |
7382 | 3159 |
|
3160 |
lVal = LONG_ceil(__longFloatVal(self)); |
|
24267 | 3161 |
if ((lVal >= (LONGFLOAT_t)_MIN_INT) && (lVal <= (LONGFLOAT_t)_MAX_INT)) { |
14931 | 3162 |
RETURN ( __mkSmallInteger( (INT) lVal ) ); |
7382 | 3163 |
} |
3164 |
__qMKLFLOAT(val, lVal); |
|
3165 |
#endif |
|
3166 |
%}. |
|
3167 |
val notNil ifTrue:[ |
|
14931 | 3168 |
^ val asInteger |
7382 | 3169 |
]. |
3170 |
^ super ceiling. |
|
3171 |
||
3172 |
" |
|
14745 | 3173 |
0.5q ceiling |
3174 |
-0.5q ceiling |
|
7382 | 3175 |
" |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
3176 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
3177 |
|
7382 | 3178 |
ceilingAsFloat |
3179 |
"return the smallest integer-valued float greater or equal to the receiver. |
|
10333 | 3180 |
This is much like #ceiling, but avoids a (possibly expensive) conversion |
7382 | 3181 |
of the result to an integer. |
3182 |
It may be useful, if the result is to be further used in another float-operation." |
|
3183 |
||
3184 |
%{ /* NOCONTEXT */ |
|
3185 |
#if defined(LONG_ceil) |
|
24267 | 3186 |
LONGFLOAT_t lVal; |
7382 | 3187 |
OBJ v; |
3188 |
||
3189 |
lVal = LONG_ceil(__longFloatVal(self)); |
|
3190 |
__qMKLFLOAT(v, lVal); |
|
3191 |
RETURN (v); |
|
3192 |
#endif |
|
3193 |
%}. |
|
3194 |
^ super ceilingAsFloat |
|
3195 |
||
3196 |
" |
|
14745 | 3197 |
0.5q ceilingAsFloat |
3198 |
-0.5q ceilingAsFloat |
|
3199 |
-1.5q ceilingAsFloat |
|
7382 | 3200 |
" |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
3201 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
3202 |
|
7382 | 3203 |
floor |
3204 |
"return the integer nearest the receiver towards negative infinity." |
|
3205 |
||
3206 |
|val| |
|
3207 |
||
3208 |
%{ |
|
3209 |
#if defined(LONG_floor) |
|
24267 | 3210 |
LONGFLOAT_t lVal; |
7382 | 3211 |
|
3212 |
lVal = LONG_floor(__longFloatVal(self)); |
|
24267 | 3213 |
if ((lVal >= (LONGFLOAT_t)_MIN_INT) && (lVal <= (LONGFLOAT_t)_MAX_INT)) { |
14931 | 3214 |
RETURN ( __mkSmallInteger( (INT) lVal ) ); |
7382 | 3215 |
} |
3216 |
__qMKLFLOAT(val, lVal); |
|
3217 |
#endif |
|
3218 |
%}. |
|
3219 |
val notNil ifTrue:[ |
|
14931 | 3220 |
^ val asInteger |
7382 | 3221 |
]. |
3222 |
^ super floor. |
|
3223 |
||
3224 |
" |
|
14745 | 3225 |
0.5q floor |
3226 |
-0.5q floor |
|
7382 | 3227 |
" |
3228 |
! |
|
3229 |
||
3230 |
floorAsFloat |
|
3231 |
"return the float which represents the next lower |
|
3232 |
integer nearest the receiver towards negative infinity. |
|
3233 |
Much like floor, but returns a float result - useful if the result |
|
3234 |
will be used in another float operation, to avoid costy int-conversion." |
|
3235 |
||
3236 |
%{ /* NOCONTEXT */ |
|
3237 |
#if defined(LONG_floor) |
|
24267 | 3238 |
LONGFLOAT_t lVal; |
7382 | 3239 |
OBJ v; |
3240 |
||
3241 |
lVal = LONG_floor(__longFloatVal(self)); |
|
3242 |
__qMKLFLOAT(v, lVal); |
|
3243 |
RETURN (v); |
|
3244 |
#endif |
|
3245 |
%}. |
|
3246 |
^ super floorAsFloat |
|
3247 |
||
3248 |
" |
|
14745 | 3249 |
0.5q floorAsFloat |
3250 |
-0.5q floorAsFloat |
|
3251 |
-1.5q floorAsFloat |
|
7382 | 3252 |
" |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
3253 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
3254 |
|
14743 | 3255 |
fractionPart |
3256 |
"extract the after-decimal fraction part. |
|
3257 |
such that (self truncated + self fractionPart) = self" |
|
3258 |
||
3259 |
%{ /* NOCONTEXT */ |
|
3260 |
#if defined(LONG_modf) |
|
24267 | 3261 |
LONGFLOAT_t frac, trunc; |
14743 | 3262 |
OBJ v; |
3263 |
||
19322 | 3264 |
// mingw64 runtime modfl has a bug, triggering a SEGV |
3265 |
// see https://sourceforge.net/p/mingw-w64/bugs/478/ |
|
3266 |
# if defined(MINGW_MODFL_BUG) |
|
3267 |
{ |
|
24267 | 3268 |
LONGFLOAT_t value = __longFloatVal(self); |
3269 |
LONGFLOAT_t int_part = LONG_trunc(value); |
|
19329
52f5c0de20b4
LongFloat printing under mingw was broken (wrong printf called)
Claus Gittinger <cg@exept.de>
parents:
19324
diff
changeset
|
3270 |
frac = (isinf (value) ? 0.0L : value - int_part); |
19322 | 3271 |
} |
3272 |
# else |
|
14743 | 3273 |
frac = LONG_modf(__longFloatVal(self), &trunc); |
19329
52f5c0de20b4
LongFloat printing under mingw was broken (wrong printf called)
Claus Gittinger <cg@exept.de>
parents:
19324
diff
changeset
|
3274 |
# endif |
14743 | 3275 |
__qMKLFLOAT(v, frac); |
3276 |
RETURN (v); |
|
3277 |
#endif |
|
3278 |
%}. |
|
3279 |
^ super fractionPart |
|
3280 |
||
3281 |
" |
|
14745 | 3282 |
1.6q fractionPart + 1.6q truncated |
3283 |
-1.6q fractionPart + -1.6q truncated |
|
3284 |
||
3285 |
1.0q fractionPart |
|
3286 |
2.0q fractionPart |
|
14743 | 3287 |
3.0 asLongFloat fractionPart |
3288 |
4.0 asLongFloat fractionPart |
|
3289 |
0.5 asLongFloat fractionPart |
|
3290 |
0.25 asLongFloat fractionPart |
|
3291 |
3.14159 asLongFloat fractionPart |
|
3292 |
12345673.14159 asLongFloat fractionPart |
|
3293 |
123456731231231231.14159 asLongFloat fractionPart |
|
3294 |
||
3295 |
3.14159 asLongFloat fractionPart + 3.14159 asLongFloat truncated |
|
3296 |
||
3297 |
12345673.14159 asLongFloat fractionPart + 12345673.14159 asLongFloat truncated |
|
3298 |
||
3299 |
123456731231231231.14159 asLongFloat fractionPart + 123456731231231231.14159 asLongFloat truncated |
|
3300 |
" |
|
3301 |
! |
|
3302 |
||
25053 | 3303 |
integerAndFractionParts |
3304 |
"return the integer and the fraction part of the receiver as a pair |
|
25055 | 3305 |
of floats (i.e. the result of the modf function) |
3306 |
Adding the parts gives the original value" |
|
25053 | 3307 |
|
3308 |
|integerPart fractionPart| |
|
3309 |
||
3310 |
%{ |
|
3311 |
#ifdef __SCHTEAM__ |
|
3312 |
ERROR("unimplemented"); |
|
3313 |
#else |
|
3314 |
LONGFLOAT_t lVal, iPart, fPart; |
|
3315 |
OBJ i, f; |
|
3316 |
||
3317 |
lVal = __longFloatVal(self); |
|
3318 |
fPart = modfl(lVal, &iPart); |
|
3319 |
__qMKLFLOAT(i, iPart); |
|
3320 |
__qMKLFLOAT(f, fPart); |
|
3321 |
integerPart = i; |
|
3322 |
fractionPart = f; |
|
3323 |
#endif |
|
3324 |
%}. |
|
3325 |
integerPart isNil ifTrue:[^ super integerAndFractionParts]. |
|
3326 |
^ { integerPart . fractionPart } |
|
3327 |
||
3328 |
" |
|
3329 |
0.5 asLongFloat integerAndFractionParts |
|
3330 |
-0.5 asLongFloat integerAndFractionParts |
|
3331 |
12345.6789 asLongFloat integerAndFractionParts |
|
3332 |
-12345.6789 asLongFloat integerAndFractionParts |
|
3333 |
" |
|
3334 |
! |
|
3335 |
||
7382 | 3336 |
rounded |
3337 |
"return the receiver rounded to the nearest integer" |
|
3338 |
||
3339 |
%{ /* NOCONTEXT */ |
|
3340 |
#if defined(LONG_ceil) && defined(LONG_floor) |
|
24267 | 3341 |
LONGFLOAT_t lVal; |
7382 | 3342 |
OBJ v; |
3343 |
||
3344 |
lVal = __longFloatVal(self); |
|
3345 |
if (lVal < 0.0) { |
|
24267 | 3346 |
lVal = LONG_ceil(lVal - (LONGFLOAT_t)0.5); |
7382 | 3347 |
} else { |
24267 | 3348 |
lVal = LONG_floor(lVal + (LONGFLOAT_t)0.5); |
7382 | 3349 |
} |
3350 |
/* |
|
3351 |
* ST-80 (and X3J20) returns integer. |
|
3352 |
*/ |
|
24267 | 3353 |
if ((lVal >= (LONGFLOAT_t)_MIN_INT) && (lVal <= (LONGFLOAT_t)_MAX_INT)) { |
14931 | 3354 |
RETURN ( __mkSmallInteger( (INT) lVal ) ); |
7382 | 3355 |
} |
3356 |
__qMKLFLOAT(v, lVal); |
|
3357 |
RETURN (v); |
|
3358 |
#endif |
|
3359 |
%}. |
|
3360 |
^ super rounded |
|
3361 |
||
3362 |
" |
|
14745 | 3363 |
0.4q rounded |
3364 |
0.5q rounded |
|
3365 |
0.6qqrounded |
|
3366 |
-0.4q rounded |
|
3367 |
-0.5q rounded |
|
3368 |
-0.6q rounded |
|
7382 | 3369 |
" |
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
3370 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
3371 |
|
7382 | 3372 |
roundedAsFloat |
3373 |
"return the receiver rounded to the nearest integer as a float. |
|
10333 | 3374 |
This is much like #rounded, but avoids a (possibly expensive) conversion |
7382 | 3375 |
of the result to an integer. |
3376 |
It may be useful, if the result is to be further used in another float-operation." |
|
3377 |
||
3378 |
%{ /* NOCONTEXT */ |
|
3379 |
#if defined(LONG_ceil) && defined(LONG_floor) |
|
24267 | 3380 |
LONGFLOAT_t lVal; |
7382 | 3381 |
OBJ v; |
3382 |
||
3383 |
lVal = __longFloatVal(self); |
|
3384 |
if (lVal < 0.0) { |
|
24267 | 3385 |
lVal = LONG_ceil(lVal - (LONGFLOAT_t)0.5); |
7382 | 3386 |
} else { |
24267 | 3387 |
lVal = LONG_floor(lVal + (LONGFLOAT_t)0.5); |
7382 | 3388 |
} |
3389 |
__qMKLFLOAT(v, lVal); |
|
3390 |
RETURN (v); |
|
3391 |
#endif |
|
3392 |
%}. |
|
3393 |
^ super roundedAsFloat |
|
7357
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
3394 |
! |
cde54b45c469
full float functionality available (on linux)
Claus Gittinger <cg@exept.de>
parents:
7141
diff
changeset
|
3395 |
|
7382 | 3396 |
truncated |
3397 |
"return the receiver truncated towards zero as an integer" |
|
3398 |
||
3399 |
|val| |
|
3400 |
||
3401 |
%{ |
|
3402 |
#if defined(LONG_ceil) && defined(LONG_floor) |
|
24267 | 3403 |
LONGFLOAT_t lVal; |
7382 | 3404 |
|
3405 |
lVal = __longFloatVal(self); |
|
3406 |
if (lVal < 0.0) { |
|
14931 | 3407 |
lVal = LONG_ceil(lVal); |
7382 | 3408 |
} else { |
14931 | 3409 |
lVal = LONG_floor(lVal); |
7382 | 3410 |
} |
3411 |
||
3412 |
/* |
|
3413 |
* ST-80 (and X3J20) returns integer. |
|
3414 |
*/ |
|
24267 | 3415 |
if ((lVal >= (LONGFLOAT_t)_MIN_INT) && (lVal <= (LONGFLOAT_t)_MAX_INT)) { |
14931 | 3416 |
RETURN ( __mkSmallInteger( (INT) lVal ) ); |
7382 | 3417 |
} |
3418 |
__qMKLFLOAT(val, lVal); |
|
3419 |
#endif |
|
3420 |
%}. |
|
3421 |
val notNil ifTrue:[ |
|
14931 | 3422 |
^ val asInteger |
7382 | 3423 |
]. |
3424 |
^ super truncated |
|
3425 |
||
3426 |
" |
|
14745 | 3427 |
0.5q truncated |
3428 |
-0.5q truncated |
|
3429 |
0.5q truncatedAsFloat |
|
3430 |
-0.5q truncatedAsFloat |
|
7382 | 3431 |
" |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3432 |
! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3433 |
|
7382 | 3434 |
truncatedAsFloat |
3435 |
"return the receiver truncated towards zero as a float. |
|
10333 | 3436 |
This is much like #truncated, but avoids a (possibly expensive) conversion |
7382 | 3437 |
of the result to an integer. |
10333 | 3438 |
It may be useful, if the result is to be further used in another |
7382 | 3439 |
float-operation." |
3440 |
||
3441 |
%{ /* NOCONTEXT */ |
|
3442 |
#if defined(LONG_ceil) && defined(LONG_floor) |
|
24267 | 3443 |
LONGFLOAT_t lVal; |
7382 | 3444 |
OBJ v; |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3445 |
|
7382 | 3446 |
lVal = __longFloatVal(self); |
3447 |
if (lVal < 0.0) { |
|
14931 | 3448 |
lVal = LONG_ceil(lVal); |
7382 | 3449 |
} else { |
14931 | 3450 |
lVal = LONG_floor(lVal); |
7382 | 3451 |
} |
3452 |
__qMKLFLOAT(v, lVal); |
|
3453 |
RETURN (v); |
|
3454 |
#endif |
|
3455 |
%}. |
|
3456 |
^ super truncatedAsFloat |
|
3457 |
||
3458 |
" |
|
14745 | 3459 |
0.5q truncated |
3460 |
-0.5q truncated |
|
3461 |
0.5q truncatedAsFloat |
|
3462 |
-0.5q truncatedAsFloat |
|
7382 | 3463 |
" |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3464 |
! ! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3465 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3466 |
!LongFloat class methodsFor:'documentation'! |
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3467 |
|
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3468 |
version |
18833 | 3469 |
^ '$Header$' |
12476
66b5104cedc9
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11925
diff
changeset
|
3470 |
! |
66b5104cedc9
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11925
diff
changeset
|
3471 |
|
66b5104cedc9
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11925
diff
changeset
|
3472 |
version_CVS |
18833 | 3473 |
^ '$Header$' |
4165
6d83608a7584
initial - not yet tested/released
Claus Gittinger <cg@exept.de>
parents:
diff
changeset
|
3474 |
! ! |
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3475 |
|
14600 | 3476 |
|
7389
4fd487ca919a
longFloat precision constants;
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3477 |
LongFloat initialize! |