author | Claus Gittinger <cg@exept.de> |
Wed, 20 Nov 2019 16:32:58 +0100 | |
changeset 24930 | b9f4cb048fe7 |
parent 24915 | 9b05c18790b2 |
child 24954 | 04f672a40ad9 |
permissions | -rw-r--r-- |
24930 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1988 by Claus Gittinger |
175 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5411 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17384 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
54 | 18 |
LimitedPrecisionReal variableByteSubclass:#Float |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
19 |
instanceVariableNames:'' |
21870 | 20 |
classVariableNames:'DefaultPrintFormat DefaultPrintfFormat E Epsilon Halfpi |
21904 | 21 |
HalfpiNegative Ln10 Ln2 MaxSmallInteger NaN NegativeInfinity Pi |
22 |
PositiveInfinity RadiansPerDegree Sqrt2 Twopi' |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
23 |
poolDictionaries:'' |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
24 |
category:'Magnitude-Numbers' |
1 | 25 |
! |
26 |
||
701 | 27 |
!Float primitiveDefinitions! |
28 |
%{ |
|
14751 | 29 |
#include <stdio.h> |
701 | 30 |
#include <errno.h> |
31 |
||
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
32 |
#ifndef __OPTIMIZE__ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
33 |
# define __OPTIMIZE__ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
34 |
#endif |
4825 | 35 |
|
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 |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
38 |
#include <math.h> |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
39 |
|
16669 | 40 |
#ifndef INT64 |
41 |
# ifdef HAS_LONGLONG |
|
42 |
# define INT64 long long int |
|
43 |
# else |
|
44 |
# define INT64 __int64 |
|
45 |
# endif |
|
46 |
#endif |
|
47 |
||
48 |
||
701 | 49 |
/* |
50 |
* on some systems errno is a macro ... check for it here |
|
51 |
*/ |
|
52 |
#ifndef errno |
|
53 |
extern errno; |
|
54 |
#endif |
|
55 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
56 |
#if !defined (__win32__) |
14672
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
57 |
# include <locale.h> |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
58 |
#endif |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
59 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
60 |
#if defined (__aix__) |
2394 | 61 |
# include <float.h> |
62 |
#endif |
|
4825 | 63 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
64 |
#if defined(__irix__) |
2395 | 65 |
# include <nan.h> |
66 |
#endif |
|
4825 | 67 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
68 |
#if defined(__linux__) |
4825 | 69 |
# ifndef NAN |
5822
4e56f8aadda5
Get nan.h from bits/nan.h for Linux
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
70 |
# include <bits/nan.h> |
4825 | 71 |
# endif |
2396 | 72 |
#endif |
4825 | 73 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
74 |
#if defined(__solaris__) || defined(__sunos__) |
2398 | 75 |
# include <nan.h> |
76 |
#endif |
|
2394 | 77 |
|
3129 | 78 |
/* |
79 |
* sigh - some systems define that stuff; others dont. |
|
80 |
* (AIX even declares them as macros, so an external decl |
|
81 |
* will not work below ... |
|
82 |
*/ |
|
22578 | 83 |
#if !defined(__aix__) && !defined(__NEXT3__) |
3129 | 84 |
|
85 |
# ifdef acos |
|
86 |
double acos(); |
|
87 |
# endif |
|
88 |
# ifdef asin |
|
89 |
double asin(); |
|
90 |
# endif |
|
91 |
# ifndef atan |
|
92 |
double atan(); |
|
93 |
# endif |
|
94 |
# ifndef cos |
|
95 |
double cos(); |
|
96 |
# endif |
|
97 |
# ifndef sin |
|
98 |
double sin(); |
|
99 |
# endif |
|
100 |
# ifndef pow |
|
101 |
double pow(); |
|
102 |
# endif |
|
103 |
# ifndef log |
|
104 |
double log(); |
|
105 |
# endif |
|
106 |
# ifndef exp |
|
107 |
double exp(); |
|
108 |
# endif |
|
109 |
# ifndef sqrt |
|
110 |
double sqrt(); |
|
111 |
# endif |
|
17199 | 112 |
# ifndef cbrt |
17200
3f919ff62213
cbrt is not avail in win32's math library
Claus Gittinger <cg@exept.de>
parents:
17199
diff
changeset
|
113 |
# ifndef WIN32 |
17199 | 114 |
double cbrt(); |
17200
3f919ff62213
cbrt is not avail in win32's math library
Claus Gittinger <cg@exept.de>
parents:
17199
diff
changeset
|
115 |
# endif |
17199 | 116 |
# endif |
3129 | 117 |
# ifndef tan |
118 |
double tan(); |
|
119 |
# endif |
|
120 |
||
121 |
#endif /* not AIX */ |
|
122 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
123 |
#ifdef __win32__ |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
124 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
125 |
* no finite(x) ? |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
126 |
* no isnan(x) ? |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
127 |
*/ |
7420 | 128 |
# ifndef isnan |
129 |
# define isnan(x) \ |
|
17199 | 130 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
131 |
(((unsigned int *)(&x))[1] == 0xFFF80000)) |
|
7420 | 132 |
# endif |
133 |
||
134 |
# ifndef isPositiveInfinity |
|
135 |
# define isPositiveInfinity(x) \ |
|
17199 | 136 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
137 |
(((unsigned int *)(&x))[1] == 0x7FF00000)) |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
138 |
# endif |
7420 | 139 |
|
140 |
# ifndef isNegativeInfinity |
|
14931 | 141 |
# define isNegativeInfinity(x) \ |
17199 | 142 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
143 |
(((unsigned int *)(&x))[1] == 0xFFF00000)) |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
144 |
# endif |
7420 | 145 |
|
146 |
# ifndef isinf |
|
147 |
# define isinf(x) \ |
|
17199 | 148 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
149 |
((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000)) |
|
7420 | 150 |
# endif |
151 |
||
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
152 |
# ifndef isfinite |
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
153 |
# define isfinite(x) (!isinf(x) && !isnan(x)) |
7420 | 154 |
# endif |
155 |
||
7411 | 156 |
# define NO_ASINH |
157 |
# define NO_ACOSH |
|
158 |
# define NO_ATANH |
|
14931 | 159 |
|
160 |
# ifdef __MINGW__ |
|
22491 | 161 |
# ifndef _STRING_H_INCLUDED_ |
162 |
# include <string.h> |
|
163 |
# define _STRING_H_INCLUDED_ |
|
164 |
# endif |
|
14931 | 165 |
# endif |
166 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
167 |
#endif /* __win32__ */ |
8984 | 168 |
|
169 |
#ifdef solaris |
|
170 |
# ifndef isfinite |
|
171 |
# define isfinite(f) finite((double)(f)) |
|
172 |
# endif |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
173 |
#endif |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
174 |
|
3414 | 175 |
#ifdef realIX |
11945 | 176 |
# ifndef isfinite |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
177 |
# define isfinite(x) 1 |
3414 | 178 |
# endif |
179 |
#endif |
|
180 |
||
22578 | 181 |
#ifndef __NEXT3__ |
3241 | 182 |
# ifndef ceil |
183 |
double ceil(); |
|
184 |
double floor(); |
|
185 |
# endif |
|
186 |
#endif |
|
187 |
||
701 | 188 |
%} |
189 |
! ! |
|
190 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
191 |
!Float class methodsFor:'documentation'! |
68 | 192 |
|
88 | 193 |
copyright |
194 |
" |
|
195 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
175 | 196 |
All Rights Reserved |
88 | 197 |
|
198 |
This software is furnished under a license and may be used |
|
199 |
only in accordance with the terms of that license and with the |
|
200 |
inclusion of the above copyright notice. This software may not |
|
201 |
be provided or otherwise made available to, or used by, any |
|
202 |
other person. No title to or ownership of the software is |
|
203 |
hereby transferred. |
|
204 |
" |
|
205 |
! |
|
206 |
||
68 | 207 |
documentation |
208 |
" |
|
15016 | 209 |
Floats represent rational numbers with limited precision. |
24461 | 210 |
They use the C-compiler's 'double' format, |
211 |
which is usually the 8byte IEEE double float format. |
|
7380 | 212 |
|
213 |
Floats give you 64 bit floats. |
|
15016 | 214 |
In contrast to ShortFloats (32bit) and LongFloats (>=64bit). |
7380 | 215 |
|
216 |
WARNING: |
|
24441 | 217 |
The layout of Float instances is known by the runtime system and the compiler; |
218 |
you may not add instance variables here. |
|
219 |
Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats, |
|
220 |
and does some float-checks by an identity compare with the Float-class. |
|
221 |
(i.e. your subclasses instances may not be recognized as float-like objects, |
|
222 |
thus mixed mode arithmetic will always coerce them, effectively slowing things down). |
|
1 | 223 |
|
68 | 224 |
Notice, that Floats are defined as Byte-array to prevent the garbage collector |
225 |
from going into the value ... otherwise I needed a special case in many places. |
|
226 |
||
16632 | 227 |
Also notice, that ST/X Floats are what Doubles are in ST-80. The reason for doing this |
228 |
was to be compatible to both Digitalk, Squeak AND ParcPlace smalltalk implementations |
|
6674 | 229 |
(ParcPlace uses a 4-byte Float and an 8-byte Double class, in contrast to |
15016 | 230 |
Digitalk and Squeak, which have an 8-byte Float class). |
11945 | 231 |
Thus, by providing an 8-byte Float class, code would not loose precicion |
7380 | 232 |
(although some memory is wasted when porting from VW). |
6674 | 233 |
Notice that ST/X provides an alias called Double, and an extra ShortFloat class, which has 4-byte |
234 |
instances. |
|
68 | 235 |
|
1892 | 236 |
Mixed mode arithmetic: |
24441 | 237 |
float op float -> float |
238 |
float op fix -> float |
|
239 |
float op fraction -> float |
|
240 |
float op integer -> float |
|
241 |
float op shortFloat -> float |
|
242 |
float op longFloat -> longFloat |
|
243 |
float op complex -> complex |
|
1892 | 244 |
|
7405 | 245 |
Representation: |
24441 | 246 |
64bit double precision IEEE floats |
247 |
52 bit mantissa + 1 hidden bit providing 53 bits of precision, |
|
248 |
11 bit exponent, |
|
24461 | 249 |
15 decimal digits (approx.) |
7405 | 250 |
|
251 |
Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation |
|
85 | 252 |
|
7380 | 253 |
[author:] |
24441 | 254 |
Claus Gittinger |
7380 | 255 |
|
1295 | 256 |
[see also:] |
24441 | 257 |
Number |
258 |
ShortFloat LongFloat Fraction FixedPoint Integer Complex |
|
259 |
FloatArray DoubleArray |
|
68 | 260 |
" |
2215 | 261 |
! |
262 |
||
263 |
errorHandling |
|
264 |
" |
|
265 |
Floating point error handling and signalling depends on the systems |
|
266 |
(actually: the C-runtime systems) ability to handle floating point errors. |
|
267 |
Most systems report errors by raising an OS floatingPoint exception, |
|
268 |
which is mapped to a fpExceptionInterrupt in ST/X. |
|
269 |
However, some systems do return NaN as result. |
|
270 |
||
11945 | 271 |
Currently, ST/X does not care specially for these systems - it maybe added |
2215 | 272 |
easily, if there is sufficient customer interest, though. |
273 |
||
274 |
Try: |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
275 |
|f1 f2| |
2215 | 276 |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
277 |
f1 := 1.0. |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
278 |
f2 := 0.0. |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
279 |
f1 / f2 |
2215 | 280 |
|
281 |
or: |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
282 |
2 arcSin |
2215 | 283 |
" |
68 | 284 |
! ! |
1 | 285 |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
286 |
!Float class methodsFor:'instance creation'! |
1 | 287 |
|
288 |
basicNew |
|
289 |
"return a new float - here we return 0.0 |
|
290 |
- floats are usually NOT created this way ... |
|
291 |
Its implemented here to allow things like binary store & load |
|
292 |
of floats. (but even this support will go away eventually, its not |
|
293 |
a good idea to store the bits of a float - the reader might have a |
|
11945 | 294 |
totally different representation - so floats will eventually be |
13 | 295 |
binary stored in a device independent format." |
1 | 296 |
|
297 |
%{ /* NOCONTEXT */ |
|
18296 | 298 |
#ifdef __SCHTEAM__ |
299 |
ERROR("trying to instantiate a float"); |
|
300 |
#else |
|
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
301 |
OBJ newFloat; |
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
302 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
303 |
__qMKFLOAT(newFloat, 0.0); |
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
304 |
RETURN (newFloat); |
18296 | 305 |
#endif /* not SCHTEAM */ |
1 | 306 |
%} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
307 |
! |
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
308 |
|
4295 | 309 |
fastFromString:aString at:startIndex |
11945 | 310 |
"return the next Float from the string starting at startIndex. |
4295 | 311 |
No spaces are skipped. |
23477 | 312 |
Raises an exception, if the startIndex is not valid. |
23943 | 313 |
Returns garbage if the argument string is not a valid double float number. |
23477 | 314 |
|
315 |
This is a specially tuned entry (using a low-level C-call to atof). |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
316 |
It has been added to allow high speed string decomposition |
23477 | 317 |
into numbers, especially for mass-data (reading millions of floats)." |
11945 | 318 |
|
319 |
%{ /* NOCONTEXT */ |
|
23477 | 320 |
int idx = __intVal(startIndex) - 1; |
321 |
||
12478
e8051030cda6
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12423
diff
changeset
|
322 |
if (__isStringLike(aString) && __isSmallInteger(startIndex)) { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
323 |
char *cp = (char *)(__stringVal(aString)); |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
324 |
double atof(); |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
325 |
double val; |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
326 |
OBJ newFloat; |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
327 |
|
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
328 |
if ((unsigned)idx < __stringSize(aString)) { |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
329 |
val = atof(cp + idx); |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
330 |
__qMKFLOAT(newFloat, val); |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
331 |
RETURN (newFloat); |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
332 |
} |
4295 | 333 |
} |
334 |
%}. |
|
335 |
self primitiveFailed. |
|
336 |
||
337 |
" |
|
11945 | 338 |
Float fastFromString:'123.45' at:1 |
339 |
Float fastFromString:'123.45' at:2 |
|
21870 | 340 |
Float fastFromString:'123.45' at:3 |
341 |
Float fastFromString:'123.45' at:4 |
|
342 |
Float fastFromString:'123.45' at:5 |
|
343 |
Float fastFromString:'123.45' at:6 |
|
344 |
||
11945 | 345 |
Float fastFromString:'123.45E4' at:1 |
346 |
Float fastFromString:'hello123.45E4' at:6 |
|
347 |
Float fastFromString:'12345' at:1 |
|
348 |
Float fastFromString:'12345' at:2 |
|
349 |
Float fastFromString:'12345' at:3 |
|
350 |
Float fastFromString:'12345' at:4 |
|
351 |
Float fastFromString:'12345' at:5 |
|
21870 | 352 |
|
353 |
Float fastFromString:'12345' at:6 -> error |
|
354 |
Float fastFromString:'12345' at:0 -> error |
|
355 |
||
356 |
Float fastFromString:'hello123.45E4' at:1 -> 0 |
|
4295 | 357 |
|
23477 | 358 |
Float fastFromString:'1.7976931348623157e+308' |
359 |
Float fastFromString:'Nan' |
|
360 |
Float fastFromString:'+Inf' |
|
361 |
Float fastFromString:'-Inf' |
|
362 |
" |
|
363 |
||
364 |
" |
|
4295 | 365 |
Time millisecondsToRun:[ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
366 |
1000000 timesRepeat:[ |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
367 |
Float readFrom:'123.45' |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
368 |
] |
4295 | 369 |
] |
370 |
" |
|
371 |
||
372 |
" |
|
373 |
Time millisecondsToRun:[ |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
374 |
1000000 timesRepeat:[ |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
375 |
Float fastFromString:'123.45' at:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
376 |
] |
4295 | 377 |
] |
378 |
" |
|
21870 | 379 |
|
380 |
"Modified (comment): / 21-06-2017 / 09:24:32 / cg" |
|
23943 | 381 |
"Modified (comment): / 20-03-2019 / 13:45:12 / Claus Gittinger" |
4295 | 382 |
! |
383 |
||
15016 | 384 |
fromIEEE32Bit: anInteger |
385 |
"creates a double, given the four native float bytes as an integer" |
|
386 |
||
387 |
%{ /* NOCONTEXT */ |
|
21870 | 388 |
#ifndef __SCHTEAM__ |
15016 | 389 |
REGISTER union { |
22578 | 390 |
unsigned int i; |
391 |
float f; |
|
15016 | 392 |
} r; |
393 |
||
394 |
r.i = __unsignedLongIntVal( anInteger ); |
|
15017 | 395 |
RETURN( __MKFLOAT((double)(r.f)) ); |
18296 | 396 |
#endif |
21870 | 397 |
%}. |
398 |
self primitiveFailed. |
|
17218 | 399 |
|
400 |
" |
|
21870 | 401 |
ShortFloat fromIEEE32Bit:((ShortFloat pi digitBytesMSB:true) asIntegerMSB:true) |
17218 | 402 |
" |
21870 | 403 |
|
404 |
"Modified (comment): / 21-06-2017 / 09:26:41 / cg" |
|
17218 | 405 |
! |
406 |
||
407 |
fromIEEE64Bit: anInteger |
|
21875 | 408 |
"creates a double, given the eight native double bytes as an integer" |
17218 | 409 |
|
410 |
%{ /* NOCONTEXT */ |
|
21870 | 411 |
#ifndef __SCHTEAM__ |
21876 | 412 |
extern int __unsignedLong64IntVal(OBJ o, __uint64__ *pI); |
17218 | 413 |
|
414 |
REGISTER union { |
|
22578 | 415 |
__uint64__ u64; |
416 |
double d; |
|
17218 | 417 |
} r; |
418 |
||
419 |
if (__unsignedLong64IntVal(anInteger, &r.u64)) { |
|
22578 | 420 |
RETURN( __MKFLOAT(r.d) ); |
17218 | 421 |
} |
18296 | 422 |
#endif |
17218 | 423 |
%}. |
424 |
self primitiveFailed. |
|
425 |
||
426 |
" |
|
22578 | 427 |
Float fromIEEE64Bit:((Float pi digitBytesMSB:true) asIntegerMSB:true) |
17218 | 428 |
" |
21870 | 429 |
|
21876 | 430 |
"Modified: / 21-06-2017 / 09:37:47 / cg" |
15016 | 431 |
! |
432 |
||
19358 | 433 |
fromInteger:anInteger |
434 |
"return a new float, given an integer value" |
|
435 |
||
436 |
%{ /* NOCONTEXT */ |
|
437 |
#ifdef __SCHTEAM__ |
|
438 |
if (anInteger.isSmallInteger()) { |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
439 |
return __c__._RETURN( STDouble._new( (double)(anInteger.longValue()) )); |
19358 | 440 |
} |
441 |
#else |
|
442 |
OBJ newFloat; |
|
443 |
||
444 |
if (__isSmallInteger(anInteger)) { |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
445 |
double f = (double)__smallIntegerVal(anInteger); |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
446 |
__qMKFLOAT(newFloat, f); /* OBJECT ALLOCATION */ |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
447 |
RETURN (newFloat); |
19358 | 448 |
} |
449 |
#endif /* not SCHTEAM */ |
|
450 |
%}. |
|
451 |
^ super fromInteger:anInteger |
|
452 |
||
453 |
" |
|
454 |
Float fromInteger:123 |
|
455 |
Float fromInteger:(100 factorial) |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
456 |
(100 factorial) asFloat |
19358 | 457 |
" |
458 |
! |
|
459 |
||
17653 | 460 |
fromNumber:aNumber |
21870 | 461 |
"return aNumber coerced to Float" |
22578 | 462 |
|
21870 | 463 |
^ aNumber asFloat |
464 |
||
465 |
"Modified (comment): / 21-06-2017 / 08:55:15 / cg" |
|
17653 | 466 |
! |
467 |
||
3279 | 468 |
fromVAXFloatBytes:b1 b2:b2 b3:b3 b4:b4 |
21870 | 469 |
"creates a double, given the four vax F-format float bytes to an ieee double. |
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
470 |
For NaNs and Infinity, nil is returned. |
21870 | 471 |
To get an idea of how big the floating-point zoo really is, |
472 |
see: http://www.quadibloc.com/comp/cp0201.htm |
|
3279 | 473 |
" |
474 |
||
475 |
%{ /* NOCONTEXT */ |
|
21870 | 476 |
#ifndef __SCHTEAM__ |
3279 | 477 |
REGISTER union { |
22578 | 478 |
unsigned char b[4]; |
479 |
unsigned int l; |
|
480 |
float f; |
|
3279 | 481 |
} r; |
482 |
||
18296 | 483 |
# ifdef __LSBFIRST__ |
3279 | 484 |
r.b[3] = __intVal( b2 ); |
485 |
r.b[2] = __intVal( b1 ); |
|
486 |
r.b[1] = __intVal( b4 ); |
|
487 |
r.b[0] = __intVal( b3 ); |
|
18296 | 488 |
# else |
3279 | 489 |
r.b[0] = __intVal( b2 ); |
490 |
r.b[1] = __intVal( b1 ); |
|
491 |
r.b[2] = __intVal( b4 ); |
|
492 |
r.b[3] = __intVal( b3 ); |
|
18296 | 493 |
# endif |
21870 | 494 |
if( (r.l & 0xff800000) != 0x80000000 ) { |
22578 | 495 |
if( (r.l & 0x7f800000) > 0x01000000 ) |
496 |
r.l -= 0x01000000; |
|
497 |
else |
|
498 |
r.l = 0; |
|
499 |
||
500 |
RETURN( __MKFLOAT(r.f) ); |
|
21870 | 501 |
} else { |
22578 | 502 |
// add code to handle NaN and Inf |
503 |
RETURN( nil ); |
|
3279 | 504 |
} |
18296 | 505 |
#endif |
3279 | 506 |
%}. |
21870 | 507 |
^ self primitiveFailed |
508 |
||
509 |
"Modified: / 21-06-2017 / 09:21:55 / cg" |
|
1 | 510 |
! ! |
511 |
||
12916
a32796fca6ed
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12723
diff
changeset
|
512 |
!Float class methodsFor:'accessing'! |
a32796fca6ed
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12723
diff
changeset
|
513 |
|
a32796fca6ed
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12723
diff
changeset
|
514 |
defaultPrintFormat |
a32796fca6ed
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12723
diff
changeset
|
515 |
^ DefaultPrintFormat |
a32796fca6ed
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12723
diff
changeset
|
516 |
! |
a32796fca6ed
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12723
diff
changeset
|
517 |
|
a32796fca6ed
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12723
diff
changeset
|
518 |
defaultPrintFormat:something |
a32796fca6ed
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12723
diff
changeset
|
519 |
DefaultPrintFormat := something. |
16658 | 520 |
! |
521 |
||
21868 | 522 |
defaultPrintfFormat |
523 |
^ DefaultPrintfFormat |
|
524 |
! |
|
525 |
||
526 |
defaultPrintfFormat:something |
|
527 |
DefaultPrintfFormat := something. |
|
12916
a32796fca6ed
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12723
diff
changeset
|
528 |
! ! |
a32796fca6ed
#printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents:
12723
diff
changeset
|
529 |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
530 |
!Float class methodsFor:'binary storage'! |
701 | 531 |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
532 |
readBinaryIEEEDoubleFrom:aStream |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
533 |
"read a float from the binary stream, aStream, |
14925 | 534 |
interpreting the next bytes as an IEEE formatted 8-byte float. |
535 |
The bytes are read in the native byte order (i.e.lsb on intel)" |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
536 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
537 |
|f| |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
538 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
539 |
f := self basicNew. |
15013 | 540 |
self readBinaryIEEEDoubleFrom:aStream into:f MSB:(UninterpretedBytes isBigEndian). |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
541 |
^ f |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
542 |
|
9637 | 543 |
"not part of libboss, as this is also used by others (TIFFReader)" |
544 |
||
545 |
"Created: / 16-04-1996 / 20:59:59 / cg" |
|
546 |
"Modified: / 23-08-2006 / 16:00:42 / cg" |
|
701 | 547 |
! |
548 |
||
15013 | 549 |
readBinaryIEEEDoubleFrom:aStream MSB:msbFirst |
550 |
"read a float from the binary stream, aStream, |
|
551 |
interpreting the next bytes as an IEEE formatted 8-byte float. |
|
552 |
The bytes are read in the specified byte order" |
|
553 |
||
554 |
|f| |
|
555 |
||
556 |
f := self basicNew. |
|
557 |
self readBinaryIEEEDoubleFrom:aStream into:f MSB:msbFirst. |
|
558 |
^ f |
|
559 |
||
560 |
"not part of libboss, as this is also used by others (TIFFReader)" |
|
561 |
! |
|
562 |
||
19616 | 563 |
readBinaryIEEEDoubleFrom:aStream into:aBasicNewFloat |
14923 | 564 |
"read the receiver's value from the binary stream, aStream, |
565 |
interpreting the next bytes as an IEEE formatted 8-byte float. |
|
14925 | 566 |
The bytes are read in the native byte order (i.e.lsb on intel)" |
14923 | 567 |
|
19616 | 568 |
^ self readBinaryIEEEDoubleFrom:aStream into:aBasicNewFloat MSB:(UninterpretedBytes isBigEndian) |
14923 | 569 |
! |
570 |
||
571 |
readBinaryIEEEDoubleFrom:aStream into:aFloat MSB:msb |
|
572 |
"read the receiver's value from the binary stream, aStream, |
|
573 |
interpreting the next bytes as an IEEE formatted 8-byte float. |
|
574 |
If msb is true, the stream bytes are most-significant-first." |
|
701 | 575 |
|
576 |
" |
|
577 |
this implementation is wrong: does not work on non-IEEE machines |
|
578 |
(to date all machines where ST/X is running on use |
|
14923 | 579 |
IEEE float format. Will need more here, when porting ST/X to 370's) |
701 | 580 |
" |
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
581 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
582 |
|
14923 | 583 |
(UninterpretedBytes isBigEndian == msb) ifFalse:[ |
14931 | 584 |
"swap the bytes" |
585 |
8 to:1 by:-1 do:[:i | |
|
586 |
aFloat basicAt:i put:(aStream next) |
|
587 |
]. |
|
588 |
^ self |
|
701 | 589 |
]. |
590 |
1 to:8 do:[:i | |
|
14931 | 591 |
aFloat basicAt:i put:aStream next |
701 | 592 |
] |
9637 | 593 |
|
594 |
"not part of libboss, as this is also used by others (TIFFReader)" |
|
595 |
||
596 |
"Modified: / 23-08-2006 / 16:00:37 / cg" |
|
701 | 597 |
! |
598 |
||
599 |
storeBinaryIEEEDouble:aFloat on:aStream |
|
600 |
"store aFloat as an IEEE formatted 8-byte float |
|
14925 | 601 |
onto the binary stream, aStream. |
602 |
The bytes are written in the native byte order (i.e.lsb on intel)" |
|
603 |
||
604 |
self storeBinaryIEEEDouble:aFloat on:aStream MSB:(UninterpretedBytes isBigEndian) |
|
605 |
! |
|
606 |
||
607 |
storeBinaryIEEEDouble:aFloat on:aStream MSB:msb |
|
608 |
"store aFloat as an IEEE formatted 8-byte float |
|
609 |
onto the binary stream, aStream. |
|
610 |
If msb is true, the stream bytes are written most-significant-first." |
|
701 | 611 |
|
612 |
" |
|
613 |
this implementation is wrong: does not work on non-IEEE machines |
|
614 |
(to date all machines where ST/X is running on use |
|
615 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
616 |
" |
|
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
617 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
618 |
|
14925 | 619 |
(UninterpretedBytes isBigEndian == msb) ifFalse:[ |
14931 | 620 |
"swap the bytes" |
621 |
8 to:1 by:-1 do:[:i | |
|
622 |
aStream nextPut:(aFloat basicAt:i). |
|
623 |
]. |
|
624 |
^ self |
|
701 | 625 |
]. |
626 |
1 to:8 do:[:i | |
|
14931 | 627 |
aStream nextPut:(aFloat basicAt:i). |
701 | 628 |
]. |
9637 | 629 |
|
630 |
"not part of libboss, as this is also used by others (TIFFReader)" |
|
631 |
||
632 |
"Modified: / 23-08-2006 / 16:00:47 / cg" |
|
701 | 633 |
! ! |
634 |
||
7441 | 635 |
!Float class methodsFor:'class initialization'! |
636 |
||
637 |
initialize |
|
14105 | 638 |
Pi isNil ifTrue:[ |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
639 |
DefaultPrintFormat := '.15'. "/ print 15 valid digits |
21868 | 640 |
DefaultPrintfFormat := '%15f'. |
641 |
||
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
642 |
Pi := 3.14159265358979323846264338327950288419716939937510582097494459. |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
643 |
Halfpi := Pi / 2.0. |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
644 |
HalfpiNegative := Halfpi negated. |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
645 |
Twopi := Pi * 2.0. |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
646 |
E := 2.7182818284590452353602874713526625. |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
647 |
Sqrt2 := 1.41421356237309504880168872420969808. |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
648 |
RadiansPerDegree := Pi / 180.0. |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
649 |
Ln2 := 0.69314718055994530941723212145817657. |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
650 |
Ln10 := 10.0 ln. |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
651 |
MaxSmallInteger := super maxSmallInteger. |
14105 | 652 |
]. |
10604 | 653 |
|
654 |
" |
|
14105 | 655 |
Pi := nil. |
10604 | 656 |
self initialize |
657 |
" |
|
7441 | 658 |
|
659 |
" |
|
11945 | 660 |
DefaultPrintFormat := '.9'. |
661 |
Float pi printString. |
|
662 |
||
663 |
DefaultPrintFormat := '.6'. |
|
664 |
Float pi printString. |
|
7441 | 665 |
" |
10604 | 666 |
|
667 |
"Modified: / 07-06-2007 / 21:17:53 / cg" |
|
7441 | 668 |
! ! |
669 |
||
21870 | 670 |
!Float class methodsFor:'coercing & converting'! |
671 |
||
672 |
coerce:aNumber |
|
673 |
"convert the argument aNumber into an instance of the receiver (class) and return it." |
|
674 |
||
675 |
^ aNumber asFloat. |
|
676 |
! ! |
|
677 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
678 |
!Float class methodsFor:'constants'! |
1 | 679 |
|
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
680 |
NaN |
21859 | 681 |
"return the constant NaN (not a Number)" |
682 |
||
683 |
NaN isNil ifTrue:[ |
|
684 |
%{ |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8635
diff
changeset
|
685 |
#if defined(LINUX) && defined(__i386__) |
3955 | 686 |
# ifdef NAN |
21868 | 687 |
@global(Float:NaN) = __MKFLOAT(NAN); |
3955 | 688 |
# else |
21868 | 689 |
@global(Float:NaN) = __MKFLOAT(_SNAN); |
3955 | 690 |
# endif |
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
691 |
#endif |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
692 |
%}. |
21868 | 693 |
NaN isNil ifTrue:[ |
694 |
NaN := super NaN. |
|
695 |
]. |
|
696 |
]. |
|
21859 | 697 |
^ NaN |
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
698 |
|
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
699 |
" |
21868 | 700 |
Float NaN |
11945 | 701 |
Float NaN + 0.0 |
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
702 |
Float NaN + Float NaN |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
703 |
0.0 + Float NaN |
21859 | 704 |
|
705 |
it's a singleton: |
|
21868 | 706 |
|
21859 | 707 |
Float NaN == Float NaN |
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
708 |
" |
21859 | 709 |
|
710 |
"Modified (format): / 20-06-2017 / 13:52:31 / cg" |
|
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
711 |
! |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
712 |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
713 |
e |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
714 |
"return the constant e as Float" |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
715 |
|
20799 | 716 |
"/ don't expect this many valid digits on all machines; |
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
717 |
"/ The actual precision is very CPU specific. |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
718 |
|
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
719 |
^ 2.7182818284590452353602874713526625 |
6341 | 720 |
! |
721 |
||
18129 | 722 |
emax |
723 |
"Answer the maximum exponent for this representation." |
|
724 |
||
725 |
^1023 |
|
17661 | 726 |
! |
727 |
||
18133 | 728 |
emin |
729 |
"Answer the minimum exponent for this representation." |
|
730 |
||
731 |
^ -1022 |
|
732 |
! |
|
733 |
||
22725 | 734 |
halfpi |
735 |
"return the constant pi/2 as Float" |
|
736 |
||
737 |
"/ don't expect this many valid digits on all machines; |
|
738 |
"/ The actual precision is very CPU specific. |
|
739 |
||
740 |
^ 1.570796326794896619231321691639751442098584699687552910 |
|
741 |
! |
|
742 |
||
743 |
halfpiNegative |
|
744 |
"return the constant -pi/2 as Float" |
|
745 |
||
746 |
"/ don't expect this many valid digits on all machines; |
|
747 |
"/ The actual precision is very CPU specific. |
|
748 |
||
749 |
^ -1.570796326794896619231321691639751442098584699687552910 |
|
750 |
! |
|
751 |
||
21859 | 752 |
infinity |
24302 | 753 |
"return a float which represents positive infinity (for my instances). |
754 |
Warning: do not compare equal against infinities; |
|
755 |
instead, check using isFinite or isInfinite" |
|
21859 | 756 |
|
757 |
PositiveInfinity isNil ifTrue:[ |
|
24295 | 758 |
PositiveInfinity := super infinity |
21859 | 759 |
]. |
760 |
^ PositiveInfinity |
|
761 |
||
762 |
" |
|
21868 | 763 |
Float infinity == Float infinity |
21859 | 764 |
" |
765 |
||
766 |
"Created: / 20-06-2017 / 13:56:07 / cg" |
|
24302 | 767 |
"Modified (comment): / 09-06-2019 / 12:54:54 / Claus Gittinger" |
21859 | 768 |
! |
769 |
||
18492 | 770 |
ln10 |
771 |
"return the natural logarithm of 10; |
|
772 |
will return something like 2.30258509299405" |
|
773 |
||
774 |
^ Ln10 |
|
775 |
! |
|
776 |
||
10604 | 777 |
ln2 |
18492 | 778 |
"return the natural logarithm of 2" |
779 |
||
780 |
"/ don't expect this many valid digits on all machines; |
|
10604 | 781 |
"/ The actual precision is very CPU specific. |
782 |
||
783 |
^ 0.69314718055994530941723212145817657. |
|
784 |
||
785 |
"Created: / 07-06-2007 / 21:11:55 / cg" |
|
786 |
! |
|
787 |
||
19358 | 788 |
maxSmallInteger |
21868 | 789 |
"return the max. smallInteger value as a float" |
790 |
||
19358 | 791 |
^ MaxSmallInteger |
792 |
! |
|
793 |
||
21859 | 794 |
negativeInfinity |
24302 | 795 |
"return a float which represents positive infinity (for my instances). |
796 |
Warning: do not compare equal against infinities; |
|
797 |
instead, check using isFinite or isInfinite" |
|
21859 | 798 |
|
799 |
NegativeInfinity isNil ifTrue:[ |
|
24295 | 800 |
NegativeInfinity := super negativeInfinity |
21859 | 801 |
]. |
802 |
^ NegativeInfinity |
|
803 |
||
804 |
" |
|
21868 | 805 |
Float negativeInfinity == Float negativeInfinity |
21859 | 806 |
" |
807 |
||
808 |
"Created: / 20-06-2017 / 13:56:35 / cg" |
|
24302 | 809 |
"Modified (comment): / 09-06-2019 / 12:55:10 / Claus Gittinger" |
21859 | 810 |
! |
811 |
||
24930 | 812 |
phi |
813 |
"return the constant phi as Float" |
|
814 |
||
815 |
"/ don't expect this many valid digits on all machines; |
|
816 |
"/ The actual precision is very CPU specific. |
|
817 |
||
818 |
^ 1.618033988749894848204586834365638117720309179805762862135 |
|
819 |
||
820 |
||
821 |
! |
|
822 |
||
701 | 823 |
pi |
1260 | 824 |
"return the constant pi as Float" |
1 | 825 |
|
20799 | 826 |
"/ don't expect this many valid digits on all machines; |
3244 | 827 |
"/ The actual precision is very CPU specific. |
828 |
||
6063 | 829 |
^ 3.14159265358979323846264338327950288419716939937510582097494459 |
1260 | 830 |
|
831 |
"Modified: 23.4.1996 / 09:27:02 / cg" |
|
1 | 832 |
! |
833 |
||
10604 | 834 |
sqrt2 |
20799 | 835 |
"/ don't expect this many valid digits on all machines; |
10604 | 836 |
"/ The actual precision is very CPU specific. |
837 |
||
838 |
^ 1.41421356237309504880168872420969808 |
|
839 |
||
840 |
"Created: / 07-06-2007 / 21:12:33 / cg" |
|
841 |
! |
|
842 |
||
24930 | 843 |
sqrt5 |
844 |
"/ don't expect this many valid digits on all machines; |
|
845 |
"/ The actual precision is very CPU specific. |
|
846 |
||
847 |
^ 2.236067977499789696409173668731276235440618359611525724270 |
|
848 |
||
849 |
"Created: / 07-06-2007 / 21:12:33 / cg" |
|
850 |
! |
|
851 |
||
1 | 852 |
unity |
1260 | 853 |
"return the neutral element for multiplication (1.0) as Float" |
1 | 854 |
|
855 |
^ 1.0 |
|
1260 | 856 |
|
857 |
"Modified: 23.4.1996 / 09:27:09 / cg" |
|
1 | 858 |
! |
859 |
||
701 | 860 |
zero |
1260 | 861 |
"return the neutral element for addition (0.0) as Float" |
1 | 862 |
|
701 | 863 |
^ 0.0 |
1260 | 864 |
|
865 |
"Modified: 23.4.1996 / 09:27:15 / cg" |
|
1 | 866 |
! ! |
867 |
||
14105 | 868 |
!Float class methodsFor:'misc'! |
869 |
||
870 |
getFPUControl |
|
24169 | 871 |
"BORLAND only: get the fpu control word." |
14105 | 872 |
|
873 |
%{ |
|
874 |
#ifdef __BORLANDC__ |
|
14106 | 875 |
unsigned int _control87(); |
876 |
||
14105 | 877 |
int result = _control87(0, 0); |
878 |
RETURN(__MKSMALLINT(result)); |
|
879 |
#endif |
|
24169 | 880 |
%}. |
881 |
^ 0 "/ otherwise an arbitrary value |
|
14105 | 882 |
|
883 |
" |
|
21849 | 884 |
self getFPUControl |
14105 | 885 |
" |
21849 | 886 |
|
887 |
"Modified (comment): / 20-06-2017 / 11:51:58 / cg" |
|
24169 | 888 |
"Modified (comment): / 27-05-2019 / 08:58:54 / Claus Gittinger" |
14105 | 889 |
! |
890 |
||
891 |
setFPUControl |
|
21849 | 892 |
"BORLAND only: set the fpu control word for 64 bit precision for long doubles here" |
14105 | 893 |
|
894 |
%{ |
|
895 |
#ifdef __BORLANDC__ |
|
896 |
#include <float.h> |
|
897 |
||
898 |
// Set precision to long double / 64bit |
|
899 |
int result = _control87(PC_64, MCW_PC); |
|
900 |
RETURN(__MKSMALLINT(result)); |
|
901 |
#endif |
|
24169 | 902 |
%}. |
903 |
"/ otherwise ignored |
|
14105 | 904 |
|
905 |
" |
|
21849 | 906 |
self setFPUControl |
14105 | 907 |
" |
21849 | 908 |
|
909 |
"Modified (comment): / 20-06-2017 / 11:51:54 / cg" |
|
24169 | 910 |
"Modified (comment): / 27-05-2019 / 08:58:35 / Claus Gittinger" |
14105 | 911 |
! ! |
912 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
913 |
!Float class methodsFor:'queries'! |
3 | 914 |
|
24320 | 915 |
epsilon |
916 |
"return the maximum relative spacing of instances of mySelf |
|
917 |
(i.e. the value-delta of the least significant bit)" |
|
918 |
||
919 |
Epsilon isNil ifTrue:[ |
|
24915 | 920 |
Epsilon := self computeEpsilon. |
24320 | 921 |
]. |
922 |
^ Epsilon |
|
923 |
||
24915 | 924 |
" |
925 |
Float epsilon -> 1.11022302462516E-16 |
|
926 |
ShortFloat epsilon -> 5.960464e-08 |
|
927 |
LongFloat epsilon -> 5.42101086242752217E-20 |
|
928 |
QuadFloat epsilon -> |
|
929 |
" |
|
930 |
||
24320 | 931 |
"Modified (comment): / 22-06-2017 / 13:44:12 / cg" |
932 |
! |
|
933 |
||
6898 | 934 |
exponentCharacter |
24326 | 935 |
"return the character used to print between mantissa an exponent. |
936 |
Also used by the scanner when reading numbers." |
|
937 |
||
6898 | 938 |
^ $d |
24326 | 939 |
|
940 |
"Modified (comment): / 10-06-2019 / 21:27:46 / Claus Gittinger" |
|
6898 | 941 |
! |
942 |
||
3 | 943 |
isBuiltInClass |
1264 | 944 |
"return true if this class is known by the run-time-system. |
945 |
Here, true is returned for myself, false for subclasses." |
|
3 | 946 |
|
947 |
^ self == Float |
|
1264 | 948 |
|
949 |
"Modified: 23.4.1996 / 15:59:04 / cg" |
|
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
950 |
! |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
951 |
|
7355 | 952 |
numBitsInExponent |
953 |
"answer the number of bits in the exponent |
|
954 |
This is an IEEE float, where 11 bits are available: |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
955 |
seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
7355 | 956 |
" |
957 |
||
958 |
^ 11 |
|
24206 | 959 |
|
960 |
" |
|
961 |
1.0 numBitsInExponent |
|
962 |
" |
|
963 |
||
964 |
"Modified (format): / 28-05-2019 / 08:55:51 / Claus Gittinger" |
|
7355 | 965 |
! |
966 |
||
967 |
numBitsInMantissa |
|
968 |
"answer the number of bits in the mantissa. |
|
969 |
This is an IEEE double, where 52 bits (the hidden one is not counted here) are available: |
|
11945 | 970 |
seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
7355 | 971 |
" |
972 |
||
973 |
^ 52 |
|
974 |
! |
|
975 |
||
976 |
precision |
|
24266 | 977 |
"answer the precision (the number of bits in the mantissa) of a Float (in bits) |
11945 | 978 |
This is an IEEE double, where only the fraction from the normalized mantissa is stored |
979 |
and so there is a hidden bit and the mantissa is actually represented |
|
9150 | 980 |
by 53 binary digits (although only 52 are needed in the binary representation)" |
7355 | 981 |
|
982 |
^ 53 |
|
19326 | 983 |
|
984 |
" |
|
985 |
self numBitsInMantissa + 1 |
|
986 |
self precision |
|
987 |
" |
|
24266 | 988 |
|
989 |
"Modified (comment): / 06-06-2019 / 13:23:58 / Claus Gittinger" |
|
7355 | 990 |
! |
991 |
||
992 |
radix |
|
24440 | 993 |
"answer the radix of a Float's exponent |
7355 | 994 |
This is an IEEE float, which is represented as binary" |
995 |
||
8635 | 996 |
^ 2 "must be careful here, whenever ST/X is used on VAX or a 370" |
24440 | 997 |
|
998 |
"Modified (comment): / 19-07-2019 / 17:28:11 / Claus Gittinger" |
|
3 | 999 |
! ! |
1000 |
||
1 | 1001 |
!Float methodsFor:'arithmetic'! |
1002 |
||
701 | 1003 |
* aNumber |
11733 | 1004 |
"return the product of the receiver and the argument." |
701 | 1005 |
|
1006 |
%{ /* NOCONTEXT */ |
|
18296 | 1007 |
#ifdef __SCHTEAM__ |
1008 |
if (aNumber.isNumber()) { |
|
1009 |
return context._RETURN( self.times(aNumber) ); |
|
1010 |
} |
|
1011 |
#else |
|
701 | 1012 |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1013 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1014 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1015 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1016 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1017 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1018 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1019 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1020 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1021 |
*/ |
701 | 1022 |
OBJ newFloat; |
1023 |
double result; |
|
1024 |
||
1025 |
if (__isSmallInteger(aNumber)) { |
|
11945 | 1026 |
result = __floatVal(self) * (double)(__intVal(aNumber)); |
701 | 1027 |
retResult: |
11945 | 1028 |
__qMKFLOAT(newFloat, result); |
1029 |
RETURN ( newFloat ); |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1030 |
} |
14689
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1031 |
/* knowing that aNumber is not a SmallInt, we only need to check for nil; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1032 |
* then can use qIsXXX macros which saves us some checks |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1033 |
*/ |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1034 |
if (aNumber != nil) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1035 |
if (__qIsFloatLike(aNumber)) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1036 |
result = __floatVal(self) * __floatVal(aNumber); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1037 |
goto retResult; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1038 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1039 |
if (__qIsShortFloat(aNumber)) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1040 |
result = __floatVal(self) * (double)(__shortFloatVal(aNumber)); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1041 |
goto retResult; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1042 |
} |
701 | 1043 |
} |
18296 | 1044 |
#endif |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1045 |
%}. |
701 | 1046 |
^ aNumber productFromFloat:self |
1047 |
! |
|
1048 |
||
1 | 1049 |
+ aNumber |
1050 |
"return the sum of the receiver and the argument, aNumber" |
|
1051 |
||
1052 |
%{ /* NOCONTEXT */ |
|
18296 | 1053 |
#ifdef __SCHTEAM__ |
1054 |
if (aNumber.isNumber()) { |
|
1055 |
return context._RETURN( self.plus(aNumber) ); |
|
1056 |
} |
|
1057 |
#else |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1058 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1059 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1060 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1061 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1062 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1063 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1064 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1065 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1066 |
*/ |
1 | 1067 |
OBJ newFloat; |
1068 |
double result; |
|
1069 |
||
250 | 1070 |
if (__isSmallInteger(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1071 |
result = __floatVal(self) + (double)(__intVal(aNumber)); |
1 | 1072 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1073 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1074 |
RETURN ( newFloat ); |
11945 | 1075 |
} |
14689
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1076 |
/* knowing that aNumber is not a SmallInt, we only need to check for nil; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1077 |
* then can use qIsXXX macros which saves us some checks |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1078 |
*/ |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1079 |
if (aNumber != nil) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1080 |
if (__qIsFloatLike(aNumber)) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1081 |
result = __floatVal(self) + __floatVal(aNumber); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1082 |
goto retResult; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1083 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1084 |
if (__qIsShortFloat(aNumber)) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1085 |
result = __floatVal(self) + (double)(__shortFloatVal(aNumber)); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1086 |
goto retResult; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1087 |
} |
1 | 1088 |
} |
18296 | 1089 |
#endif |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1090 |
%}. |
1 | 1091 |
^ aNumber sumFromFloat:self |
1092 |
! |
|
1093 |
||
1094 |
- aNumber |
|
1095 |
"return the difference of the receiver and the argument, aNumber" |
|
1096 |
||
1097 |
%{ /* NOCONTEXT */ |
|
18296 | 1098 |
#ifdef __SCHTEAM__ |
1099 |
if (aNumber.isNumber()) { |
|
1100 |
return context._RETURN( self.minus(aNumber) ); |
|
1101 |
} |
|
1102 |
#else |
|
13 | 1103 |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1104 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1105 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1106 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1107 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1108 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1109 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1110 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1111 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1112 |
*/ |
1 | 1113 |
OBJ newFloat; |
1114 |
double result; |
|
1115 |
||
250 | 1116 |
if (__isSmallInteger(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1117 |
result = __floatVal(self) - (double)(__intVal(aNumber)); |
1 | 1118 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1119 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1120 |
RETURN ( newFloat ); |
11945 | 1121 |
} |
14689
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1122 |
/* knowing that aNumber is not a SmallInt, we only need to check for nil; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1123 |
* then can use qIsXXX macros which saves us some checks |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1124 |
*/ |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1125 |
if (aNumber != nil) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1126 |
if (__qIsFloatLike(aNumber)) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1127 |
result = __floatVal(self) - __floatVal(aNumber); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1128 |
goto retResult; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1129 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1130 |
if (__qIsShortFloat(aNumber)) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1131 |
result = __floatVal(self) - (double)(__shortFloatVal(aNumber)); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1132 |
goto retResult; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1133 |
} |
1 | 1134 |
} |
18296 | 1135 |
#endif |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1136 |
%}. |
1 | 1137 |
^ aNumber differenceFromFloat:self |
1138 |
! |
|
1139 |
||
1140 |
/ aNumber |
|
1141 |
"return the quotient of the receiver and the argument, aNumber" |
|
1142 |
||
1143 |
%{ /* NOCONTEXT */ |
|
18296 | 1144 |
#ifdef __SCHTEAM__ |
1145 |
if (aNumber.isNumber()) { |
|
1146 |
return context._RETURN( self.quotient(aNumber) ); |
|
1147 |
} |
|
1148 |
#else |
|
1 | 1149 |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1150 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1151 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1152 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1153 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1154 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1155 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1156 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1157 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1158 |
*/ |
1 | 1159 |
OBJ newFloat; |
1160 |
double result, val; |
|
1161 |
||
250 | 1162 |
if (__isSmallInteger(aNumber)) { |
11945 | 1163 |
if (aNumber != __mkSmallInteger(0)) { |
1164 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
|
1 | 1165 |
retResult: |
11945 | 1166 |
__qMKFLOAT(newFloat, result); |
1167 |
RETURN ( newFloat ); |
|
1168 |
} |
|
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1169 |
} else if (__isFloatLike(aNumber)) { |
11945 | 1170 |
val = __floatVal(aNumber); |
1171 |
if (val != 0.0) { |
|
1172 |
result = __floatVal(self) / val; |
|
1173 |
goto retResult; |
|
1174 |
} |
|
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1175 |
} else if (__isShortFloat(aNumber)) { |
11945 | 1176 |
val = (double)(__shortFloatVal(aNumber)); |
1177 |
if (val != 0.0) { |
|
1178 |
result = __floatVal(self) / val; |
|
1179 |
goto retResult; |
|
1180 |
} |
|
1 | 1181 |
} |
18296 | 1182 |
#endif |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1183 |
%}. |
1 | 1184 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
11945 | 1185 |
" |
1186 |
No, you shalt not divide by zero |
|
1187 |
" |
|
1188 |
^ ZeroDivide raiseRequestWith:thisContext. |
|
1 | 1189 |
]. |
1190 |
^ aNumber quotientFromFloat:self |
|
1191 |
! |
|
1192 |
||
14923 | 1193 |
abs |
1194 |
"return the absolute value of the receiver |
|
1195 |
reimplemented here for speed" |
|
1196 |
||
1197 |
%{ /* NOCONTEXT */ |
|
18296 | 1198 |
#ifdef __SCHTEAM__ |
1199 |
return context._RETURN( self.abs() ); |
|
1200 |
#else |
|
14923 | 1201 |
|
1202 |
OBJ newFloat; |
|
1203 |
double val =__floatVal(self); |
|
1204 |
||
1205 |
if (val < 0.0) { |
|
1206 |
__qMKFLOAT(newFloat, -val); |
|
1207 |
RETURN ( newFloat ); |
|
1208 |
} |
|
1209 |
RETURN (self); |
|
18296 | 1210 |
#endif |
14923 | 1211 |
%}. |
1212 |
||
1213 |
" |
|
1214 |
3.0 abs |
|
1215 |
-3.0 abs |
|
1216 |
" |
|
1217 |
! |
|
1218 |
||
1219 |
negated |
|
17226 | 1220 |
"return the receiver negated" |
14923 | 1221 |
|
1222 |
%{ /* NOCONTEXT */ |
|
18296 | 1223 |
#ifdef __SCHTEAM__ |
1224 |
return context._RETURN( self.negated() ); |
|
1225 |
#else |
|
14923 | 1226 |
OBJ newFloat; |
1227 |
double rslt = - __floatVal(self); |
|
1228 |
||
1229 |
__qMKFLOAT(newFloat, rslt); |
|
1230 |
RETURN ( newFloat ); |
|
18296 | 1231 |
#endif |
14923 | 1232 |
%}. |
1233 |
! |
|
1234 |
||
14689
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1235 |
rem: aNumber |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1236 |
"return the floating point remainder of the receiver and the argument, aNumber" |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1237 |
|
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1238 |
%{ /* NOCONTEXT */ |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1239 |
|
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1240 |
/* |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1241 |
* notice: |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1242 |
* the following inline code handles some common cases, |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1243 |
* and exists as an optimization, to speed up those cases. |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1244 |
* |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1245 |
* Conceptionally, (and for most other argument types), |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1246 |
* mixed arithmetic is implemented by double dispatching |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1247 |
* (see the message send at the bottom) |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1248 |
*/ |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1249 |
OBJ newFloat; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1250 |
double result, val; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1251 |
|
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1252 |
if (__isSmallInteger(aNumber)) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1253 |
if (aNumber != __mkSmallInteger(0)) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1254 |
val = (double)__intVal(aNumber); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1255 |
computeResult: |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1256 |
result = fmod(__floatVal(self), val) ; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1257 |
__qMKFLOAT(newFloat, result); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1258 |
RETURN ( newFloat ); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1259 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1260 |
} else if (__isFloatLike(aNumber)) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1261 |
val = __floatVal(aNumber); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1262 |
if (val != 0.0) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1263 |
goto computeResult; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1264 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1265 |
} else if (__isShortFloat(aNumber)) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1266 |
val = (double)(__shortFloatVal(aNumber)); |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1267 |
if (val != 0.0) { |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1268 |
goto computeResult; |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1269 |
} |
14720 | 1270 |
#ifdef LONGFLOAT_KNOWN_HERE |
1271 |
} else if (__isLongFloat(aNumber)) { |
|
1272 |
long double lval; |
|
1273 |
||
1274 |
lval = (long double)(__longFloatVal(aNumber)); |
|
1275 |
if (val != 0.0) { |
|
1276 |
long double lResult; |
|
1277 |
||
1278 |
lResult = fmodl((long double)(__floatVal(self)), lval); |
|
1279 |
__qMKLFLOAT(newFloat, lResult); |
|
1280 |
RETURN (newFloat); |
|
1281 |
} |
|
1282 |
#endif |
|
14689
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1283 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1284 |
%}. |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1285 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1286 |
" |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1287 |
No, you shalt not divide by zero |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1288 |
" |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1289 |
^ ZeroDivide raiseRequestWith:thisContext. |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1290 |
]. |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1291 |
^ aNumber remainderFromFloat:self |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1292 |
! |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1293 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1294 |
uncheckedDivide:aNumber |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1295 |
"return the quotient of the receiver and the argument, aNumber. |
7471 | 1296 |
Do not check for divide by zero (return NaN or Infinity). |
7355 | 1297 |
This operation is provided for emulators of other languages/semantics, |
1298 |
where no exception is raised for these results (i.e. Java). |
|
18838 | 1299 |
It is only defined if the argument's type is the same as the receiver's." |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1300 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1301 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1302 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1303 |
OBJ newFloat; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1304 |
double result, val; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1305 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1306 |
if (__isSmallInteger(aNumber)) { |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1307 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1308 |
retResult: |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1309 |
__qMKFLOAT(newFloat, result); |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1310 |
RETURN ( newFloat ); |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1311 |
} |
7355 | 1312 |
if (__isFloatLike(aNumber)) { |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1313 |
val = __floatVal(aNumber); |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1314 |
result = __floatVal(self) / val; |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1315 |
goto retResult; |
7355 | 1316 |
} |
1317 |
if (__isShortFloat(aNumber)) { |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1318 |
val = (double)(__shortFloatVal(aNumber)); |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1319 |
result = __floatVal(self) / val; |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1320 |
goto retResult; |
7355 | 1321 |
} |
1322 |
%}. |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1323 |
^ aNumber quotientFromFloat:self |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1324 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1325 |
" |
11945 | 1326 |
0.0 uncheckedDivide:0.0 |
1327 |
1.0 uncheckedDivide:0.0 |
|
1328 |
-1.0 uncheckedDivide:0.0 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1329 |
" |
1 | 1330 |
! ! |
1331 |
||
701 | 1332 |
|
5238 | 1333 |
!Float methodsFor:'coercing & converting'! |
1 | 1334 |
|
3014 | 1335 |
asDouble |
17226 | 1336 |
"ST80 compatibility: return a double with the receiver's value. |
1337 |
In ST/X, floats are the equivalent to ST80 doubles" |
|
3014 | 1338 |
|
1339 |
^ self |
|
1340 |
! |
|
1341 |
||
701 | 1342 |
asFloat |
24280 | 1343 |
"return a Float with same value - that's me" |
701 | 1344 |
|
1345 |
^ self |
|
24280 | 1346 |
|
1347 |
"Modified (comment): / 07-06-2019 / 02:34:18 / Claus Gittinger" |
|
701 | 1348 |
! |
1349 |
||
1350 |
asInteger |
|
1351 |
"return an integer with same value - might truncate" |
|
1352 |
||
1 | 1353 |
%{ /* NOCONTEXT */ |
1670 | 1354 |
double dVal; |
13 | 1355 |
|
1670 | 1356 |
dVal = __floatVal(self); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
1357 |
#ifdef __win32__ |
11945 | 1358 |
if (! isnan(dVal)) |
7420 | 1359 |
#endif |
1360 |
{ |
|
11945 | 1361 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
1362 |
RETURN ( __mkSmallInteger( (INT)dVal) ); |
|
1363 |
} |
|
701 | 1364 |
} |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1365 |
%}. |
701 | 1366 |
^ super asInteger |
1367 |
||
1368 |
"12345.0 asInteger" |
|
1369 |
"1e15 asInteger" |
|
1 | 1370 |
! |
1371 |
||
5986 | 1372 |
asLongFloat |
24280 | 1373 |
"return a LongFloat with same value as receiver" |
5986 | 1374 |
|
7355 | 1375 |
^ LongFloat fromFloat:self |
5986 | 1376 |
|
1377 |
" |
|
11945 | 1378 |
123 asFloat asLongFloat |
5986 | 1379 |
" |
1380 |
||
24280 | 1381 |
"Created: / 07-09-2001 / 13:43:04 / cg" |
1382 |
"Modified (comment): / 07-06-2019 / 02:34:07 / Claus Gittinger" |
|
1383 |
! |
|
1384 |
||
1385 |
asQuadFloat |
|
1386 |
"return a quadFloat with same value as receiver" |
|
1387 |
||
1388 |
^ QuadFloat fromFloat:self |
|
1389 |
||
1390 |
" |
|
1391 |
123 asFloat asQuadFloat |
|
24328 | 1392 |
0 asFloat asQuadFloat |
1393 |
0.0 asQuadFloat |
|
24280 | 1394 |
" |
1395 |
||
1396 |
"Created: / 07-06-2019 / 02:28:26 / Claus Gittinger" |
|
24328 | 1397 |
"Modified (comment): / 10-06-2019 / 21:51:04 / Claus Gittinger" |
5986 | 1398 |
! |
1399 |
||
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1400 |
asShortFloat |
24280 | 1401 |
"return a ShortFloat with same value as receiver. |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1402 |
Raises an error if the receiver exceeds the float range." |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1403 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1404 |
%{ /* NOCONTEXT */ |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1405 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1406 |
OBJ dummy = @global(ShortFloat); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1407 |
OBJ newFloat; |
24255 | 1408 |
double dVal = __floatVal(self); |
1409 |
float fVal = (float)dVal; |
|
1410 |
||
1411 |
if (isfinite(fVal) || !isfinite(dVal)) { |
|
24280 | 1412 |
__qMKSFLOAT(newFloat, fVal); |
1413 |
RETURN ( newFloat ); |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1414 |
} |
18296 | 1415 |
%}. |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1416 |
" |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1417 |
value out of range |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1418 |
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:
24230
diff
changeset
|
1419 |
" |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1420 |
^ self class |
24280 | 1421 |
raise:#infiniteResultSignal |
1422 |
receiver:self |
|
1423 |
selector:#asShortFloat |
|
1424 |
arguments:#() |
|
1425 |
errorString:'receiver is out of the single-precision float range' |
|
1426 |
||
1427 |
"Modified: / 07-06-2019 / 02:34:14 / Claus Gittinger" |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1428 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1429 |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1430 |
asTrueFraction |
17226 | 1431 |
"Answer a fraction or integer that EXACTLY represents the receiver, |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1432 |
a double precision IEEE floating point number. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1433 |
Floats are stored in the same form on all platforms. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1434 |
(Does not handle gradual underflow or NANs.) |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1435 |
By David N. Smith with significant performance |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1436 |
improvements by Luciano Esteban Notarfrancesco. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1437 |
(Version of 11April97)" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1438 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1439 |
|shifty sign expPart exp fraction fractionPart result zeroBitsCount| |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1440 |
|
6344 | 1441 |
self isFinite ifFalse:[ |
24745 | 1442 |
^ self asMetaNumber |
7441 | 1443 |
"/ ^ self class |
1444 |
"/ raise:#domainErrorSignal |
|
1445 |
"/ receiver:self |
|
1446 |
"/ selector:#asTrueFraction |
|
1447 |
"/ arguments:#() |
|
1448 |
"/ errorString:'Cannot represent non-finite float as a fraction'. |
|
6341 | 1449 |
]. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1450 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1451 |
"Extract the bits of an IEEE double float " |
6341 | 1452 |
shifty := LargeInteger basicNew numberOfDigits:8. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1453 |
UninterpretedBytes isBigEndian ifTrue:[ |
24745 | 1454 |
"/ shifty := ((self longWordAt: 1) bitShift: 32) + (self longWordAt: 2). |
1455 |
1 to:8 do:[:i | shifty digitAt:(9-i) put:(self basicAt:i)]. |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1456 |
] ifFalse:[ |
24745 | 1457 |
1 to:8 do:[:i | shifty digitAt:i put:(self basicAt:i)]. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1458 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1459 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1460 |
" Extract the sign and the biased exponent " |
24745 | 1461 |
sign := (shifty bitShift: -63) == 0 ifTrue: [1] ifFalse: [-1]. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1462 |
expPart := (shifty bitShift: -52) bitAnd: 16r7FF. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1463 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1464 |
" Extract fractional part; answer 0 if this is a true 0.0 value " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1465 |
fractionPart := shifty bitAnd: 16r000FFFFFFFFFFFFF. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1466 |
( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0 ]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1467 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1468 |
" Replace omitted leading 1 in fraction " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1469 |
fraction := fractionPart bitOr: 16r0010000000000000. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1470 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1471 |
"Unbias exponent: 16r3FF is bias; 52 is fraction width" |
7480 | 1472 |
exp := 16r3FF - expPart + 52. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1473 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1474 |
" Form the result. When exp>52, the exponent is adjusted by |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1475 |
the number of trailing zero bits in the fraction to minimize |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1476 |
the (huge) time otherwise spent in #gcd:. " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1477 |
exp negative ifTrue: [ |
24745 | 1478 |
result := sign * (fraction bitShift: exp negated) |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1479 |
] ifFalse:[ |
24745 | 1480 |
zeroBitsCount := fraction lowBit - 1. |
1481 |
exp := exp - zeroBitsCount. |
|
1482 |
exp <= 0 ifTrue: [ |
|
1483 |
zeroBitsCount := zeroBitsCount + exp. |
|
1484 |
"exp := 0." " Not needed; exp not refernced again " |
|
1485 |
result := sign * (fraction bitShift:zeroBitsCount negated) |
|
1486 |
] ifFalse: [ |
|
1487 |
result := Fraction |
|
1488 |
numerator: (sign * (fraction bitShift: zeroBitsCount negated)) |
|
1489 |
denominator: (1 bitShift:exp) |
|
1490 |
] |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1491 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1492 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1493 |
"Low cost validation omitted after extensive testing" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1494 |
"(result asFloat = self) ifFalse: [self error: 'asTrueFraction validation failed']." |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1495 |
|
11945 | 1496 |
^ result |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1497 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1498 |
" |
17226 | 1499 |
0.3 asTrueFraction - as you can see, Float is not able to represent this exactly |
1500 |
1.25 asTrueFraction - but this one (it is a sum of powers of two) |
|
11945 | 1501 |
0.25 asTrueFraction |
1502 |
-0.25 asTrueFraction |
|
1503 |
3e37 asTrueFraction |
|
17226 | 1504 |
2e37 asTrueFraction |
1505 |
1e37 asTrueFraction |
|
18296 | 1506 |
1e30 asTrueFraction |
6341 | 1507 |
Float NaN asTrueFraction |
6344 | 1508 |
Float infinity asTrueFraction |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1509 |
" |
24230 | 1510 |
|
1511 |
"Modified (format): / 29-05-2019 / 03:12:55 / Claus Gittinger" |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1512 |
! |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1513 |
|
701 | 1514 |
coerce:aNumber |
18838 | 1515 |
"convert the argument aNumber into an instance of the receiver's class and return it." |
1 | 1516 |
|
701 | 1517 |
^ aNumber asFloat |
1518 |
! |
|
13 | 1519 |
|
701 | 1520 |
generality |
1521 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
1522 |
||
1523 |
^ 80 |
|
1 | 1524 |
! ! |
1525 |
||
1526 |
!Float methodsFor:'comparing'! |
|
1527 |
||
1528 |
< aNumber |
|
1529 |
"return true, if the argument is greater" |
|
1530 |
||
1531 |
%{ /* NOCONTEXT */ |
|
18296 | 1532 |
#ifdef __SCHTEAM__ |
1533 |
if (aNumber.isNumber()) { |
|
1534 |
return context._RETURN( self.ltP(aNumber) ); |
|
1535 |
} |
|
1536 |
#else |
|
11945 | 1537 |
/* |
1538 |
* notice: |
|
1539 |
* the following inline code handles some common cases, |
|
1540 |
* and exists as an optimization, to speed up those cases. |
|
1541 |
* |
|
1542 |
* Conceptionally, (and for most other argument types), |
|
1543 |
* mixed arithmetic is implemented by double dispatching |
|
1544 |
* (see the message send at the bottom) |
|
1545 |
*/ |
|
7355 | 1546 |
if (__isSmallInteger(aNumber)) { |
11945 | 1547 |
RETURN ( (__floatVal(self) < (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1548 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1549 |
if (aNumber != nil) { |
11945 | 1550 |
if (__qIsFloatLike(aNumber)) { |
1551 |
RETURN ( (__floatVal(self) < __floatVal(aNumber)) ? true : false ); |
|
1552 |
} |
|
1553 |
if (__qIsShortFloat(aNumber)) { |
|
1554 |
RETURN ( (__floatVal(self) < (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1555 |
} |
|
1 | 1556 |
} |
18296 | 1557 |
#endif |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1558 |
%}. |
1 | 1559 |
^ aNumber lessFromFloat:self |
1560 |
! |
|
1561 |
||
1562 |
<= aNumber |
|
1563 |
"return true, if the argument is greater or equal" |
|
1564 |
||
1565 |
%{ /* NOCONTEXT */ |
|
18296 | 1566 |
#ifdef __SCHTEAM__ |
1567 |
if (aNumber.isNumber()) { |
|
1568 |
return context._RETURN( self.leP(aNumber) ); |
|
1569 |
} |
|
1570 |
#else |
|
11945 | 1571 |
/* |
1572 |
* notice: |
|
1573 |
* the following inline code handles some common cases, |
|
1574 |
* and exists as an optimization, to speed up those cases. |
|
1575 |
* |
|
1576 |
* Conceptionally, (and for most other argument types), |
|
1577 |
* mixed arithmetic is implemented by double dispatching |
|
1578 |
* (see the message send at the bottom) |
|
1579 |
*/ |
|
7355 | 1580 |
if (__isSmallInteger(aNumber)) { |
11945 | 1581 |
RETURN ( (__floatVal(self) <= (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1582 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1583 |
if (aNumber != nil) { |
11945 | 1584 |
if (__qIsFloatLike(aNumber)) { |
1585 |
RETURN ( (__floatVal(self) <= __floatVal(aNumber)) ? true : false ); |
|
1586 |
} |
|
1587 |
if (__qIsShortFloat(aNumber)) { |
|
1588 |
RETURN ( (__floatVal(self) <= (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1589 |
} |
|
1 | 1590 |
} |
18296 | 1591 |
#endif |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1592 |
%}. |
1 | 1593 |
^ self retry:#<= coercing:aNumber |
1594 |
! |
|
1595 |
||
1596 |
= aNumber |
|
7355 | 1597 |
"return true, if the argument represents the same numeric value |
1598 |
as the receiver, false otherwise" |
|
1 | 1599 |
|
1600 |
%{ /* NOCONTEXT */ |
|
18296 | 1601 |
#ifdef __SCHTEAM__ |
1602 |
if (aNumber.isNumber()) { |
|
1603 |
return context._RETURN( self.eqNrP(aNumber) ); |
|
1604 |
} |
|
1605 |
#else |
|
13 | 1606 |
|
11945 | 1607 |
/* |
1608 |
* notice: |
|
1609 |
* the following inline code handles some common cases, |
|
1610 |
* and exists as an optimization, to speed up those cases. |
|
1611 |
* |
|
1612 |
* Conceptionally, (and for most other argument types), |
|
1613 |
* mixed arithmetic is implemented by double dispatching |
|
1614 |
* (see the message send at the bottom) |
|
1615 |
*/ |
|
7355 | 1616 |
if (__isSmallInteger(aNumber)) { |
11945 | 1617 |
RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1618 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1619 |
if (aNumber != nil) { |
11945 | 1620 |
if (__qIsFloatLike(aNumber)) { |
1621 |
RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false ); |
|
1622 |
} |
|
1623 |
if (__qIsShortFloat(aNumber)) { |
|
1624 |
RETURN ( (__floatVal(self) == (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1625 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1626 |
} else { |
11945 | 1627 |
RETURN (false); |
1 | 1628 |
} |
18296 | 1629 |
#endif |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1630 |
%}. |
7355 | 1631 |
^ aNumber equalFromFloat:self |
1 | 1632 |
! |
1633 |
||
701 | 1634 |
> aNumber |
1635 |
"return true, if the argument is less" |
|
1 | 1636 |
|
1637 |
%{ /* NOCONTEXT */ |
|
18296 | 1638 |
#ifdef __SCHTEAM__ |
1639 |
if (aNumber.isNumber()) { |
|
1640 |
return context._RETURN( self.gtP(aNumber) ); |
|
1641 |
} |
|
1642 |
#else |
|
11945 | 1643 |
/* |
1644 |
* notice: |
|
1645 |
* the following inline code handles some common cases, |
|
1646 |
* and exists as an optimization, to speed up those cases. |
|
1647 |
* |
|
1648 |
* Conceptionally, (and for most other argument types), |
|
1649 |
* mixed arithmetic is implemented by double dispatching |
|
1650 |
* (see the message send at the bottom) |
|
1651 |
*/ |
|
7355 | 1652 |
if (__isSmallInteger(aNumber)) { |
11945 | 1653 |
RETURN ( (__floatVal(self) > (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1654 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1655 |
if (aNumber != nil) { |
11945 | 1656 |
if (__qIsFloatLike(aNumber)) { |
1657 |
RETURN ( (__floatVal(self) > __floatVal(aNumber)) ? true : false ); |
|
1658 |
} |
|
1659 |
if (__qIsShortFloat(aNumber)) { |
|
1660 |
RETURN ( (__floatVal(self) > (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1661 |
} |
|
1 | 1662 |
} |
18296 | 1663 |
#endif |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1664 |
%}. |
701 | 1665 |
^ self retry:#> coercing:aNumber |
1666 |
! |
|
1667 |
||
1668 |
>= aNumber |
|
1669 |
"return true, if the argument is less or equal" |
|
1670 |
||
1671 |
%{ /* NOCONTEXT */ |
|
18296 | 1672 |
#ifdef __SCHTEAM__ |
1673 |
if (aNumber.isNumber()) { |
|
1674 |
return context._RETURN( self.geP(aNumber) ); |
|
1675 |
} |
|
1676 |
#else |
|
11945 | 1677 |
/* |
1678 |
* notice: |
|
1679 |
* the following inline code handles some common cases, |
|
1680 |
* and exists as an optimization, to speed up those cases. |
|
1681 |
* |
|
1682 |
* Conceptionally, (and for most other argument types), |
|
1683 |
* mixed arithmetic is implemented by double dispatching |
|
1684 |
* (see the message send at the bottom) |
|
1685 |
*/ |
|
7355 | 1686 |
if (__isSmallInteger(aNumber)) { |
11945 | 1687 |
RETURN ( (__floatVal(self) >= (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1688 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1689 |
if (aNumber != nil) { |
11945 | 1690 |
if (__qIsFloatLike(aNumber)) { |
1691 |
RETURN ( (__floatVal(self) >= __floatVal(aNumber)) ? true : false ); |
|
1692 |
} |
|
1693 |
if (__qIsShortFloat(aNumber)) { |
|
1694 |
RETURN ( (__floatVal(self) >= (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1695 |
} |
|
701 | 1696 |
} |
18296 | 1697 |
#endif |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1698 |
%}. |
701 | 1699 |
^ self retry:#>= coercing:aNumber |
92 | 1700 |
! |
1701 |
||
1702 |
hash |
|
1703 |
"return a number for hashing; redefined, since floats compare |
|
1704 |
by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same |
|
4594
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
1705 |
as 3 hash." |
92 | 1706 |
|
305 | 1707 |
|i| |
92 | 1708 |
|
1709 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1710 |
i := self asInteger. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1711 |
self = i ifTrue:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1712 |
^ i hash |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1713 |
]. |
92 | 1714 |
]. |
1715 |
||
1716 |
" |
|
305 | 1717 |
mhmh take some of my value-bits to hash on |
92 | 1718 |
" |
4590 | 1719 |
^ (((self basicAt:8) bitAnd:16r1F) bitShift:24) + |
305 | 1720 |
((self basicAt:7) bitShift:16) + |
1721 |
((self basicAt:6) bitShift:8) + |
|
4592 | 1722 |
(((self basicAt:5) + (self basicAt:1) + (self basicAt:2)) bitAnd:16rFF) |
92 | 1723 |
|
1724 |
" |
|
11945 | 1725 |
3 hash |
92 | 1726 |
3.0 hash |
11945 | 1727 |
3.1 hash |
1728 |
3.14159 hash |
|
1729 |
31.4159 hash |
|
1730 |
3.141591 hash |
|
1731 |
1.234567890123456 hash |
|
1732 |
1.234567890123457 hash |
|
92 | 1733 |
Set withAll:#(3 3.0 99 99.0 3.1415) |
1734 |
" |
|
1 | 1735 |
! |
1736 |
||
17199 | 1737 |
isAlmostEqualTo:aNumber nEpsilon:nE |
16658 | 1738 |
"return true, if the argument, aNumber represents almost the same numeric value |
1739 |
as the receiver, false otherwise. |
|
1740 |
||
1741 |
nE is the number of minimal float distances, that the numbers may differ and |
|
22578 | 1742 |
still be considered equal. |
22559 | 1743 |
That is an integer, which counts the delta-steps in the mantissa. |
1744 |
Notice, that the absolute value of the epsilon depends on the receiver |
|
1745 |
(i.e. with a receiver of 10^17, a mantissa-step is much larger than with 10^-17 as receiver) |
|
16658 | 1746 |
|
17199 | 1747 |
For background information why floats need this |
16658 | 1748 |
read: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ |
1749 |
" |
|
1750 |
||
21148 | 1751 |
Epsilon isNil ifTrue:[ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1752 |
Epsilon := self class computeEpsilon. |
21148 | 1753 |
]. |
1754 |
||
16658 | 1755 |
%{ /* NOCONTEXT */ |
1756 |
||
1757 |
/* |
|
1758 |
* notice: |
|
1759 |
* the following inline code handles some common cases, |
|
1760 |
* and exists as an optimization, to speed up those cases. |
|
1761 |
* |
|
1762 |
* Conceptionally, (and for most other argument types), |
|
1763 |
* mixed arithmetic is implemented by double dispatching |
|
1764 |
* (see the message send at the bottom) |
|
1765 |
*/ |
|
1766 |
||
1767 |
INT64 ulpDiff; |
|
1768 |
union { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1769 |
double d; |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1770 |
INT64 i; |
16658 | 1771 |
} myself, otherFloat; |
1772 |
int nEpsilon; |
|
1773 |
double scaledEpsilon; |
|
1774 |
||
1775 |
if (!__isSmallInteger(nE)) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1776 |
goto tryHarder; |
16658 | 1777 |
} |
1778 |
||
1779 |
nEpsilon = __intVal(nE); |
|
1780 |
scaledEpsilon = nEpsilon *__floatVal(@global(Epsilon)); |
|
1781 |
||
1782 |
if (__isSmallInteger(aNumber)) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1783 |
otherFloat.d = (double)(__intVal(aNumber)); |
16658 | 1784 |
} else if (aNumber == nil) { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1785 |
RETURN(false) |
16658 | 1786 |
} else if (__qIsFloatLike(aNumber)) { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1787 |
otherFloat.d = (double)(__floatVal(aNumber)); |
16658 | 1788 |
} else if (__qIsShortFloat(aNumber)) { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1789 |
otherFloat.d = (double)(__shortFloatVal(aNumber)); |
16658 | 1790 |
} else { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1791 |
goto tryHarder; |
16658 | 1792 |
} |
1793 |
||
1794 |
myself.d = __floatVal(self); |
|
1795 |
||
1796 |
// Check if the numbers are really close -- needed |
|
1797 |
// when comparing numbers near zero (ULP method below fails for numbers near 0!). |
|
1798 |
if (fabs(myself.d - otherFloat.d) <= scaledEpsilon) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1799 |
RETURN(true); |
16658 | 1800 |
} |
1801 |
||
1802 |
// if the signs differ, the numbers are different |
|
16667 | 1803 |
if ((myself.d >= 0) != (otherFloat.d >= 0)) { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1804 |
RETURN(false); |
16658 | 1805 |
} |
1806 |
||
1807 |
// compute the difference of the 'units in the last place" ULP |
|
1808 |
// (if ulpDiff == 1, two floats are adjecant) |
|
1809 |
ulpDiff = myself.i - otherFloat.i; |
|
1810 |
if (ulpDiff < 0) ulpDiff = -ulpDiff; |
|
1811 |
if (ulpDiff <= nEpsilon) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1812 |
RETURN(true); |
16658 | 1813 |
} else { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1814 |
RETURN(false) |
16658 | 1815 |
} |
1816 |
||
1817 |
tryHarder:; |
|
1818 |
%}. |
|
22559 | 1819 |
nE isInteger ifFalse:[ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1820 |
self error:'nEpsilon argument must be an integer'. |
22559 | 1821 |
]. |
16658 | 1822 |
^ aNumber isAlmostEqualToFromFloat:self nEpsilon:nE |
1823 |
||
1824 |
" |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1825 |
67329.234 isAlmostEqualTo:67329.23400000001 nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1826 |
1.0 isAlmostEqualTo:1.0001 nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1827 |
1.0 isAlmostEqualTo:-1.0 nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1828 |
1 isAlmostEqualTo:1.000000000000001 nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1829 |
1 isAlmostEqualTo:1.000000000000001 nEpsilon:10 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1830 |
1.0 isAlmostEqualTo:1 nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1831 |
1.0 isAlmostEqualTo:1 asFraction nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1832 |
0.0 isAlmostEqualTo:0 nEpsilon:1 |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1833 |
0.0 isAlmostEqualTo:self epsilon nEpsilon:1 |
16658 | 1834 |
" |
22854 | 1835 |
|
1836 |
"Modified: / 10-05-2018 / 00:48:57 / stefan" |
|
16658 | 1837 |
! |
1838 |
||
701 | 1839 |
~= aNumber |
1840 |
"return true, if the arguments value are not equal" |
|
1 | 1841 |
|
1842 |
%{ /* NOCONTEXT */ |
|
1843 |
||
11945 | 1844 |
/* |
1845 |
* notice: |
|
1846 |
* the following inline code handles some common cases, |
|
1847 |
* and exists as an optimization, to speed up those cases. |
|
1848 |
* |
|
1849 |
* Conceptionally, (and for most other argument types), |
|
1850 |
* mixed arithmetic is implemented by double dispatching |
|
1851 |
* (see the message send at the bottom) |
|
1852 |
*/ |
|
7355 | 1853 |
if (__isSmallInteger(aNumber)) { |
11945 | 1854 |
RETURN ( (__floatVal(self) != (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1855 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1856 |
if (aNumber != nil) { |
11945 | 1857 |
if (__qIsFloatLike(aNumber)) { |
1858 |
RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false ); |
|
1859 |
} |
|
1860 |
if (__qIsShortFloat(aNumber)) { |
|
1861 |
RETURN ( (__floatVal(self) != (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1862 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1863 |
} else { |
11945 | 1864 |
RETURN ( true ); |
1 | 1865 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1866 |
%}. |
7355 | 1867 |
^ super ~= aNumber |
1 | 1868 |
! ! |
1869 |
||
24191 | 1870 |
!Float methodsFor:'copying'! |
1871 |
||
1872 |
deepCopy |
|
1873 |
"return a deep copy of myself |
|
1874 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
1875 |
||
1876 |
^ self |
|
1877 |
! |
|
1878 |
||
1879 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
1880 |
"return a deep copy of myself |
|
1881 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
1882 |
||
1883 |
^ self |
|
1884 |
! |
|
1885 |
||
1886 |
shallowCopy |
|
1887 |
"return a shallow copy of the receiver" |
|
1888 |
||
1889 |
^ self |
|
1890 |
! |
|
1891 |
||
1892 |
simpleDeepCopy |
|
1893 |
"return a deep copy of the receiver |
|
1894 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
1895 |
||
1896 |
^ self |
|
1897 |
! ! |
|
1898 |
||
1 | 1899 |
!Float methodsFor:'mathematical functions'! |
1900 |
||
17218 | 1901 |
cbrt |
1902 |
"return the cubic root of myself." |
|
1903 |
||
1904 |
%{ /* NOCONTEXT */ |
|
1905 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
1906 |
#ifndef __win32__ /* seems to be not avail. in WIN32 math lib */ |
17218 | 1907 |
double val, rslt; |
1908 |
OBJ newFloat; |
|
1909 |
||
1910 |
val = __floatVal(self); |
|
1911 |
||
1912 |
{ |
|
24875 | 1913 |
__threadErrno = 0; |
1914 |
rslt = cbrt(val); |
|
1915 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
1916 |
{ |
|
1917 |
if (__threadErrno == 0) { |
|
1918 |
__qMKFLOAT(newFloat, rslt); |
|
1919 |
RETURN ( newFloat ); |
|
1920 |
} |
|
1921 |
} |
|
17218 | 1922 |
} |
1923 |
# endif /* WIN32 */ |
|
1924 |
%}. |
|
1925 |
^ super cbrt |
|
1926 |
||
1927 |
" |
|
1928 |
8 cbrt |
|
1929 |
-8 cbrt |
|
24875 | 1930 |
8.0 cbrt |
1931 |
-8.0 cbrt |
|
1932 |
8.0 raisedTo:(1/3) |
|
1933 |
-8.0 raisedTo:(1/3) |
|
17218 | 1934 |
" |
1935 |
! |
|
1936 |
||
701 | 1937 |
exp |
1938 |
"return e raised to the power of the receiver" |
|
1939 |
||
1940 |
%{ /* NOCONTEXT */ |
|
1941 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1942 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1943 |
OBJ newFloat; |
701 | 1944 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1945 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1946 |
rslt = exp(__floatVal(self)); |
7393 | 1947 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
1948 |
{ |
|
11945 | 1949 |
if (__threadErrno == 0) { |
1950 |
__qMKFLOAT(newFloat, rslt); |
|
1951 |
RETURN ( newFloat ); |
|
1952 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1953 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1954 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1955 |
^ self class |
11945 | 1956 |
raise:#domainErrorSignal |
1957 |
receiver:self |
|
1958 |
selector:#exp |
|
1959 |
arguments:#() |
|
1960 |
errorString:'bad receiver in exp' |
|
6195 | 1961 |
|
1962 |
"Modified: / 16.11.2001 / 14:14:29 / cg" |
|
701 | 1963 |
! |
1964 |
||
21832 | 1965 |
ldexp:exp |
1966 |
"multiply the receiver by an integral power of 2. |
|
1967 |
I.e. return self * (2 ^ exp)" |
|
1968 |
||
1969 |
%{ /* NOCONTEXT */ |
|
1970 |
#ifndef __SCHTEAM__ |
|
1971 |
double val, rslt; |
|
1972 |
OBJ newFloat; |
|
1973 |
||
1974 |
if (__isSmallInteger(exp)) { |
|
21868 | 1975 |
int __exp = __intVal(exp); |
1976 |
||
1977 |
val = __floatVal(self); |
|
1978 |
||
1979 |
{ |
|
1980 |
__threadErrno = 0; |
|
1981 |
rslt = ldexp(val, __exp); |
|
1982 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
1983 |
{ |
|
1984 |
if (__threadErrno == 0) { |
|
1985 |
__qMKFLOAT(newFloat, rslt); |
|
1986 |
RETURN ( newFloat ); |
|
1987 |
} |
|
1988 |
} |
|
1989 |
} |
|
21832 | 1990 |
} |
1991 |
#endif |
|
1992 |
%}. |
|
21835 | 1993 |
^ super ldexp:exp |
21832 | 1994 |
|
1995 |
" |
|
1996 |
1.0 ldexp:16 |
|
1997 |
" |
|
1998 |
||
1999 |
"Created: / 19-06-2017 / 01:42:22 / cg" |
|
21835 | 2000 |
"Modified: / 19-06-2017 / 09:16:32 / cg" |
21832 | 2001 |
! |
2002 |
||
1 | 2003 |
ln |
6193 | 2004 |
"return the natural logarithm of myself. |
2005 |
Raises an exception, if the receiver is less or equal to zero." |
|
1 | 2006 |
|
2007 |
%{ /* NOCONTEXT */ |
|
18296 | 2008 |
#ifdef __SCHTEAM__ |
18299 | 2009 |
return context._RETURN( self.log() ); |
18296 | 2010 |
#else |
1 | 2011 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2012 |
double val, rslt; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2013 |
OBJ newFloat; |
1 | 2014 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2015 |
val = __floatVal(self); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2016 |
|
22578 | 2017 |
/* |
2018 |
* to suppress the warnBox opened by win32 |
|
21952 | 2019 |
* to avoid returning -INF from some unix math libs (__osx__) |
2020 |
*/ |
|
2021 |
if (val > 0.0) { |
|
22578 | 2022 |
__threadErrno = 0; |
2023 |
rslt = log(val); |
|
2024 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2025 |
{ |
|
2026 |
if (__threadErrno == 0) { |
|
2027 |
__qMKFLOAT(newFloat, rslt); |
|
2028 |
RETURN ( newFloat ); |
|
2029 |
} |
|
2030 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2031 |
} |
18296 | 2032 |
#endif |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2033 |
%}. |
142 | 2034 |
" |
2035 |
an invalid value for logarithm |
|
21970 | 2036 |
if you need -INF for a zero receiver, try Number trapInfinity:[...] |
142 | 2037 |
" |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
2038 |
^ self class |
22578 | 2039 |
raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal]) |
2040 |
receiver:self |
|
2041 |
selector:#ln |
|
2042 |
arguments:#() |
|
2043 |
errorString:'bad receiver in ln (not strictly positive)' |
|
21952 | 2044 |
|
21970 | 2045 |
"Modified (comment): / 03-07-2017 / 15:58:17 / cg" |
1 | 2046 |
! |
2047 |
||
7373 | 2048 |
log10 |
21824 | 2049 |
"return the base-10 logarithm of the receiver. |
7373 | 2050 |
Raises an exception, if the receiver is less or equal to zero." |
2051 |
||
2052 |
%{ /* NOCONTEXT */ |
|
18296 | 2053 |
#ifdef __SCHTEAM__ |
18299 | 2054 |
return context._RETURN( self.log10() ); |
18296 | 2055 |
#else |
7373 | 2056 |
|
2057 |
double val, rslt; |
|
2058 |
OBJ newFloat; |
|
2059 |
||
2060 |
val = __floatVal(self); |
|
2061 |
||
22578 | 2062 |
/* |
2063 |
* to suppress the warnBox opened by win32 |
|
21953 | 2064 |
* to avoid returning -INF from some unix math libs (__osx__) |
2065 |
*/ |
|
2066 |
if (val > 0.0) { |
|
22578 | 2067 |
__threadErrno = 0; |
2068 |
rslt = log10(val); |
|
2069 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2070 |
{ |
|
2071 |
if (__threadErrno == 0) { |
|
2072 |
__qMKFLOAT(newFloat, rslt); |
|
2073 |
RETURN ( newFloat ); |
|
2074 |
} |
|
2075 |
} |
|
7373 | 2076 |
} |
18296 | 2077 |
#endif |
7373 | 2078 |
%}. |
2079 |
" |
|
2080 |
an invalid value for logarithm |
|
21970 | 2081 |
if you need -INF for a zero receiver, try Number trapInfinity:[...] |
7373 | 2082 |
" |
2083 |
^ self class |
|
22578 | 2084 |
raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal]) |
2085 |
receiver:self |
|
2086 |
selector:#log10 |
|
2087 |
arguments:#() |
|
2088 |
errorString:'bad receiver in log10 (not strictly positive)' |
|
21953 | 2089 |
|
21970 | 2090 |
"Modified (comment): / 03-07-2017 / 15:58:21 / cg" |
7373 | 2091 |
! |
2092 |
||
1 | 2093 |
raisedTo:aNumber |
2094 |
"return self raised to the power of aNumber" |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2095 |
|
1 | 2096 |
%{ |
21936 | 2097 |
double _n, rslt; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2098 |
OBJ newFloat; |
1 | 2099 |
|
21936 | 2100 |
if (__isFloatLike(aNumber)) { |
22578 | 2101 |
_n = __floatVal(aNumber); |
21936 | 2102 |
} else if (__isSmallInteger(aNumber)) { |
22578 | 2103 |
_n = (double)__intVal(aNumber); |
21936 | 2104 |
} else { |
22578 | 2105 |
goto notEasy; |
2106 |
} |
|
21936 | 2107 |
__threadErrno = 0; |
2108 |
rslt = pow(__floatVal(self), _n); |
|
2109 |
if (! isnan(rslt)) { /* Currently all our systems support isnan() */ |
|
22578 | 2110 |
if (__threadErrno == 0) { |
2111 |
__qMKFLOAT(newFloat, rslt); |
|
2112 |
RETURN ( newFloat ); |
|
2113 |
} |
|
1 | 2114 |
} |
22578 | 2115 |
notEasy: ; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2116 |
%}. |
21913 | 2117 |
"/ the c-library pow function, has a bug: |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
2118 |
"/ it does not deal correctly with negative numbers. |
19091 | 2119 |
"/ I.e. it raises an error on -8^(1/3) instead of returning a negative -2 |
2120 |
"/ work around with a kludge: |
|
2121 |
self < 0 ifTrue:[ |
|
22578 | 2122 |
^ (self negated raisedTo:aNumber) negated |
19091 | 2123 |
]. |
2124 |
||
21936 | 2125 |
^ aNumber raisedFromFloat:self |
2126 |
||
2127 |
"Modified: / 01-07-2017 / 21:58:26 / cg" |
|
1 | 2128 |
! |
2129 |
||
2130 |
sqrt |
|
6193 | 2131 |
"return the square root of myself. |
2132 |
Raises an exception, if the receiver is less than zero." |
|
1 | 2133 |
|
2134 |
%{ /* NOCONTEXT */ |
|
2135 |
||
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2136 |
double val, rslt; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2137 |
OBJ newFloat; |
1 | 2138 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2139 |
val = __floatVal(self); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2140 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
2141 |
#ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2142 |
if (val >= 0.0) |
3889
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
2143 |
#endif |
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
2144 |
{ |
11945 | 2145 |
__threadErrno = 0; |
2146 |
rslt = sqrt(val); |
|
2147 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2148 |
{ |
|
2149 |
if (__threadErrno == 0) { |
|
2150 |
__qMKFLOAT(newFloat, rslt); |
|
2151 |
RETURN ( newFloat ); |
|
2152 |
} |
|
2153 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2154 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2155 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
2156 |
^ self class |
11945 | 2157 |
raise:#imaginaryResultSignal |
2158 |
receiver:self |
|
2159 |
selector:#sqrt |
|
2160 |
arguments:#() |
|
2161 |
errorString:'bad (negative) receiver in sqrt' |
|
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
2162 |
|
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
2163 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
2164 |
10 sqrt |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
2165 |
-10 sqrt |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
2166 |
" |
6193 | 2167 |
|
6195 | 2168 |
"Modified: / 16.11.2001 / 14:14:43 / cg" |
13 | 2169 |
! ! |
2170 |
||
92 | 2171 |
!Float methodsFor:'printing & storing'! |
1 | 2172 |
|
22301 | 2173 |
printOn:aStream |
2174 |
"append a printed representation of the receiver to |
|
2175 |
the argument, aStream. |
|
2176 |
||
2177 |
I use #printString instead of #printOn: as basic print mechanism." |
|
2178 |
||
2179 |
aStream nextPutAll:self printString |
|
2180 |
||
2181 |
"Created: / 10-10-2017 / 14:05:13 / cg" |
|
2182 |
! |
|
2183 |
||
1 | 2184 |
printString |
2358 | 2185 |
"return a printed representation of the receiver; |
2186 |
if not specified otherwise (by setting DefaultPrintFormat), |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
2187 |
6 valid digits are printed. |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
2188 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
2189 |
#printOn: as basic print mechanism." |
1 | 2190 |
|
21868 | 2191 |
^ self printStringWithFormat:self class defaultPrintFormat |
18138 | 2192 |
|
2193 |
" |
|
22578 | 2194 |
Float pi printString. |
2195 |
1.0 printString |
|
2196 |
1.234 printString |
|
2197 |
1e10 printString |
|
2198 |
1e-60 printString |
|
2199 |
1.2e3 printString |
|
2200 |
1.2e30 printString |
|
2201 |
(1.0 uncheckedDivide:0) printString |
|
2202 |
(0.0 uncheckedDivide:0) printString |
|
2203 |
self pi printString. |
|
2204 |
||
2205 |
DecimalPointCharacter := $,. |
|
2206 |
1.234 printString. |
|
2207 |
1.0 printString. |
|
2208 |
1e10 printString. |
|
2209 |
1.2e3 printString. |
|
2210 |
1.2e30 printString. |
|
2211 |
(1.0 uncheckedDivide:0) printString. |
|
2212 |
(0.0 uncheckedDivide:0) printString. |
|
2213 |
DecimalPointCharacter := $. |
|
18138 | 2214 |
" |
21877 | 2215 |
|
2216 |
"Modified (comment): / 21-06-2017 / 09:46:01 / cg" |
|
18138 | 2217 |
! |
2218 |
||
2219 |
printStringWithFormat:format |
|
2220 |
"return a printed representation of the receiver; |
|
2221 |
fmt must be of the form: .nn, where nn is the number of digits. |
|
2222 |
To print 6 valid digits, use printStringWithFormat:'.6' |
|
2223 |
For Floats, the default used in printString, is 15 (because its a double); |
|
2224 |
for ShortFloats, it is 6 (because it is a float)" |
|
2225 |
||
1 | 2226 |
%{ /* NOCONTEXT */ |
2227 |
||
13 | 2228 |
char buffer[64]; |
1 | 2229 |
REGISTER char *cp; |
314 | 2230 |
OBJ s; |
2358 | 2231 |
char *fmt; |
2232 |
char fmtBuffer[20]; |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2233 |
int len; |
2358 | 2234 |
|
18138 | 2235 |
if (__isStringLike(format)) { |
18296 | 2236 |
fmt = (char *) __stringVal(format); |
2358 | 2237 |
} else { |
18296 | 2238 |
/* |
2239 |
* in case we get called with garbage ... |
|
2240 |
*/ |
|
2241 |
fmt = ".15"; |
|
2358 | 2242 |
} |
2243 |
||
2244 |
/* |
|
2245 |
* build a printf format string |
|
2246 |
*/ |
|
2247 |
fmtBuffer[0] = '%'; |
|
2248 |
strncpy(fmtBuffer+1, fmt, 10); |
|
2249 |
#ifdef SYSV |
|
2250 |
strcat(fmtBuffer, "lg"); |
|
2251 |
#else |
|
2252 |
strcat(fmtBuffer, "G"); |
|
2253 |
#endif |
|
314 | 2254 |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2255 |
__BEGIN_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2256 |
len = snprintf(buffer, sizeof(buffer), fmtBuffer, __floatVal(self)); |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2257 |
__END_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2258 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2259 |
if (len >= 0 && len < sizeof(buffer)-3) { |
18296 | 2260 |
/* |
2261 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
|
2262 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
|
2263 |
*/ |
|
2264 |
for (cp = buffer; *cp; cp++) { |
|
2265 |
if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break; |
|
2266 |
} |
|
2267 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
|
2268 |
if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
|
2269 |
*cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
|
2270 |
} else { |
|
2271 |
*cp++ = '.'; |
|
2272 |
} |
|
2273 |
*cp++ = '0'; |
|
2274 |
*cp = '\0'; |
|
2275 |
} else { |
|
2276 |
if (cp && ((*cp == '.') || (*cp == ','))) { |
|
2277 |
if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
|
2278 |
*cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
|
2279 |
} |
|
2280 |
} |
|
2281 |
} |
|
2282 |
||
2283 |
s = __MKSTRING(buffer); |
|
2284 |
if (s != nil) { |
|
2285 |
RETURN (s); |
|
2286 |
} |
|
314 | 2287 |
} |
2288 |
%}. |
|
2289 |
" |
|
2290 |
memory allocation (for the new string) failed. |
|
2291 |
When we arrive here, there was no memory, even after a garbage collect. |
|
2292 |
This means, that the VM wanted to get some more memory from the |
|
2293 |
OS, which was not kind enough to give it. |
|
2294 |
Bad luck - you should increase the swap space on your machine. |
|
2295 |
" |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20415
diff
changeset
|
2296 |
^ AllocationFailure raise. |
314 | 2297 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2298 |
" |
18296 | 2299 |
1.0 printString |
2300 |
1.234 printString |
|
2301 |
1e10 printString |
|
2302 |
1.2e3 printString |
|
2303 |
1.2e30 printString |
|
2304 |
(1.0 uncheckedDivide:0) printString |
|
2305 |
(0.0 uncheckedDivide:0) printString |
|
2306 |
self pi printString. |
|
2307 |
||
2308 |
DecimalPointCharacter := $,. |
|
2309 |
1.234 printString. |
|
2310 |
1.0 printString. |
|
2311 |
1e10 printString. |
|
2312 |
1.2e3 printString. |
|
2313 |
1.2e30 printString. |
|
2314 |
(1.0 uncheckedDivide:0) printString. |
|
2315 |
(0.0 uncheckedDivide:0) printString. |
|
2316 |
DecimalPointCharacter := $. |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2317 |
" |
1 | 2318 |
! |
2319 |
||
2320 |
printfPrintString:formatString |
|
24690 | 2321 |
<unsave> |
2322 |
||
7746 | 2323 |
"non-standard: return a printed representation of the receiver |
1 | 2324 |
as specified by formatString, which is defined by printf. |
22578 | 2325 |
|
31 | 2326 |
If you use this, be aware, that specifying doubles differs on |
11945 | 2327 |
systems; on SYSV machines you have to give something like %lf, |
13 | 2328 |
while on BSD systems the format string has to be %F. |
31 | 2329 |
Also, the resulting string may not be longer than 255 bytes - |
20415 | 2330 |
since that's the (static) size of the buffer. |
21909 | 2331 |
|
11926
295e8bb99fde
changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents:
11733
diff
changeset
|
2332 |
This method is NONSTANDARD and may be removed without notice. |
24690 | 2333 |
|
2334 |
WARNING: this goes directly to the C-printf function and may therefore me inherently unsafe. |
|
11926
295e8bb99fde
changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents:
11733
diff
changeset
|
2335 |
Please use the printf: method, which is safe as it is completely implemented in Smalltalk." |
1 | 2336 |
|
24690 | 2337 |
%{ /* STACK: 8000 */ |
2338 |
#ifndef __SCHTEAM__ |
|
1 | 2339 |
char buffer[256]; |
314 | 2340 |
OBJ s; |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2341 |
int len; |
1 | 2342 |
|
12478
e8051030cda6
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12423
diff
changeset
|
2343 |
if (__isStringLike(formatString)) { |
24690 | 2344 |
/* |
2345 |
* actually only needed on sparc: since thisContext is |
|
2346 |
* in a global register, which gets destroyed by printf, |
|
2347 |
* manually save it here - very stupid ... |
|
2348 |
*/ |
|
2349 |
__BEGIN_PROTECT_REGISTERS__ |
|
2350 |
||
2351 |
len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __floatVal(self)); |
|
2352 |
||
2353 |
__END_PROTECT_REGISTERS__ |
|
2354 |
||
2355 |
if (len < 0) goto fail; |
|
2356 |
if (len >= sizeof(buffer)) goto fail; |
|
2357 |
||
2358 |
s = __MKSTRING_L(buffer, len); |
|
2359 |
if (s != nil) { |
|
2360 |
RETURN (s); |
|
2361 |
} |
|
1 | 2362 |
} |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2363 |
fail: ; |
24690 | 2364 |
#endif /* not __SCHTEAM__ */ |
314 | 2365 |
%}. |
21909 | 2366 |
^ super printfPrintString:formatString |
1 | 2367 |
|
7355 | 2368 |
" |
2369 |
Float pi printfPrintString:'%%lg -> %lg' |
|
2370 |
Float pi printfPrintString:'%%lf -> %lf' |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2371 |
Float pi printfPrintString:'%%7.15lg -> %7.15lg' |
7355 | 2372 |
Float pi printfPrintString:'%%7.5lf -> %7.5lf' |
2373 |
Float pi printfPrintString:'%%G -> %G' |
|
2374 |
Float pi printfPrintString:'%%F -> %F' |
|
2375 |
Float pi printfPrintString:'%%7.5G -> %7.5G' |
|
2376 |
Float pi printfPrintString:'%%7.5F -> %7.5F' |
|
22578 | 2377 |
|
21952 | 2378 |
Float pi printfPrintString:'%%7.5f -> %7.5f' |
2379 |
Float pi printfPrintString:'%%100.98f -> %100.98f' |
|
2380 |
Float pi printfPrintString:'%%100.6f -> %100.6f' |
|
2381 |
Float pi printfPrintString:'%%300.6f -> %300.6f' |
|
22578 | 2382 |
|
21952 | 2383 |
Float pi printfPrintString:'%%-100.98f -> %-100.98f' |
2384 |
Float pi printfPrintString:'%%300.298f -> %300.298f' |
|
2385 |
Float pi printfPrintString:'%%-300.298f -> %-300.298f' |
|
2386 |
||
2387 |
Float pi printfPrintString:'%%100.6f -> <%100.6f>' |
|
2388 |
Float pi printfPrintString:'%%300.6f -> <%300.6f>' |
|
2389 |
||
2390 |
Float pi printfPrintString:'%%100.6f -> <%100.6>' |
|
2391 |
Float pi printfPrintString:'%%300.6f -> <%300.6>' |
|
7355 | 2392 |
" |
21909 | 2393 |
|
21952 | 2394 |
"Modified (comment): / 03-07-2017 / 15:11:13 / cg" |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2395 |
! |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2396 |
|
22301 | 2397 |
storeOn:aStream |
2398 |
"append a printed representation of the receiver to |
|
2399 |
the argument, aStream. |
|
2400 |
||
2401 |
I use #storeString instead of #storeOn: as basic store mechanism." |
|
2402 |
||
2403 |
aStream nextPutAll:self storeString |
|
2404 |
||
2405 |
"Created: / 10-10-2017 / 14:06:39 / cg" |
|
2406 |
! |
|
2407 |
||
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2408 |
storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2409 |
"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
|
2410 |
all valid digits are printed. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2411 |
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
|
2412 |
#storeOn: as basic print mechanism." |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2413 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2414 |
%{ /* NOCONTEXT */ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2415 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2416 |
char buffer[64]; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2417 |
REGISTER char *cp; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2418 |
OBJ s; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2419 |
int len; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2420 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2421 |
__BEGIN_PROTECT_REGISTERS__ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2422 |
#ifdef SYSV |
16658 | 2423 |
len = snprintf(buffer, sizeof(buffer), "%.17lg", __floatVal(self)); |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2424 |
#else |
16658 | 2425 |
len = snprintf(buffer, sizeof(buffer), "%.17G", __floatVal(self)); |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2426 |
#endif |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2427 |
__END_PROTECT_REGISTERS__ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2428 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2429 |
if (len >= 0 && len < sizeof(buffer)-3) { |
17199 | 2430 |
/* |
2431 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
|
2432 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
|
2433 |
*/ |
|
2434 |
for (cp = buffer; *cp; cp++) { |
|
2435 |
if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break; |
|
2436 |
} |
|
2437 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
|
2438 |
*cp++ = '.'; |
|
2439 |
*cp++ = '0'; |
|
2440 |
*cp = '\0'; |
|
2441 |
} |
|
2442 |
||
2443 |
s = __MKSTRING(buffer); |
|
2444 |
if (s != nil) { |
|
2445 |
RETURN (s); |
|
2446 |
} |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2447 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2448 |
%}. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2449 |
" |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2450 |
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
|
2451 |
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
|
2452 |
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
|
2453 |
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
|
2454 |
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
|
2455 |
" |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20415
diff
changeset
|
2456 |
^ AllocationFailure raise. |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2457 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2458 |
" |
17199 | 2459 |
1.0 storeString |
2460 |
0.1 storeString |
|
2461 |
((Array new:10 withAll:0.1) inject:0 into:[:v :sumSoFar| sumSoFar + v]) storeString |
|
2462 |
1.234 storeString |
|
2463 |
1e10 storeString |
|
2464 |
1.2e3 storeString |
|
2465 |
1.2e30 storeString |
|
2466 |
Float pi storeString |
|
2467 |
(1.0 uncheckedDivide:0) storeString |
|
2468 |
(0.0 uncheckedDivide:0) storeString |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2469 |
|
9124 | 2470 |
notice that the storeString is NOT affected by DecimalPointCharacterForPrinting: |
2471 |
||
17199 | 2472 |
DecimalPointCharacterForPrinting := $,. |
2473 |
1.234 storeString. |
|
2474 |
1.0 storeString. |
|
2475 |
1e10 storeString. |
|
2476 |
1.2e3 storeString. |
|
2477 |
1.2e30 storeString. |
|
2478 |
(1.0 uncheckedDivide:0) storeString. |
|
2479 |
(0.0 uncheckedDivide:0) storeString. |
|
2480 |
DecimalPointCharacterForPrinting := $. |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2481 |
" |
1 | 2482 |
! ! |
701 | 2483 |
|
11926
295e8bb99fde
changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents:
11733
diff
changeset
|
2484 |
|
7258 | 2485 |
!Float methodsFor:'private-accessing'! |
701 | 2486 |
|
2487 |
basicAt:index |
|
2488 |
"return an internal byte of the float. |
|
2489 |
The value returned here depends on byte order, float representation etc. |
|
2490 |
Therefore, this method should be used strictly private. |
|
2491 |
||
11945 | 2492 |
Notice: |
2493 |
the need to redefine this method here is due to the |
|
2494 |
inability of many machines to store floats in non-double aligned memory. |
|
2495 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
2496 |
and the actual float is stored at index 5 .. 12. |
|
2497 |
To hide this at one place, this method knows about that, and returns |
|
2498 |
values as if this filler wasnt present." |
|
701 | 2499 |
|
2500 |
%{ /* NOCONTEXT */ |
|
2501 |
||
2502 |
register int indx; |
|
2503 |
unsigned char *cp; |
|
2504 |
||
2505 |
/* |
|
2506 |
* notice the missing test for self being a nonNilObject - |
|
2507 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
2508 |
* and SmallInteger |
|
2509 |
*/ |
|
2510 |
if (__isSmallInteger(index)) { |
|
11945 | 2511 |
indx = __intVal(index) - 1; |
2512 |
if (((unsigned)(indx)) < sizeof(double)) { |
|
2513 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
|
2514 |
RETURN ( __mkSmallInteger(cp[indx] & 0xFF) ); |
|
2515 |
} |
|
701 | 2516 |
} |
2517 |
%}. |
|
7217 | 2518 |
^ self indexNotIntegerOrOutOfBounds:index |
701 | 2519 |
! |
2520 |
||
2521 |
basicAt:index put:value |
|
2522 |
"set an internal byte of the float. |
|
2523 |
The value to be stored here depends on byte order, float representation etc. |
|
2524 |
Therefore, this method should be used strictly private. |
|
2525 |
||
11945 | 2526 |
Notice: |
2527 |
the need to redefine this method here is due to the |
|
2528 |
inability of many machines to store floats in non-double aligned memory. |
|
2529 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
2530 |
and the actual float is stored at index 5 .. 12. |
|
2531 |
To hide this at one place, this method knows about that, and returns |
|
2532 |
values as if this filler wasnt present." |
|
701 | 2533 |
|
2534 |
%{ /* NOCONTEXT */ |
|
2535 |
register int indx, val; |
|
2536 |
unsigned char *cp; |
|
2537 |
||
2538 |
/* |
|
2539 |
* notice the missing test for self being a nonNilObject - |
|
2540 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
2541 |
* and SmallInteger |
|
2542 |
*/ |
|
2543 |
if (__bothSmallInteger(index, value)) { |
|
11945 | 2544 |
val = __intVal(value); |
2545 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
2546 |
indx = __intVal(index) - 1; |
|
2547 |
if (((unsigned)(indx)) < sizeof(double)) { |
|
2548 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
|
2549 |
cp[indx] = val; |
|
2550 |
RETURN ( value ); |
|
2551 |
} |
|
2552 |
} |
|
701 | 2553 |
} |
2554 |
%}. |
|
2555 |
value isInteger ifFalse:[ |
|
11945 | 2556 |
" |
2557 |
the object to store should be an integer number |
|
2558 |
" |
|
2559 |
^ self elementNotInteger |
|
701 | 2560 |
]. |
2561 |
(value between:0 and:255) ifFalse:[ |
|
11945 | 2562 |
" |
2563 |
the object to store must be a bytes value |
|
2564 |
" |
|
2565 |
^ self elementBoundsError:value |
|
701 | 2566 |
]. |
7217 | 2567 |
^ self indexNotIntegerOrOutOfBounds:index |
16658 | 2568 |
! |
4592 | 2569 |
|
2570 |
basicSize |
|
2571 |
"return the size in bytes of the float. |
|
2572 |
||
11945 | 2573 |
Notice: |
17199 | 2574 |
the need to redefine this method here is due to the |
2575 |
inability of many machines to store floats in non-double aligned memory. |
|
2576 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
2577 |
and the actual float is stored at index 5 .. 12. |
|
2578 |
To hide this at one place, this method knows about that, and returns |
|
2579 |
values as if this filler wasn't present." |
|
4592 | 2580 |
|
2581 |
%{ /* NOCONTEXT */ |
|
2582 |
||
8913 | 2583 |
RETURN (__mkSmallInteger(sizeof(double))); |
4592 | 2584 |
%}. |
22260 | 2585 |
! |
2586 |
||
2587 |
byteAt:index |
|
2588 |
^ self basicAt:index |
|
2589 |
! |
|
2590 |
||
2591 |
byteAt:index put:newByte |
|
2592 |
self shouldNotImplement |
|
701 | 2593 |
! ! |
2594 |
||
16658 | 2595 |
!Float methodsFor:'queries'! |
2596 |
||
2597 |
nextFloat:count |
|
2598 |
"answer the next float count places after (or before if count is negative) myself" |
|
2599 |
||
2600 |
%{ |
|
2601 |
union { |
|
17199 | 2602 |
double d; |
2603 |
INT64 i; |
|
16658 | 2604 |
} this; |
2605 |
||
2606 |
if (__isSmallInteger(count)) { |
|
17199 | 2607 |
this.d = __floatVal(self); |
2608 |
if (isfinite(this.d)) |
|
2609 |
this.i += __intVal(count); |
|
2610 |
||
2611 |
RETURN(__MKFLOAT(this.d)); |
|
16658 | 2612 |
} |
2613 |
%}. |
|
2614 |
self primitiveFailed:#badArgument |
|
2615 |
||
2616 |
" |
|
2617 |
(1.0 nextFloat:1) storeString |
|
2618 |
(67329.234 nextFloat:1) storeString |
|
2619 |
(67329.234 asShortFloat nextFloat:1) storeString |
|
2620 |
Float NaN nextFloat:100000 |
|
2621 |
Float infinity nextFloat:100000 |
|
2622 |
" |
|
2623 |
! ! |
|
2624 |
||
3896 | 2625 |
!Float methodsFor:'special access'! |
2626 |
||
2627 |
exponent |
|
21849 | 2628 |
"extract a normalized float's exponent. |
3896 | 2629 |
The returned value depends on the float-representation of |
2630 |
the underlying machine and is therefore highly unportable. |
|
2631 |
This is not for general use. |
|
2632 |
This assumes that the mantissa is normalized to |
|
12423 | 2633 |
0.5 .. 1.0 and the float's value is: mantissa * 2^exp" |
3896 | 2634 |
|
2635 |
%{ /* NOCONTEXT */ |
|
21849 | 2636 |
double myVal; |
3896 | 2637 |
double frac; |
8913 | 2638 |
int exp; |
3896 | 2639 |
|
21849 | 2640 |
myVal = __floatVal(self); |
2641 |
// ouch: math libs seem to not care for NaN here; |
|
2642 |
#if 1 |
|
2643 |
// should we? |
|
2644 |
if (! (isnan(myVal) || isinf(myVal))) |
|
2645 |
#endif |
|
2646 |
{ |
|
21868 | 2647 |
frac = frexp(myVal, &exp); |
2648 |
RETURN (__mkSmallInteger(exp)); |
|
21849 | 2649 |
} |
3896 | 2650 |
%}. |
21849 | 2651 |
^ super exponent |
3896 | 2652 |
|
2653 |
" |
|
14672
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2654 |
1.0 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2655 |
2.0 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2656 |
3.0 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2657 |
4.0 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2658 |
0.5 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2659 |
0.4 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2660 |
0.25 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2661 |
0.2 exponent |
11945 | 2662 |
0.00000011111 exponent |
21849 | 2663 |
0.0 exponent |
2664 |
1e1000 exponent |
|
3896 | 2665 |
" |
21849 | 2666 |
|
2667 |
"Modified: / 20-06-2017 / 11:34:43 / cg" |
|
3896 | 2668 |
! |
2669 |
||
2670 |
mantissa |
|
24152 | 2671 |
"extract a normalized float's mantissa. |
3896 | 2672 |
The returned value depends on the float-representation of |
2673 |
the underlying machine and is therefore highly unportable. |
|
2674 |
This is not for general use. |
|
2675 |
This assumes that the mantissa is normalized to |
|
24152 | 2676 |
0.5 .. 1.0 and the float's value is mantissa * 2^exp" |
3896 | 2677 |
|
2678 |
%{ /* NOCONTEXT */ |
|
21849 | 2679 |
double myVal; |
3896 | 2680 |
double frac; |
8913 | 2681 |
int exp; |
3896 | 2682 |
|
21849 | 2683 |
myVal = __floatVal(self); |
2684 |
// ouch: math libs seem to not care for NaN here; |
|
2685 |
#if 1 |
|
2686 |
// should we? |
|
2687 |
if (! (isnan(myVal) || isinf(myVal))) |
|
2688 |
#endif |
|
2689 |
{ |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
2690 |
frac = frexp(myVal, &exp); |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
2691 |
RETURN (__MKFLOAT(frac)); |
21868 | 2692 |
} |
3896 | 2693 |
%}. |
20009 | 2694 |
^ super mantissa |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20415
diff
changeset
|
2695 |
|
3896 | 2696 |
" |
11945 | 2697 |
1.0 exponent |
2698 |
1.0 mantissa |
|
2699 |
||
2700 |
0.25 exponent |
|
2701 |
0.25 mantissa |
|
2702 |
||
2703 |
0.00000011111 exponent |
|
2704 |
0.00000011111 mantissa |
|
21849 | 2705 |
|
2706 |
1e1000 mantissa |
|
3896 | 2707 |
" |
21849 | 2708 |
|
2709 |
"Modified: / 20-06-2017 / 11:37:13 / cg" |
|
24152 | 2710 |
"Modified (comment): / 26-05-2019 / 03:12:55 / Claus Gittinger" |
3896 | 2711 |
! ! |
2712 |
||
701 | 2713 |
!Float methodsFor:'testing'! |
2714 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2715 |
isFinite |
24710 | 2716 |
"return true, if the receiver is a finite float (not NaN and not +/-INF)" |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2717 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2718 |
%{ /* NOCONTEXT */ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2719 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
2720 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
2721 |
* notice: on machines which do not provide |
11945 | 2722 |
* a finite() macro or function (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
2723 |
* this may always ret true here ... |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
2724 |
*/ |
17384 | 2725 |
RETURN (isfinite(__floatVal(self)) ? true : false) |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2726 |
%}. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2727 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2728 |
" |
24696 | 2729 |
1.0 isFinite |
2730 |
1 isFinite |
|
2731 |
||
2732 |
Float NaN isFinite |
|
2733 |
Float infinity isFinite |
|
2734 |
Float negativeInfinity isFinite |
|
2735 |
(0.0 uncheckedDivide: 0.0) isFinite |
|
2736 |
(1.0 uncheckedDivide: 0.0) isFinite |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2737 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2738 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2739 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2740 |
isInfinite |
24710 | 2741 |
"return true, if the receiver is an infinite float (+Inf or -Inf). |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2742 |
These are not created by ST/X float operations (they raise an exception); |
24710 | 2743 |
however, inline C-code could produce them." |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2744 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2745 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2746 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2747 |
double dV = __floatVal(self); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2748 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
2749 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
2750 |
* notice: on machines which do not provide |
11945 | 2751 |
* finite() & isnan() macros or functions (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
2752 |
* this may always ret false here ... |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
2753 |
*/ |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2754 |
#if defined(isinf) |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2755 |
if (isinf(dV)) { RETURN (true); } |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2756 |
#else |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2757 |
if (!isfinite(dV) && !isnan(dV)) { RETURN (true); } |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2758 |
#endif |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2759 |
%}. |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2760 |
^ false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2761 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2762 |
" |
24710 | 2763 |
1.0 isInfinite |
2764 |
(0.0 uncheckedDivide: 0.0) isInfinite |
|
2765 |
(1.0 uncheckedDivide: 0.0) isInfinite |
|
2766 |
(-1.0 uncheckedDivide: 0.0) isInfinite |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2767 |
" |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2768 |
! |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2769 |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2770 |
isLiteral |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2771 |
"return true, if the receiver can be used as a literal constant in ST syntax |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2772 |
(i.e. can be used in constant arrays)" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2773 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2774 |
^ true |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2775 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2776 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2777 |
! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2778 |
|
2387 | 2779 |
isNaN |
2780 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
2781 |
These are not created by ST/X float operations (they raise an exception); |
|
24710 | 2782 |
however, inline C-code could produce them." |
2387 | 2783 |
|
2784 |
%{ /* NOCONTEXT */ |
|
2785 |
||
17384 | 2786 |
RETURN (isnan(__floatVal(self)) ? true : false) |
2392 | 2787 |
%}. |
3139 | 2788 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2789 |
" |
24710 | 2790 |
self NaN isNaN |
2791 |
1.0 isNaN |
|
2792 |
(0.0 uncheckedDivide: 0.0) isNaN |
|
2793 |
(1.0 uncheckedDivide: 0.0) isNaN |
|
2794 |
(-1.0 uncheckedDivide: 0.0) isNaN |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2795 |
" |
2387 | 2796 |
! |
2797 |
||
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2798 |
isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2799 |
"many systems have two float.Pnt zeros" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2800 |
|
18296 | 2801 |
%{ /* NOCONTEXT */ |
17389 | 2802 |
|
17392 | 2803 |
#if defined(__BORLANDC__) |
2804 |
union { double d; int i[2]; } __u; |
|
2805 |
__u.d = __floatVal(self); |
|
2806 |
RETURN ( (__u.d == 0.0 && __u.i[1] < 0) ? true : false ); |
|
17389 | 2807 |
#else |
17384 | 2808 |
RETURN ( (__floatVal(self) == 0.0 && signbit(__floatVal(self)) != 0) ? true : false ); |
17389 | 2809 |
#endif |
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2810 |
%}. |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2811 |
|
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2812 |
" |
11945 | 2813 |
0.0 isNegativeZero |
2814 |
-0.0 isNegativeZero |
|
2815 |
-1.0 isNegativeZero |
|
2816 |
1.0 isNegativeZero |
|
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2817 |
" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2818 |
! |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2819 |
|
24328 | 2820 |
isZero |
2821 |
"return true, if the receiver is zero" |
|
2822 |
||
2823 |
^ self = 0.0 |
|
2824 |
||
2825 |
"Created: / 10-06-2019 / 21:58:24 / Claus Gittinger" |
|
2826 |
! |
|
2827 |
||
701 | 2828 |
negative |
17384 | 2829 |
"return true if the receiver is less than zero. |
2830 |
-0.0 is positive for now." |
|
701 | 2831 |
|
2832 |
%{ /* NOCONTEXT */ |
|
2833 |
||
17384 | 2834 |
RETURN ( __floatVal(self) < 0.0 ? true : false ); |
2835 |
// RETURN ( signbit(__floatVal(self)) != 0 ? true : false ); |
|
5411 | 2836 |
%}. |
17384 | 2837 |
|
2838 |
" |
|
24696 | 2839 |
0.0 negative |
2840 |
-0.0 negative |
|
2841 |
1.0 negative |
|
2842 |
-1.0 negative |
|
2843 |
(1.0 uncheckedDivide: 0.0) negative |
|
2844 |
(-1.0 uncheckedDivide: 0.0) negative |
|
2845 |
||
2846 |
Float infinity negative |
|
2847 |
Float negativeInfinity negative |
|
2848 |
Float NaN negative |
|
2849 |
||
2850 |
Float infinity positive |
|
2851 |
Float negativeInfinity positive |
|
2852 |
Float NaN positive |
|
17384 | 2853 |
" |
701 | 2854 |
! |
2855 |
||
5357 | 2856 |
numberOfBits |
2857 |
"return the size (in bits) of the real; |
|
2858 |
typically, 64 is returned here, |
|
2859 |
but who knows ..." |
|
2860 |
||
2861 |
%{ /* NOCONTEXT */ |
|
2862 |
||
8913 | 2863 |
RETURN (__mkSmallInteger (sizeof(double) * 8)); |
5357 | 2864 |
%} |
2865 |
||
2866 |
" |
|
11945 | 2867 |
1.2 numberOfBits |
2868 |
1.2 asShortFloat numberOfBits |
|
5357 | 2869 |
" |
2870 |
! |
|
2871 |
||
701 | 2872 |
positive |
18857 | 2873 |
"return true if the receiver is greater or equal to zero (not negative). |
17384 | 2874 |
0.0 and -0.0 are positive for now." |
701 | 2875 |
|
2876 |
%{ /* NOCONTEXT */ |
|
2877 |
||
17384 | 2878 |
RETURN ( __floatVal(self) >= 0.0 ? true : false ); |
2879 |
// RETURN ( signbit(__floatVal(self)) == 0 ? true : false ); |
|
2880 |
%}. |
|
2881 |
||
2882 |
" |
|
24696 | 2883 |
0.0 positive |
2884 |
-0.0 positive |
|
2885 |
1.0 positive |
|
2886 |
-1.0 positive |
|
2887 |
(1.0 uncheckedDivide: 0.0) positive |
|
2888 |
(-1.0 uncheckedDivide: 0.0) positive |
|
2889 |
||
2890 |
Float infinity positive |
|
2891 |
Float negativeInfinity positive |
|
2892 |
Float NaN positive |
|
2893 |
||
2894 |
Float infinity negative |
|
2895 |
Float negativeInfinity negative |
|
2896 |
Float NaN negative |
|
17384 | 2897 |
" |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2898 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2899 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2900 |
strictlyPositive |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2901 |
"return true if the receiver is greater than zero" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2902 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2903 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2904 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2905 |
RETURN ( (__floatVal(self) > 0.0) ? true : false ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2906 |
%} |
701 | 2907 |
! ! |
2908 |
||
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2909 |
!Float methodsFor:'tracing'! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2910 |
|
4682 | 2911 |
traceInto:aRequestor level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2912 |
"double dispatch into tracer, passing my type implicitely in the selector" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2913 |
|
4682 | 2914 |
^ aRequestor traceFloat:self level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2915 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2916 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2917 |
! ! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2918 |
|
7385 | 2919 |
!Float methodsFor:'trigonometric'! |
2920 |
||
2921 |
arcCos |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2922 |
"return the arccosine of the receiver (as radians). |
7385 | 2923 |
Raises an exception, if the receiver is not in -1..1" |
2924 |
||
2925 |
%{ /* NOCONTEXT */ |
|
18296 | 2926 |
#ifdef __SCHTEAM__ |
18299 | 2927 |
return context._RETURN( self.acos() ); |
18296 | 2928 |
#else |
7385 | 2929 |
|
2930 |
double val, rslt; |
|
2931 |
OBJ newFloat; |
|
2932 |
||
2933 |
val = __floatVal(self); |
|
2934 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
2935 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7385 | 2936 |
if ((val >= -1.0) && (val <= 1.0)) |
18296 | 2937 |
# endif |
7385 | 2938 |
{ |
11945 | 2939 |
__threadErrno = 0; |
2940 |
rslt = acos(val); |
|
2941 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2942 |
{ |
|
2943 |
if (__threadErrno == 0) { |
|
2944 |
__qMKFLOAT(newFloat, rslt); |
|
2945 |
RETURN ( newFloat ); |
|
2946 |
} |
|
2947 |
} |
|
7385 | 2948 |
} |
18296 | 2949 |
#endif |
7385 | 2950 |
%}. |
2951 |
^ self class |
|
11945 | 2952 |
raise:#domainErrorSignal |
2953 |
receiver:self |
|
2954 |
selector:#arcCos |
|
2955 |
arguments:#() |
|
2956 |
errorString:'bad receiver in arcCos' |
|
7385 | 2957 |
|
2958 |
" |
|
2959 |
-10 arcCos |
|
11945 | 2960 |
1 arcCos |
7385 | 2961 |
" |
2962 |
||
2963 |
"Modified: / 16.11.2001 / 14:14:13 / cg" |
|
2964 |
! |
|
2965 |
||
2966 |
arcCosh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2967 |
"return the hyperbolic arccosine of the receiver." |
7385 | 2968 |
|
7410 | 2969 |
|useFallBack| |
2970 |
||
2971 |
%{ |
|
2972 |
#ifdef NO_ACOSH |
|
2973 |
useFallBack = true; |
|
2974 |
#else |
|
7385 | 2975 |
double val, rslt; |
2976 |
OBJ newFloat; |
|
2977 |
||
2978 |
val = __floatVal(self); |
|
2979 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
2980 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2981 |
if (val >= 1.0) |
7410 | 2982 |
# endif |
7385 | 2983 |
{ |
11945 | 2984 |
__threadErrno = 0; |
2985 |
rslt = acosh(val); |
|
2986 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2987 |
{ |
|
2988 |
if (__threadErrno == 0) { |
|
2989 |
__qMKFLOAT(newFloat, rslt); |
|
2990 |
RETURN ( newFloat ); |
|
2991 |
} |
|
2992 |
} |
|
7385 | 2993 |
} |
7410 | 2994 |
#endif |
7385 | 2995 |
%}. |
7410 | 2996 |
useFallBack notNil ifTrue:[ |
2997 |
^ super arcCosh |
|
2998 |
]. |
|
2999 |
||
7385 | 3000 |
^ self class |
11945 | 3001 |
raise:#domainErrorSignal |
3002 |
receiver:self |
|
3003 |
selector:#arcCosh |
|
3004 |
arguments:#() |
|
3005 |
errorString:'bad receiver in arcCosh' |
|
7385 | 3006 |
|
3007 |
" |
|
3008 |
-10.0 arcCosh |
|
11945 | 3009 |
1.0 arcCosh |
7385 | 3010 |
" |
3011 |
||
3012 |
"Modified: / 16.11.2001 / 14:14:13 / cg" |
|
3013 |
! |
|
3014 |
||
3015 |
arcSin |
|
3016 |
"return the arcsine of myself (I am interpreted as radians). |
|
3017 |
Raises an exception, if the receiver is not in -1..1" |
|
3018 |
||
3019 |
%{ /* NOCONTEXT */ |
|
18296 | 3020 |
#ifdef __SCHTEAM__ |
18299 | 3021 |
return context._RETURN( self.asin() ); |
18296 | 3022 |
#else |
7385 | 3023 |
|
3024 |
double val, rslt; |
|
3025 |
OBJ newFloat; |
|
3026 |
||
3027 |
val = __floatVal(self); |
|
3028 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
3029 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7385 | 3030 |
if ((val >= -1.0) && (val <= 1.0)) |
18296 | 3031 |
# endif |
7385 | 3032 |
{ |
11945 | 3033 |
__threadErrno = 0; |
3034 |
rslt = asin(val); |
|
3035 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
3036 |
{ |
|
3037 |
if (__threadErrno == 0) { |
|
3038 |
__qMKFLOAT(newFloat, rslt); |
|
3039 |
RETURN ( newFloat ); |
|
3040 |
} |
|
3041 |
} |
|
7385 | 3042 |
} |
18296 | 3043 |
#endif |
7385 | 3044 |
%}. |
3045 |
^ self class |
|
11945 | 3046 |
raise:#domainErrorSignal |
3047 |
receiver:self |
|
3048 |
selector:#arcSin |
|
3049 |
arguments:#() |
|
3050 |
errorString:'bad receiver in arcSin' |
|
7385 | 3051 |
|
3052 |
" |
|
3053 |
-10 arcSin |
|
11945 | 3054 |
1 arcSin |
7385 | 3055 |
" |
3056 |
||
3057 |
"Modified: / 16.11.2001 / 14:14:18 / cg" |
|
3058 |
! |
|
3059 |
||
3060 |
arcSinh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3061 |
"return the hyperbolic arcsine of the receiver." |
7385 | 3062 |
|
7410 | 3063 |
|useFallBack| |
3064 |
%{ |
|
3065 |
#ifdef NO_ASINH |
|
3066 |
useFallBack = true; |
|
3067 |
#else |
|
7385 | 3068 |
double val, rslt; |
3069 |
OBJ newFloat; |
|
3070 |
||
3071 |
val = __floatVal(self); |
|
3072 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
3073 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3074 |
if (val >= 1.0) |
7410 | 3075 |
# endif |
7385 | 3076 |
{ |
11945 | 3077 |
__threadErrno = 0; |
3078 |
rslt = asinh(val); |
|
3079 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
3080 |
{ |
|
3081 |
if (__threadErrno == 0) { |
|
3082 |
__qMKFLOAT(newFloat, rslt); |
|
3083 |
RETURN ( newFloat ); |
|
3084 |
} |
|
3085 |
} |
|
7385 | 3086 |
} |
7410 | 3087 |
#endif |
7385 | 3088 |
%}. |
7410 | 3089 |
useFallBack notNil ifTrue:[ |
3090 |
^ super arcSinh |
|
3091 |
]. |
|
7385 | 3092 |
^ self class |
11945 | 3093 |
raise:#domainErrorSignal |
3094 |
receiver:self |
|
3095 |
selector:#arcSinh |
|
3096 |
arguments:#() |
|
3097 |
errorString:'bad receiver in arcSinh' |
|
7385 | 3098 |
|
3099 |
" |
|
3100 |
-10.0 arcSinh |
|
11945 | 3101 |
1.0 arcSinh |
7385 | 3102 |
" |
3103 |
! |
|
3104 |
||
3105 |
arcTan |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3106 |
"return the arctangent of the receiver (as radians)" |
7385 | 3107 |
|
3108 |
%{ /* NOCONTEXT */ |
|
18296 | 3109 |
#ifdef __SCHTEAM__ |
18299 | 3110 |
return context._RETURN( self.atan() ); |
18296 | 3111 |
#else |
7385 | 3112 |
|
3113 |
double rslt; |
|
3114 |
OBJ newFloat; |
|
3115 |
||
3116 |
__threadErrno = 0; |
|
3117 |
rslt = atan(__floatVal(self)); |
|
7393 | 3118 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3119 |
{ |
|
11945 | 3120 |
if (__threadErrno == 0) { |
3121 |
__qMKFLOAT(newFloat, rslt); |
|
3122 |
RETURN ( newFloat ); |
|
3123 |
} |
|
7385 | 3124 |
} |
18296 | 3125 |
#endif |
7385 | 3126 |
%}. |
3127 |
^ self class |
|
11945 | 3128 |
raise:#domainErrorSignal |
3129 |
receiver:self |
|
3130 |
selector:#arcTan |
|
3131 |
arguments:#() |
|
3132 |
errorString:'bad receiver in arcTan' |
|
7385 | 3133 |
|
3134 |
"Modified: / 16.11.2001 / 14:14:22 / cg" |
|
3135 |
! |
|
3136 |
||
11487 | 3137 |
arcTan2:x |
3138 |
"return the atan2(self,x)" |
|
3139 |
||
3140 |
%{ /* NOCONTEXT */ |
|
3141 |
||
3142 |
double rslt; |
|
3143 |
OBJ newFloat; |
|
3144 |
||
3145 |
if (__isFloat(x)) { |
|
11945 | 3146 |
__threadErrno = 0; |
3147 |
rslt = atan2(__floatVal(self),__floatVal(x)); |
|
3148 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
3149 |
{ |
|
3150 |
if (__threadErrno == 0) { |
|
3151 |
__qMKFLOAT(newFloat, rslt); |
|
3152 |
RETURN ( newFloat ); |
|
3153 |
} |
|
3154 |
} |
|
11487 | 3155 |
} |
3156 |
%}. |
|
3157 |
x isFloat ifFalse:[ |
|
11945 | 3158 |
^ self arcTan2:(x asFloat). |
11487 | 3159 |
]. |
3160 |
||
3161 |
^ self class |
|
11945 | 3162 |
raise:#domainErrorSignal |
3163 |
receiver:self |
|
3164 |
selector:#arcTan2: |
|
3165 |
arguments:(Array with:x) |
|
3166 |
errorString:'bad receiver in arcTan2:' |
|
11487 | 3167 |
! |
3168 |
||
10604 | 3169 |
arcTan: denominator |
22728 | 3170 |
"Evaluate the four quadrant arc tangent of the argument denominator (x) and the receiver (y)." |
3171 |
||
11945 | 3172 |
(self = 0.0) ifTrue: [ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3173 |
(denominator > 0.0) |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3174 |
ifTrue: [ ^ 0 ] |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3175 |
ifFalse: [ ^ Pi ] |
10604 | 3176 |
]. |
11945 | 3177 |
(denominator = 0.0) ifTrue: [ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3178 |
(self > 0.0) |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3179 |
ifTrue: [ ^ Halfpi ] |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3180 |
ifFalse: [ ^ HalfpiNegative ] |
10604 | 3181 |
]. |
11945 | 3182 |
(denominator > 0) |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3183 |
ifTrue: [ ^ (self / denominator) arcTan ] |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3184 |
ifFalse: [ ^ ((self / denominator) arcTan) + Pi ] |
10604 | 3185 |
|
3186 |
"Created: / 07-06-2007 / 21:10:32 / cg" |
|
3187 |
"Modified: / 11-06-2007 / 12:58:34 / cg" |
|
3188 |
! |
|
3189 |
||
7385 | 3190 |
arcTanh |
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3191 |
"return the hyperbolic arctangent of the receiver." |
7385 | 3192 |
|
7410 | 3193 |
|useFallBack| |
3194 |
%{ |
|
3195 |
#ifdef NO_ATANH |
|
3196 |
useFallBack = true; |
|
3197 |
#else |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3198 |
double val, rslt; |
7385 | 3199 |
OBJ newFloat; |
3200 |
||
3201 |
__threadErrno = 0; |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3202 |
val = __floatVal(self); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
3203 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3204 |
if ((val >= -1.0) && (val <= 1.0)) |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3205 |
# endif |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3206 |
{ |
22578 | 3207 |
rslt = atanh(val); |
3208 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
3209 |
# ifdef __osx__ |
22578 | 3210 |
if (! isinf(rslt)) |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
3211 |
# endif |
22578 | 3212 |
{ |
3213 |
if (__threadErrno == 0) { |
|
3214 |
__qMKFLOAT(newFloat, rslt); |
|
3215 |
RETURN ( newFloat ); |
|
3216 |
} |
|
3217 |
} |
|
7385 | 3218 |
} |
7410 | 3219 |
#endif |
7385 | 3220 |
%}. |
7410 | 3221 |
useFallBack notNil ifTrue:[ |
22578 | 3222 |
^ super arcTanh |
7410 | 3223 |
]. |
7385 | 3224 |
^ self class |
22578 | 3225 |
raise:#domainErrorSignal |
3226 |
receiver:self |
|
3227 |
selector:#arcTanh |
|
3228 |
arguments:#() |
|
3229 |
errorString:'bad receiver in arcTanh' |
|
7385 | 3230 |
! |
3231 |
||
3232 |
cos |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3233 |
"return the cosine of the receiver (interpreted as radians)" |
7385 | 3234 |
|
3235 |
%{ /* NOCONTEXT */ |
|
18296 | 3236 |
#ifdef __SCHTEAM__ |
18299 | 3237 |
return context._RETURN( self.cos() ); |
18296 | 3238 |
#else |
7385 | 3239 |
|
3240 |
double rslt; |
|
3241 |
OBJ newFloat; |
|
3242 |
||
3243 |
__threadErrno = 0; |
|
3244 |
rslt = cos(__floatVal(self)); |
|
7393 | 3245 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3246 |
{ |
|
11945 | 3247 |
if (__threadErrno == 0) { |
3248 |
__qMKFLOAT(newFloat, rslt); |
|
3249 |
RETURN ( newFloat ); |
|
3250 |
} |
|
7385 | 3251 |
} |
18296 | 3252 |
#endif |
7385 | 3253 |
%}. |
3254 |
^ self class |
|
11945 | 3255 |
raise:#domainErrorSignal |
3256 |
receiver:self |
|
3257 |
selector:#cos |
|
3258 |
arguments:#() |
|
3259 |
errorString:'bad receiver in cos' |
|
7385 | 3260 |
|
3261 |
"Modified: / 16.11.2001 / 14:14:26 / cg" |
|
3262 |
! |
|
3263 |
||
3264 |
cosh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3265 |
"return the hyperbolic cosine of the receiver" |
7385 | 3266 |
|
3267 |
%{ /* NOCONTEXT */ |
|
18296 | 3268 |
#ifdef __SCHTEAM__ |
18299 | 3269 |
return context._RETURN( self.cosh() ); |
18296 | 3270 |
#else |
7385 | 3271 |
|
3272 |
double rslt; |
|
3273 |
OBJ newFloat; |
|
3274 |
||
3275 |
__threadErrno = 0; |
|
3276 |
rslt = cosh(__floatVal(self)); |
|
7393 | 3277 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3278 |
{ |
|
11945 | 3279 |
if (__threadErrno == 0) { |
3280 |
__qMKFLOAT(newFloat, rslt); |
|
3281 |
RETURN ( newFloat ); |
|
3282 |
} |
|
7385 | 3283 |
} |
18296 | 3284 |
#endif |
7385 | 3285 |
%}. |
3286 |
^ self class |
|
11945 | 3287 |
raise:#domainErrorSignal |
3288 |
receiver:self |
|
3289 |
selector:#cosh |
|
3290 |
arguments:#() |
|
3291 |
errorString:'bad receiver in cosh' |
|
7385 | 3292 |
! |
3293 |
||
3294 |
sin |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3295 |
"return the sine of the receiver (interpreted as radians)" |
7385 | 3296 |
|
3297 |
%{ /* NOCONTEXT */ |
|
18296 | 3298 |
#ifdef __SCHTEAM__ |
18299 | 3299 |
return context._RETURN( self.sin() ); |
18296 | 3300 |
#else |
7385 | 3301 |
|
3302 |
double rslt; |
|
3303 |
OBJ newFloat; |
|
3304 |
||
3305 |
__threadErrno = 0; |
|
3306 |
rslt = sin(__floatVal(self)); |
|
7393 | 3307 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3308 |
{ |
|
11945 | 3309 |
if (__threadErrno == 0) { |
3310 |
__qMKFLOAT(newFloat, rslt); |
|
3311 |
RETURN ( newFloat ); |
|
3312 |
} |
|
7385 | 3313 |
} |
18296 | 3314 |
#endif |
7385 | 3315 |
%}. |
3316 |
^ self class |
|
11945 | 3317 |
raise:#domainErrorSignal |
3318 |
receiver:self |
|
3319 |
selector:#sin |
|
3320 |
arguments:#() |
|
3321 |
errorString:'bad receiver in sin' |
|
7385 | 3322 |
|
3323 |
"Modified: / 16.11.2001 / 14:14:37 / cg" |
|
3324 |
! |
|
3325 |
||
3326 |
sinh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3327 |
"return the hyperbolic sine of the receiver" |
7385 | 3328 |
|
3329 |
%{ /* NOCONTEXT */ |
|
18296 | 3330 |
#ifdef __SCHTEAM__ |
18299 | 3331 |
return context._RETURN( self.sinh() ); |
18296 | 3332 |
#else |
7385 | 3333 |
|
3334 |
double rslt; |
|
3335 |
OBJ newFloat; |
|
3336 |
||
3337 |
__threadErrno = 0; |
|
3338 |
rslt = sinh(__floatVal(self)); |
|
7393 | 3339 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3340 |
{ |
|
11945 | 3341 |
if (__threadErrno == 0) { |
3342 |
__qMKFLOAT(newFloat, rslt); |
|
3343 |
RETURN ( newFloat ); |
|
3344 |
} |
|
7385 | 3345 |
} |
18296 | 3346 |
#endif |
7385 | 3347 |
%}. |
3348 |
^ self class |
|
11945 | 3349 |
raise:#domainErrorSignal |
3350 |
receiver:self |
|
3351 |
selector:#sinh |
|
3352 |
arguments:#() |
|
3353 |
errorString:'bad receiver in sinh' |
|
7385 | 3354 |
! |
3355 |
||
3356 |
tan |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3357 |
"return the tangens of the receiver (interpreted as radians)" |
7385 | 3358 |
|
3359 |
%{ /* NOCONTEXT */ |
|
18296 | 3360 |
#ifdef __SCHTEAM__ |
18299 | 3361 |
return context._RETURN( self.tan() ); |
18296 | 3362 |
#else |
7385 | 3363 |
|
3364 |
double rslt; |
|
3365 |
OBJ newFloat; |
|
3366 |
||
3367 |
__threadErrno = 0; |
|
3368 |
rslt = tan(__floatVal(self)); |
|
7393 | 3369 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3370 |
{ |
|
11945 | 3371 |
if (__threadErrno == 0) { |
3372 |
__qMKFLOAT(newFloat, rslt); |
|
3373 |
RETURN ( newFloat ); |
|
3374 |
} |
|
7385 | 3375 |
} |
18296 | 3376 |
#endif |
7385 | 3377 |
%}. |
3378 |
^ self class |
|
11945 | 3379 |
raise:#domainErrorSignal |
3380 |
receiver:self |
|
3381 |
selector:#tan |
|
3382 |
arguments:#() |
|
3383 |
errorString:'bad receiver in tan' |
|
7385 | 3384 |
|
3385 |
"Modified: / 16.11.2001 / 14:14:49 / cg" |
|
3386 |
! |
|
3387 |
||
3388 |
tanh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3389 |
"return the hyperbolic tangens of the receiver" |
7385 | 3390 |
|
3391 |
%{ /* NOCONTEXT */ |
|
3392 |
||
3393 |
double rslt; |
|
3394 |
OBJ newFloat; |
|
3395 |
||
3396 |
__threadErrno = 0; |
|
3397 |
rslt = tanh(__floatVal(self)); |
|
7393 | 3398 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3399 |
{ |
|
11945 | 3400 |
if (__threadErrno == 0) { |
3401 |
__qMKFLOAT(newFloat, rslt); |
|
3402 |
RETURN ( newFloat ); |
|
3403 |
} |
|
7385 | 3404 |
} |
3405 |
%}. |
|
3406 |
^ self class |
|
11945 | 3407 |
raise:#domainErrorSignal |
3408 |
receiver:self |
|
3409 |
selector:#tanh |
|
3410 |
arguments:#() |
|
3411 |
errorString:'bad receiver in tanh' |
|
7385 | 3412 |
! ! |
3413 |
||
5552 | 3414 |
!Float methodsFor:'truncation & rounding'! |
701 | 3415 |
|
3416 |
ceiling |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3417 |
"return the smallest integer which is greater or equal to the receiver." |
701 | 3418 |
|
3419 |
|val| |
|
3420 |
||
3421 |
%{ |
|
18296 | 3422 |
#ifdef __SCHTEAM__ |
3423 |
ERROR("unimplemented"); |
|
3424 |
#else |
|
701 | 3425 |
double dVal; |
3426 |
||
7355 | 3427 |
dVal = ceil(__floatVal(self)); |
701 | 3428 |
/* |
3429 |
* ST-80 (and X3J20) returns integer. |
|
3430 |
*/ |
|
3431 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
11945 | 3432 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 3433 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3434 |
__qMKFLOAT(val, dVal); |
18296 | 3435 |
#endif |
701 | 3436 |
%}. |
3437 |
^ val asInteger |
|
3438 |
! |
|
3439 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3440 |
ceilingAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3441 |
"return the smallest integer-valued float greater or equal to the receiver. |
11945 | 3442 |
This is much like #ceiling, but avoids a (possibly expensive) conversion |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3443 |
of the result to an integer. |
7355 | 3444 |
It may be useful, if the result is to be further used in another float-operation." |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3445 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3446 |
%{ /* NOCONTEXT */ |
18296 | 3447 |
#ifdef __SCHTEAM__ |
18299 | 3448 |
return context._RETURN( self.ceiling() ); |
18296 | 3449 |
#else |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3450 |
double dVal; |
7355 | 3451 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3452 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3453 |
dVal = ceil(__floatVal(self)); |
7355 | 3454 |
__qMKFLOAT(v, dVal); |
3455 |
RETURN (v); |
|
18296 | 3456 |
#endif |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3457 |
%} |
7355 | 3458 |
" |
11945 | 3459 |
0.5 ceilingAsFloat |
3460 |
-0.5 ceilingAsFloat |
|
3461 |
-1.5 ceilingAsFloat |
|
7355 | 3462 |
" |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3463 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3464 |
|
701 | 3465 |
floor |
3466 |
"return the integer nearest the receiver towards negative infinity." |
|
3467 |
||
3468 |
|val| |
|
3469 |
||
3470 |
%{ |
|
18296 | 3471 |
#ifdef __SCHTEAM__ |
3472 |
ERROR("unimplemented"); |
|
3473 |
#else |
|
701 | 3474 |
double dVal; |
3475 |
||
7355 | 3476 |
dVal = floor(__floatVal(self)); |
701 | 3477 |
/* |
3478 |
* ST-80 (and X3J20) returns integer. |
|
3479 |
*/ |
|
3480 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
11945 | 3481 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 3482 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3483 |
__qMKFLOAT(val, dVal); |
18296 | 3484 |
#endif |
701 | 3485 |
%}. |
3486 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3487 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3488 |
" |
11945 | 3489 |
0.5 floor |
3490 |
0.5 floorAsFloat |
|
3491 |
-0.5 floor |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3492 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3493 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3494 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3495 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3496 |
floorAsFloat |
7355 | 3497 |
"return the integer nearest the receiver towards negative infinity as a float. |
11945 | 3498 |
This is much like #floor, but avoids a (possibly expensive) conversion |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3499 |
of the result to an integer. |
7355 | 3500 |
It may be useful, if the result is to be further used in another float-operation." |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3501 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3502 |
%{ /* NOCONTEXT */ |
18296 | 3503 |
#ifdef __SCHTEAM__ |
18299 | 3504 |
return context._RETURN( self.floor() ); |
18296 | 3505 |
#else |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3506 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3507 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3508 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3509 |
dVal = floor(__floatVal(self)); |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3510 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3511 |
RETURN (v); |
18296 | 3512 |
#endif |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3513 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3514 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3515 |
" |
11945 | 3516 |
0.5 floor |
3517 |
0.5 floorAsFloat |
|
3518 |
-0.5 floor |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3519 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3520 |
" |
701 | 3521 |
! |
3522 |
||
3896 | 3523 |
fractionPart |
3524 |
"extract the after-decimal fraction part. |
|
7355 | 3525 |
such that (self truncated + self fractionPart) = self" |
3896 | 3526 |
|
3527 |
%{ /* NOCONTEXT */ |
|
3528 |
||
14728 | 3529 |
double modf(double, double*); |
3896 | 3530 |
double frac, trunc; |
3531 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
3532 |
__threadErrno = 0; |
3896 | 3533 |
frac = modf(__floatVal(self), &trunc); |
11945 | 3534 |
if (! isnan(frac)) { |
3535 |
if (__threadErrno == 0) { |
|
3536 |
RETURN (__MKFLOAT(frac)); |
|
3537 |
} |
|
3896 | 3538 |
} |
3539 |
%}. |
|
7403 | 3540 |
^ self class |
11945 | 3541 |
raise:#domainErrorSignal |
3542 |
receiver:self |
|
3543 |
selector:#fractionPart |
|
3544 |
arguments:#() |
|
3545 |
errorString:'bad receiver in fractionPart' |
|
3896 | 3546 |
|
3547 |
" |
|
11945 | 3548 |
1.6 fractionPart + 1.6 truncated |
3549 |
-1.6 fractionPart + -1.6 truncated |
|
3550 |
||
3551 |
1.0 fractionPart |
|
3552 |
2.0 fractionPart |
|
3553 |
3.0 fractionPart |
|
3554 |
4.0 fractionPart |
|
3555 |
0.5 fractionPart |
|
3556 |
0.25 fractionPart |
|
3557 |
3.14159 fractionPart |
|
3558 |
12345673.14159 fractionPart |
|
3559 |
123456731231231231.14159 fractionPart |
|
3560 |
||
3561 |
3.14159 fractionPart + 3.14159 truncated |
|
3562 |
||
3563 |
12345673.14159 fractionPart + 12345673.14159 truncated |
|
3564 |
||
3565 |
123456731231231231.14159 fractionPart + 123456731231231231.14159 truncated |
|
3896 | 3566 |
" |
3567 |
! |
|
3568 |
||
701 | 3569 |
rounded |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3570 |
"return the receiver rounded to the nearest integer" |
701 | 3571 |
|
3572 |
|val| |
|
3573 |
||
11945 | 3574 |
%{ |
18296 | 3575 |
#ifdef __SCHTEAM__ |
3576 |
ERROR("unimplemented"); |
|
3577 |
#else |
|
701 | 3578 |
double dVal; |
3579 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3580 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3581 |
if (dVal < 0.0) { |
11945 | 3582 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3583 |
} else { |
11945 | 3584 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3585 |
} |
701 | 3586 |
/* |
3587 |
* ST-80 (and X3J20) returns integer. |
|
3588 |
*/ |
|
3589 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
11945 | 3590 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 3591 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3592 |
__qMKFLOAT(val, dVal); |
18296 | 3593 |
#endif |
701 | 3594 |
%}. |
7355 | 3595 |
^ val asInteger |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3596 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3597 |
" |
11945 | 3598 |
0.4 rounded |
3599 |
0.5 rounded |
|
3600 |
0.6 rounded |
|
3601 |
-0.4 rounded |
|
3602 |
-0.5 rounded |
|
3603 |
-0.6 rounded |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3604 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3605 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3606 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3607 |
roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3608 |
"return the receiver rounded to the nearest integer as a float. |
11945 | 3609 |
This is much like #rounded, but avoids a (possibly expensive) conversion |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3610 |
of the result to an integer. |
11945 | 3611 |
It may be useful, if the result is to be further used in another |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3612 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3613 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3614 |
|val| |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3615 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3616 |
%{ /* NOCONTEXT */ |
18296 | 3617 |
#ifdef __SCHTEAM__ |
18299 | 3618 |
return context._RETURN( self.round() ); |
18296 | 3619 |
#else |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3620 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3621 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3622 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3623 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3624 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3625 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3626 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3627 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3628 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3629 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3630 |
RETURN (v); |
18296 | 3631 |
#endif |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3632 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3633 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3634 |
" |
11945 | 3635 |
0.5 rounded |
3636 |
-0.5 rounded |
|
3637 |
0.5 roundedAsFloat |
|
3638 |
-0.5 roundedAsFloat |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3639 |
" |
701 | 3640 |
! |
3641 |
||
3642 |
truncated |
|
3643 |
"return the receiver truncated towards zero as an integer" |
|
3644 |
||
3645 |
|val| |
|
3646 |
||
3647 |
%{ |
|
18296 | 3648 |
#ifdef __SCHTEAM__ |
3649 |
ERROR("unimplemented"); |
|
3650 |
#else |
|
701 | 3651 |
double dVal; |
3652 |
||
1133 | 3653 |
dVal = __floatVal(self); |
701 | 3654 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3655 |
dVal = ceil(dVal); |
701 | 3656 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3657 |
dVal = floor(dVal); |
701 | 3658 |
} |
3659 |
||
3660 |
/* |
|
3661 |
* ST-80 (and X3J20) returns integer. |
|
3662 |
*/ |
|
3663 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
8913 | 3664 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 3665 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3666 |
__qMKFLOAT(val, dVal); |
18296 | 3667 |
#endif |
701 | 3668 |
%}. |
3669 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3670 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3671 |
" |
11945 | 3672 |
0.5 truncated |
3673 |
-0.5 truncated |
|
3674 |
0.5 truncatedAsFloat |
|
3675 |
-0.5 truncatedAsFloat |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3676 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3677 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3678 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3679 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3680 |
truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3681 |
"return the receiver truncated towards zero as a float. |
11945 | 3682 |
This is much like #truncated, but avoids a (possibly expensive) conversion |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3683 |
of the result to an integer. |
11945 | 3684 |
It may be useful, if the result is to be further used in another |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3685 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3686 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3687 |
%{ /* NOCONTEXT */ |
18296 | 3688 |
#ifdef __SCHTEAM__ |
18300 | 3689 |
return context._RETURN( self.truncated() ); |
18296 | 3690 |
#else |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3691 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3692 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3693 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3694 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3695 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3696 |
dVal = ceil(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3697 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3698 |
dVal = floor(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3699 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3700 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3701 |
RETURN (v); |
18296 | 3702 |
#endif |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3703 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3704 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3705 |
" |
11945 | 3706 |
0.5 truncated |
3707 |
-0.5 truncated |
|
3708 |
0.5 truncatedAsFloat |
|
3709 |
-0.5 truncatedAsFloat |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3710 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3711 |
|
701 | 3712 |
! ! |
3713 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3714 |
!Float class methodsFor:'documentation'! |
701 | 3715 |
|
3716 |
version |
|
18492 | 3717 |
^ '$Header$' |
12423 | 3718 |
! |
3719 |
||
3720 |
version_CVS |
|
18492 | 3721 |
^ '$Header$' |
701 | 3722 |
! ! |
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
3723 |
|
14599 | 3724 |
|
2387 | 3725 |
Float initialize! |