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