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