author | Claus Gittinger <cg@exept.de> |
Wed, 05 Jun 2019 20:08:48 +0200 | |
changeset 24257 | 3d3652e1f81c |
parent 24255 | 82a37ed5a27c |
child 24266 | e7a43fdfc447 |
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 |
|
938 |
"answer the precision 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 |
" |
|
7355 | 949 |
! |
950 |
||
951 |
radix |
|
952 |
"answer the radix of a Floats exponent |
|
953 |
This is an IEEE float, which is represented as binary" |
|
954 |
||
8635 | 955 |
^ 2 "must be careful here, whenever ST/X is used on VAX or a 370" |
3 | 956 |
! ! |
957 |
||
1 | 958 |
!Float methodsFor:'arithmetic'! |
959 |
||
701 | 960 |
* aNumber |
11733 | 961 |
"return the product of the receiver and the argument." |
701 | 962 |
|
963 |
%{ /* NOCONTEXT */ |
|
18296 | 964 |
#ifdef __SCHTEAM__ |
965 |
if (aNumber.isNumber()) { |
|
966 |
return context._RETURN( self.times(aNumber) ); |
|
967 |
} |
|
968 |
#else |
|
701 | 969 |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
970 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
971 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
972 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
973 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
974 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
975 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
976 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
977 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
978 |
*/ |
701 | 979 |
OBJ newFloat; |
980 |
double result; |
|
981 |
||
982 |
if (__isSmallInteger(aNumber)) { |
|
11945 | 983 |
result = __floatVal(self) * (double)(__intVal(aNumber)); |
701 | 984 |
retResult: |
11945 | 985 |
__qMKFLOAT(newFloat, result); |
986 |
RETURN ( newFloat ); |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
987 |
} |
14689
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
988 |
/* 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
|
989 |
* 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
|
990 |
*/ |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
991 |
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
|
992 |
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
|
993 |
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
|
994 |
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
|
995 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
996 |
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
|
997 |
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
|
998 |
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
|
999 |
} |
701 | 1000 |
} |
18296 | 1001 |
#endif |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1002 |
%}. |
701 | 1003 |
^ aNumber productFromFloat:self |
1004 |
! |
|
1005 |
||
1 | 1006 |
+ aNumber |
1007 |
"return the sum of the receiver and the argument, aNumber" |
|
1008 |
||
1009 |
%{ /* NOCONTEXT */ |
|
18296 | 1010 |
#ifdef __SCHTEAM__ |
1011 |
if (aNumber.isNumber()) { |
|
1012 |
return context._RETURN( self.plus(aNumber) ); |
|
1013 |
} |
|
1014 |
#else |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1015 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1016 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1017 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1018 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1019 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1020 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1021 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1022 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1023 |
*/ |
1 | 1024 |
OBJ newFloat; |
1025 |
double result; |
|
1026 |
||
250 | 1027 |
if (__isSmallInteger(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1028 |
result = __floatVal(self) + (double)(__intVal(aNumber)); |
1 | 1029 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1030 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1031 |
RETURN ( newFloat ); |
11945 | 1032 |
} |
14689
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1033 |
/* 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
|
1034 |
* 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
|
1035 |
*/ |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1036 |
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
|
1037 |
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
|
1038 |
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
|
1039 |
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
|
1040 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1041 |
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
|
1042 |
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
|
1043 |
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
|
1044 |
} |
1 | 1045 |
} |
18296 | 1046 |
#endif |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1047 |
%}. |
1 | 1048 |
^ aNumber sumFromFloat:self |
1049 |
! |
|
1050 |
||
1051 |
- aNumber |
|
1052 |
"return the difference of the receiver and the argument, aNumber" |
|
1053 |
||
1054 |
%{ /* NOCONTEXT */ |
|
18296 | 1055 |
#ifdef __SCHTEAM__ |
1056 |
if (aNumber.isNumber()) { |
|
1057 |
return context._RETURN( self.minus(aNumber) ); |
|
1058 |
} |
|
1059 |
#else |
|
13 | 1060 |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1061 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1062 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1063 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1064 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1065 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1066 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1067 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1068 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1069 |
*/ |
1 | 1070 |
OBJ newFloat; |
1071 |
double result; |
|
1072 |
||
250 | 1073 |
if (__isSmallInteger(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1074 |
result = __floatVal(self) - (double)(__intVal(aNumber)); |
1 | 1075 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1076 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1077 |
RETURN ( newFloat ); |
11945 | 1078 |
} |
14689
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1079 |
/* 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
|
1080 |
* 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
|
1081 |
*/ |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1082 |
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
|
1083 |
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
|
1084 |
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
|
1085 |
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
|
1086 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1087 |
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
|
1088 |
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
|
1089 |
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
|
1090 |
} |
1 | 1091 |
} |
18296 | 1092 |
#endif |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1093 |
%}. |
1 | 1094 |
^ aNumber differenceFromFloat:self |
1095 |
! |
|
1096 |
||
1097 |
/ aNumber |
|
1098 |
"return the quotient of the receiver and the argument, aNumber" |
|
1099 |
||
1100 |
%{ /* NOCONTEXT */ |
|
18296 | 1101 |
#ifdef __SCHTEAM__ |
1102 |
if (aNumber.isNumber()) { |
|
1103 |
return context._RETURN( self.quotient(aNumber) ); |
|
1104 |
} |
|
1105 |
#else |
|
1 | 1106 |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1107 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1108 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1109 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1110 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1111 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1112 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1113 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1114 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
1115 |
*/ |
1 | 1116 |
OBJ newFloat; |
1117 |
double result, val; |
|
1118 |
||
250 | 1119 |
if (__isSmallInteger(aNumber)) { |
11945 | 1120 |
if (aNumber != __mkSmallInteger(0)) { |
1121 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
|
1 | 1122 |
retResult: |
11945 | 1123 |
__qMKFLOAT(newFloat, result); |
1124 |
RETURN ( newFloat ); |
|
1125 |
} |
|
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1126 |
} else if (__isFloatLike(aNumber)) { |
11945 | 1127 |
val = __floatVal(aNumber); |
1128 |
if (val != 0.0) { |
|
1129 |
result = __floatVal(self) / val; |
|
1130 |
goto retResult; |
|
1131 |
} |
|
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1132 |
} else if (__isShortFloat(aNumber)) { |
11945 | 1133 |
val = (double)(__shortFloatVal(aNumber)); |
1134 |
if (val != 0.0) { |
|
1135 |
result = __floatVal(self) / val; |
|
1136 |
goto retResult; |
|
1137 |
} |
|
1 | 1138 |
} |
18296 | 1139 |
#endif |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
1140 |
%}. |
1 | 1141 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
11945 | 1142 |
" |
1143 |
No, you shalt not divide by zero |
|
1144 |
" |
|
1145 |
^ ZeroDivide raiseRequestWith:thisContext. |
|
1 | 1146 |
]. |
1147 |
^ aNumber quotientFromFloat:self |
|
1148 |
! |
|
1149 |
||
14923 | 1150 |
abs |
1151 |
"return the absolute value of the receiver |
|
1152 |
reimplemented here for speed" |
|
1153 |
||
1154 |
%{ /* NOCONTEXT */ |
|
18296 | 1155 |
#ifdef __SCHTEAM__ |
1156 |
return context._RETURN( self.abs() ); |
|
1157 |
#else |
|
14923 | 1158 |
|
1159 |
OBJ newFloat; |
|
1160 |
double val =__floatVal(self); |
|
1161 |
||
1162 |
if (val < 0.0) { |
|
1163 |
__qMKFLOAT(newFloat, -val); |
|
1164 |
RETURN ( newFloat ); |
|
1165 |
} |
|
1166 |
RETURN (self); |
|
18296 | 1167 |
#endif |
14923 | 1168 |
%}. |
1169 |
||
1170 |
" |
|
1171 |
3.0 abs |
|
1172 |
-3.0 abs |
|
1173 |
" |
|
1174 |
! |
|
1175 |
||
1176 |
negated |
|
17226 | 1177 |
"return the receiver negated" |
14923 | 1178 |
|
1179 |
%{ /* NOCONTEXT */ |
|
18296 | 1180 |
#ifdef __SCHTEAM__ |
1181 |
return context._RETURN( self.negated() ); |
|
1182 |
#else |
|
14923 | 1183 |
OBJ newFloat; |
1184 |
double rslt = - __floatVal(self); |
|
1185 |
||
1186 |
__qMKFLOAT(newFloat, rslt); |
|
1187 |
RETURN ( newFloat ); |
|
18296 | 1188 |
#endif |
14923 | 1189 |
%}. |
1190 |
! |
|
1191 |
||
14689
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1192 |
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
|
1193 |
"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
|
1194 |
|
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1195 |
%{ /* NOCONTEXT */ |
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 |
/* |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1198 |
* notice: |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1199 |
* 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
|
1200 |
* 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
|
1201 |
* |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1202 |
* 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
|
1203 |
* 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
|
1204 |
* (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
|
1205 |
*/ |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1206 |
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
|
1207 |
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
|
1208 |
|
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1209 |
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
|
1210 |
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
|
1211 |
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
|
1212 |
computeResult: |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1213 |
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
|
1214 |
__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
|
1215 |
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
|
1216 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1217 |
} 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
|
1218 |
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
|
1219 |
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
|
1220 |
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
|
1221 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1222 |
} 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
|
1223 |
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
|
1224 |
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
|
1225 |
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
|
1226 |
} |
14720 | 1227 |
#ifdef LONGFLOAT_KNOWN_HERE |
1228 |
} else if (__isLongFloat(aNumber)) { |
|
1229 |
long double lval; |
|
1230 |
||
1231 |
lval = (long double)(__longFloatVal(aNumber)); |
|
1232 |
if (val != 0.0) { |
|
1233 |
long double lResult; |
|
1234 |
||
1235 |
lResult = fmodl((long double)(__floatVal(self)), lval); |
|
1236 |
__qMKLFLOAT(newFloat, lResult); |
|
1237 |
RETURN (newFloat); |
|
1238 |
} |
|
1239 |
#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
|
1240 |
} |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1241 |
%}. |
f709732040c1
added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents:
14672
diff
changeset
|
1242 |
((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
|
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 |
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
|
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 |
^ 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
|
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 |
^ 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
|
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 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1251 |
uncheckedDivide:aNumber |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1252 |
"return the quotient of the receiver and the argument, aNumber. |
7471 | 1253 |
Do not check for divide by zero (return NaN or Infinity). |
7355 | 1254 |
This operation is provided for emulators of other languages/semantics, |
1255 |
where no exception is raised for these results (i.e. Java). |
|
18838 | 1256 |
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
|
1257 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1258 |
%{ /* NOCONTEXT */ |
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 |
OBJ newFloat; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1261 |
double result, val; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1262 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1263 |
if (__isSmallInteger(aNumber)) { |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1264 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1265 |
retResult: |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1266 |
__qMKFLOAT(newFloat, result); |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1267 |
RETURN ( newFloat ); |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1268 |
} |
7355 | 1269 |
if (__isFloatLike(aNumber)) { |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1270 |
val = __floatVal(aNumber); |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1271 |
result = __floatVal(self) / val; |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1272 |
goto retResult; |
7355 | 1273 |
} |
1274 |
if (__isShortFloat(aNumber)) { |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1275 |
val = (double)(__shortFloatVal(aNumber)); |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1276 |
result = __floatVal(self) / val; |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
1277 |
goto retResult; |
7355 | 1278 |
} |
1279 |
%}. |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1280 |
^ aNumber quotientFromFloat:self |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1281 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1282 |
" |
11945 | 1283 |
0.0 uncheckedDivide:0.0 |
1284 |
1.0 uncheckedDivide:0.0 |
|
1285 |
-1.0 uncheckedDivide:0.0 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1286 |
" |
1 | 1287 |
! ! |
1288 |
||
701 | 1289 |
|
5238 | 1290 |
!Float methodsFor:'coercing & converting'! |
1 | 1291 |
|
3014 | 1292 |
asDouble |
17226 | 1293 |
"ST80 compatibility: return a double with the receiver's value. |
1294 |
In ST/X, floats are the equivalent to ST80 doubles" |
|
3014 | 1295 |
|
1296 |
^ self |
|
1297 |
! |
|
1298 |
||
701 | 1299 |
asFloat |
15020 | 1300 |
"return a float with same value - that's me" |
701 | 1301 |
|
1302 |
^ self |
|
1303 |
! |
|
1304 |
||
1305 |
asInteger |
|
1306 |
"return an integer with same value - might truncate" |
|
1307 |
||
1 | 1308 |
%{ /* NOCONTEXT */ |
1670 | 1309 |
double dVal; |
13 | 1310 |
|
1670 | 1311 |
dVal = __floatVal(self); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
1312 |
#ifdef __win32__ |
11945 | 1313 |
if (! isnan(dVal)) |
7420 | 1314 |
#endif |
1315 |
{ |
|
11945 | 1316 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
1317 |
RETURN ( __mkSmallInteger( (INT)dVal) ); |
|
1318 |
} |
|
701 | 1319 |
} |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1320 |
%}. |
701 | 1321 |
^ super asInteger |
1322 |
||
1323 |
"12345.0 asInteger" |
|
1324 |
"1e15 asInteger" |
|
1 | 1325 |
! |
1326 |
||
5986 | 1327 |
asLongFloat |
1328 |
"return a longFloat with same value as receiver" |
|
1329 |
||
7355 | 1330 |
^ LongFloat fromFloat:self |
5986 | 1331 |
|
1332 |
" |
|
11945 | 1333 |
123 asFloat asLongFloat |
5986 | 1334 |
" |
1335 |
||
1336 |
"Created: / 7.9.2001 / 13:43:04 / cg" |
|
1337 |
"Modified: / 7.9.2001 / 13:43:16 / cg" |
|
1338 |
! |
|
1339 |
||
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1340 |
asShortFloat |
7355 | 1341 |
"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
|
1342 |
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
|
1343 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1344 |
%{ /* NOCONTEXT */ |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1345 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1346 |
OBJ dummy = @global(ShortFloat); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1347 |
OBJ newFloat; |
24255 | 1348 |
double dVal = __floatVal(self); |
1349 |
float fVal = (float)dVal; |
|
1350 |
||
1351 |
if (isfinite(fVal) || !isfinite(dVal)) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1352 |
__qMKSFLOAT(newFloat, fVal); |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1353 |
RETURN ( newFloat ); |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1354 |
} |
18296 | 1355 |
%}. |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1356 |
" |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1357 |
value out of range |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1358 |
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
|
1359 |
" |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1360 |
^ self class |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1361 |
raise:#infiniteResultSignal |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1362 |
receiver:self |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1363 |
selector:#asShortFloat |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1364 |
arguments:#() |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1365 |
errorString:'receiver is out of the single-precision float range' |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1366 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1367 |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1368 |
asTrueFraction |
17226 | 1369 |
"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
|
1370 |
a double precision IEEE floating point number. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1371 |
Floats are stored in the same form on all platforms. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1372 |
(Does not handle gradual underflow or NANs.) |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1373 |
By David N. Smith with significant performance |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1374 |
improvements by Luciano Esteban Notarfrancesco. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1375 |
(Version of 11April97)" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1376 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1377 |
|shifty sign expPart exp fraction fractionPart result zeroBitsCount| |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1378 |
|
6344 | 1379 |
self isFinite ifFalse:[ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1380 |
^ self asMetaNumber |
7441 | 1381 |
"/ ^ self class |
1382 |
"/ raise:#domainErrorSignal |
|
1383 |
"/ receiver:self |
|
1384 |
"/ selector:#asTrueFraction |
|
1385 |
"/ arguments:#() |
|
1386 |
"/ errorString:'Cannot represent non-finite float as a fraction'. |
|
6341 | 1387 |
]. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1388 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1389 |
"Extract the bits of an IEEE double float " |
6341 | 1390 |
shifty := LargeInteger basicNew numberOfDigits:8. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1391 |
UninterpretedBytes isBigEndian ifTrue:[ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1392 |
"/ 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
|
1393 |
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
|
1394 |
] ifFalse:[ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1395 |
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
|
1396 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1397 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1398 |
" Extract the sign and the biased exponent " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1399 |
sign := (shifty bitShift: -63) = 0 ifTrue: [1] ifFalse: [-1]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1400 |
expPart := (shifty bitShift: -52) bitAnd: 16r7FF. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1401 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1402 |
" 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
|
1403 |
fractionPart := shifty bitAnd: 16r000FFFFFFFFFFFFF. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1404 |
( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0 ]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1405 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1406 |
" Replace omitted leading 1 in fraction " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1407 |
fraction := fractionPart bitOr: 16r0010000000000000. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1408 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1409 |
"Unbias exponent: 16r3FF is bias; 52 is fraction width" |
7480 | 1410 |
exp := 16r3FF - expPart + 52. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1411 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1412 |
" 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
|
1413 |
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
|
1414 |
the (huge) time otherwise spent in #gcd:. " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1415 |
exp negative ifTrue: [ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1416 |
result := sign * (fraction bitShift: exp negated) |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1417 |
] ifFalse:[ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1418 |
zeroBitsCount := fraction lowBit - 1. |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1419 |
exp := exp - zeroBitsCount. |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1420 |
exp <= 0 ifTrue: [ |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1421 |
zeroBitsCount := zeroBitsCount + exp. |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1422 |
"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
|
1423 |
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
|
1424 |
] ifFalse: [ |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1425 |
result := Fraction |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1426 |
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
|
1427 |
denominator: (1 bitShift:exp) |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1428 |
] |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1429 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1430 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1431 |
"Low cost validation omitted after extensive testing" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1432 |
"(result asFloat = self) ifFalse: [self error: 'asTrueFraction validation failed']." |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1433 |
|
11945 | 1434 |
^ result |
4615
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 |
" |
17226 | 1437 |
0.3 asTrueFraction - as you can see, Float is not able to represent this exactly |
1438 |
1.25 asTrueFraction - but this one (it is a sum of powers of two) |
|
11945 | 1439 |
0.25 asTrueFraction |
1440 |
-0.25 asTrueFraction |
|
1441 |
3e37 asTrueFraction |
|
17226 | 1442 |
2e37 asTrueFraction |
1443 |
1e37 asTrueFraction |
|
18296 | 1444 |
1e30 asTrueFraction |
6341 | 1445 |
Float NaN asTrueFraction |
6344 | 1446 |
Float infinity asTrueFraction |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1447 |
" |
24230 | 1448 |
|
1449 |
"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
|
1450 |
! |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
1451 |
|
701 | 1452 |
coerce:aNumber |
18838 | 1453 |
"convert the argument aNumber into an instance of the receiver's class and return it." |
1 | 1454 |
|
701 | 1455 |
^ aNumber asFloat |
1456 |
! |
|
13 | 1457 |
|
701 | 1458 |
generality |
1459 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
1460 |
||
1461 |
^ 80 |
|
1 | 1462 |
! ! |
1463 |
||
1464 |
!Float methodsFor:'comparing'! |
|
1465 |
||
1466 |
< aNumber |
|
1467 |
"return true, if the argument is greater" |
|
1468 |
||
1469 |
%{ /* NOCONTEXT */ |
|
18296 | 1470 |
#ifdef __SCHTEAM__ |
1471 |
if (aNumber.isNumber()) { |
|
1472 |
return context._RETURN( self.ltP(aNumber) ); |
|
1473 |
} |
|
1474 |
#else |
|
11945 | 1475 |
/* |
1476 |
* notice: |
|
1477 |
* the following inline code handles some common cases, |
|
1478 |
* and exists as an optimization, to speed up those cases. |
|
1479 |
* |
|
1480 |
* Conceptionally, (and for most other argument types), |
|
1481 |
* mixed arithmetic is implemented by double dispatching |
|
1482 |
* (see the message send at the bottom) |
|
1483 |
*/ |
|
7355 | 1484 |
if (__isSmallInteger(aNumber)) { |
11945 | 1485 |
RETURN ( (__floatVal(self) < (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1486 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1487 |
if (aNumber != nil) { |
11945 | 1488 |
if (__qIsFloatLike(aNumber)) { |
1489 |
RETURN ( (__floatVal(self) < __floatVal(aNumber)) ? true : false ); |
|
1490 |
} |
|
1491 |
if (__qIsShortFloat(aNumber)) { |
|
1492 |
RETURN ( (__floatVal(self) < (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1493 |
} |
|
1 | 1494 |
} |
18296 | 1495 |
#endif |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1496 |
%}. |
1 | 1497 |
^ aNumber lessFromFloat:self |
1498 |
! |
|
1499 |
||
1500 |
<= aNumber |
|
1501 |
"return true, if the argument is greater or equal" |
|
1502 |
||
1503 |
%{ /* NOCONTEXT */ |
|
18296 | 1504 |
#ifdef __SCHTEAM__ |
1505 |
if (aNumber.isNumber()) { |
|
1506 |
return context._RETURN( self.leP(aNumber) ); |
|
1507 |
} |
|
1508 |
#else |
|
11945 | 1509 |
/* |
1510 |
* notice: |
|
1511 |
* the following inline code handles some common cases, |
|
1512 |
* and exists as an optimization, to speed up those cases. |
|
1513 |
* |
|
1514 |
* Conceptionally, (and for most other argument types), |
|
1515 |
* mixed arithmetic is implemented by double dispatching |
|
1516 |
* (see the message send at the bottom) |
|
1517 |
*/ |
|
7355 | 1518 |
if (__isSmallInteger(aNumber)) { |
11945 | 1519 |
RETURN ( (__floatVal(self) <= (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1520 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1521 |
if (aNumber != nil) { |
11945 | 1522 |
if (__qIsFloatLike(aNumber)) { |
1523 |
RETURN ( (__floatVal(self) <= __floatVal(aNumber)) ? true : false ); |
|
1524 |
} |
|
1525 |
if (__qIsShortFloat(aNumber)) { |
|
1526 |
RETURN ( (__floatVal(self) <= (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1527 |
} |
|
1 | 1528 |
} |
18296 | 1529 |
#endif |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1530 |
%}. |
1 | 1531 |
^ self retry:#<= coercing:aNumber |
1532 |
! |
|
1533 |
||
1534 |
= aNumber |
|
7355 | 1535 |
"return true, if the argument represents the same numeric value |
1536 |
as the receiver, false otherwise" |
|
1 | 1537 |
|
1538 |
%{ /* NOCONTEXT */ |
|
18296 | 1539 |
#ifdef __SCHTEAM__ |
1540 |
if (aNumber.isNumber()) { |
|
1541 |
return context._RETURN( self.eqNrP(aNumber) ); |
|
1542 |
} |
|
1543 |
#else |
|
13 | 1544 |
|
11945 | 1545 |
/* |
1546 |
* notice: |
|
1547 |
* the following inline code handles some common cases, |
|
1548 |
* and exists as an optimization, to speed up those cases. |
|
1549 |
* |
|
1550 |
* Conceptionally, (and for most other argument types), |
|
1551 |
* mixed arithmetic is implemented by double dispatching |
|
1552 |
* (see the message send at the bottom) |
|
1553 |
*/ |
|
7355 | 1554 |
if (__isSmallInteger(aNumber)) { |
11945 | 1555 |
RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1556 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1557 |
if (aNumber != nil) { |
11945 | 1558 |
if (__qIsFloatLike(aNumber)) { |
1559 |
RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false ); |
|
1560 |
} |
|
1561 |
if (__qIsShortFloat(aNumber)) { |
|
1562 |
RETURN ( (__floatVal(self) == (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1563 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1564 |
} else { |
11945 | 1565 |
RETURN (false); |
1 | 1566 |
} |
18296 | 1567 |
#endif |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1568 |
%}. |
7355 | 1569 |
^ aNumber equalFromFloat:self |
1 | 1570 |
! |
1571 |
||
701 | 1572 |
> aNumber |
1573 |
"return true, if the argument is less" |
|
1 | 1574 |
|
1575 |
%{ /* NOCONTEXT */ |
|
18296 | 1576 |
#ifdef __SCHTEAM__ |
1577 |
if (aNumber.isNumber()) { |
|
1578 |
return context._RETURN( self.gtP(aNumber) ); |
|
1579 |
} |
|
1580 |
#else |
|
11945 | 1581 |
/* |
1582 |
* notice: |
|
1583 |
* the following inline code handles some common cases, |
|
1584 |
* and exists as an optimization, to speed up those cases. |
|
1585 |
* |
|
1586 |
* Conceptionally, (and for most other argument types), |
|
1587 |
* mixed arithmetic is implemented by double dispatching |
|
1588 |
* (see the message send at the bottom) |
|
1589 |
*/ |
|
7355 | 1590 |
if (__isSmallInteger(aNumber)) { |
11945 | 1591 |
RETURN ( (__floatVal(self) > (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1592 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1593 |
if (aNumber != nil) { |
11945 | 1594 |
if (__qIsFloatLike(aNumber)) { |
1595 |
RETURN ( (__floatVal(self) > __floatVal(aNumber)) ? true : false ); |
|
1596 |
} |
|
1597 |
if (__qIsShortFloat(aNumber)) { |
|
1598 |
RETURN ( (__floatVal(self) > (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1599 |
} |
|
1 | 1600 |
} |
18296 | 1601 |
#endif |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1602 |
%}. |
701 | 1603 |
^ self retry:#> coercing:aNumber |
1604 |
! |
|
1605 |
||
1606 |
>= aNumber |
|
1607 |
"return true, if the argument is less or equal" |
|
1608 |
||
1609 |
%{ /* NOCONTEXT */ |
|
18296 | 1610 |
#ifdef __SCHTEAM__ |
1611 |
if (aNumber.isNumber()) { |
|
1612 |
return context._RETURN( self.geP(aNumber) ); |
|
1613 |
} |
|
1614 |
#else |
|
11945 | 1615 |
/* |
1616 |
* notice: |
|
1617 |
* the following inline code handles some common cases, |
|
1618 |
* and exists as an optimization, to speed up those cases. |
|
1619 |
* |
|
1620 |
* Conceptionally, (and for most other argument types), |
|
1621 |
* mixed arithmetic is implemented by double dispatching |
|
1622 |
* (see the message send at the bottom) |
|
1623 |
*/ |
|
7355 | 1624 |
if (__isSmallInteger(aNumber)) { |
11945 | 1625 |
RETURN ( (__floatVal(self) >= (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1626 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1627 |
if (aNumber != nil) { |
11945 | 1628 |
if (__qIsFloatLike(aNumber)) { |
1629 |
RETURN ( (__floatVal(self) >= __floatVal(aNumber)) ? true : false ); |
|
1630 |
} |
|
1631 |
if (__qIsShortFloat(aNumber)) { |
|
1632 |
RETURN ( (__floatVal(self) >= (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1633 |
} |
|
701 | 1634 |
} |
18296 | 1635 |
#endif |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1636 |
%}. |
701 | 1637 |
^ self retry:#>= coercing:aNumber |
92 | 1638 |
! |
1639 |
||
1640 |
hash |
|
1641 |
"return a number for hashing; redefined, since floats compare |
|
1642 |
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
|
1643 |
as 3 hash." |
92 | 1644 |
|
305 | 1645 |
|i| |
92 | 1646 |
|
1647 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1648 |
i := self asInteger. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1649 |
self = i ifTrue:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1650 |
^ i hash |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1651 |
]. |
92 | 1652 |
]. |
1653 |
||
1654 |
" |
|
305 | 1655 |
mhmh take some of my value-bits to hash on |
92 | 1656 |
" |
4590 | 1657 |
^ (((self basicAt:8) bitAnd:16r1F) bitShift:24) + |
305 | 1658 |
((self basicAt:7) bitShift:16) + |
1659 |
((self basicAt:6) bitShift:8) + |
|
4592 | 1660 |
(((self basicAt:5) + (self basicAt:1) + (self basicAt:2)) bitAnd:16rFF) |
92 | 1661 |
|
1662 |
" |
|
11945 | 1663 |
3 hash |
92 | 1664 |
3.0 hash |
11945 | 1665 |
3.1 hash |
1666 |
3.14159 hash |
|
1667 |
31.4159 hash |
|
1668 |
3.141591 hash |
|
1669 |
1.234567890123456 hash |
|
1670 |
1.234567890123457 hash |
|
92 | 1671 |
Set withAll:#(3 3.0 99 99.0 3.1415) |
1672 |
" |
|
1 | 1673 |
! |
1674 |
||
17199 | 1675 |
isAlmostEqualTo:aNumber nEpsilon:nE |
16658 | 1676 |
"return true, if the argument, aNumber represents almost the same numeric value |
1677 |
as the receiver, false otherwise. |
|
1678 |
||
1679 |
nE is the number of minimal float distances, that the numbers may differ and |
|
22578 | 1680 |
still be considered equal. |
22559 | 1681 |
That is an integer, which counts the delta-steps in the mantissa. |
1682 |
Notice, that the absolute value of the epsilon depends on the receiver |
|
1683 |
(i.e. with a receiver of 10^17, a mantissa-step is much larger than with 10^-17 as receiver) |
|
16658 | 1684 |
|
17199 | 1685 |
For background information why floats need this |
16658 | 1686 |
read: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ |
1687 |
" |
|
1688 |
||
21148 | 1689 |
Epsilon isNil ifTrue:[ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1690 |
Epsilon := self class computeEpsilon. |
21148 | 1691 |
]. |
1692 |
||
16658 | 1693 |
%{ /* NOCONTEXT */ |
1694 |
||
1695 |
/* |
|
1696 |
* notice: |
|
1697 |
* the following inline code handles some common cases, |
|
1698 |
* and exists as an optimization, to speed up those cases. |
|
1699 |
* |
|
1700 |
* Conceptionally, (and for most other argument types), |
|
1701 |
* mixed arithmetic is implemented by double dispatching |
|
1702 |
* (see the message send at the bottom) |
|
1703 |
*/ |
|
1704 |
||
1705 |
INT64 ulpDiff; |
|
1706 |
union { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1707 |
double d; |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1708 |
INT64 i; |
16658 | 1709 |
} myself, otherFloat; |
1710 |
int nEpsilon; |
|
1711 |
double scaledEpsilon; |
|
1712 |
||
1713 |
if (!__isSmallInteger(nE)) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1714 |
goto tryHarder; |
16658 | 1715 |
} |
1716 |
||
1717 |
nEpsilon = __intVal(nE); |
|
1718 |
scaledEpsilon = nEpsilon *__floatVal(@global(Epsilon)); |
|
1719 |
||
1720 |
if (__isSmallInteger(aNumber)) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1721 |
otherFloat.d = (double)(__intVal(aNumber)); |
16658 | 1722 |
} else if (aNumber == nil) { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1723 |
RETURN(false) |
16658 | 1724 |
} else if (__qIsFloatLike(aNumber)) { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1725 |
otherFloat.d = (double)(__floatVal(aNumber)); |
16658 | 1726 |
} else if (__qIsShortFloat(aNumber)) { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1727 |
otherFloat.d = (double)(__shortFloatVal(aNumber)); |
16658 | 1728 |
} else { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1729 |
goto tryHarder; |
16658 | 1730 |
} |
1731 |
||
1732 |
myself.d = __floatVal(self); |
|
1733 |
||
1734 |
// Check if the numbers are really close -- needed |
|
1735 |
// when comparing numbers near zero (ULP method below fails for numbers near 0!). |
|
1736 |
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
|
1737 |
RETURN(true); |
16658 | 1738 |
} |
1739 |
||
1740 |
// if the signs differ, the numbers are different |
|
16667 | 1741 |
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
|
1742 |
RETURN(false); |
16658 | 1743 |
} |
1744 |
||
1745 |
// compute the difference of the 'units in the last place" ULP |
|
1746 |
// (if ulpDiff == 1, two floats are adjecant) |
|
1747 |
ulpDiff = myself.i - otherFloat.i; |
|
1748 |
if (ulpDiff < 0) ulpDiff = -ulpDiff; |
|
1749 |
if (ulpDiff <= nEpsilon) { |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1750 |
RETURN(true); |
16658 | 1751 |
} else { |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1752 |
RETURN(false) |
16658 | 1753 |
} |
1754 |
||
1755 |
tryHarder:; |
|
1756 |
%}. |
|
22559 | 1757 |
nE isInteger ifFalse:[ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1758 |
self error:'nEpsilon argument must be an integer'. |
22559 | 1759 |
]. |
16658 | 1760 |
^ aNumber isAlmostEqualToFromFloat:self nEpsilon:nE |
1761 |
||
1762 |
" |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
1763 |
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
|
1764 |
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
|
1765 |
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
|
1766 |
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
|
1767 |
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
|
1768 |
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
|
1769 |
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
|
1770 |
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
|
1771 |
0.0 isAlmostEqualTo:self epsilon nEpsilon:1 |
16658 | 1772 |
" |
22854 | 1773 |
|
1774 |
"Modified: / 10-05-2018 / 00:48:57 / stefan" |
|
16658 | 1775 |
! |
1776 |
||
701 | 1777 |
~= aNumber |
1778 |
"return true, if the arguments value are not equal" |
|
1 | 1779 |
|
1780 |
%{ /* NOCONTEXT */ |
|
1781 |
||
11945 | 1782 |
/* |
1783 |
* notice: |
|
1784 |
* the following inline code handles some common cases, |
|
1785 |
* and exists as an optimization, to speed up those cases. |
|
1786 |
* |
|
1787 |
* Conceptionally, (and for most other argument types), |
|
1788 |
* mixed arithmetic is implemented by double dispatching |
|
1789 |
* (see the message send at the bottom) |
|
1790 |
*/ |
|
7355 | 1791 |
if (__isSmallInteger(aNumber)) { |
11945 | 1792 |
RETURN ( (__floatVal(self) != (double)(__intVal(aNumber))) ? true : false ); |
7355 | 1793 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1794 |
if (aNumber != nil) { |
11945 | 1795 |
if (__qIsFloatLike(aNumber)) { |
1796 |
RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false ); |
|
1797 |
} |
|
1798 |
if (__qIsShortFloat(aNumber)) { |
|
1799 |
RETURN ( (__floatVal(self) != (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1800 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1801 |
} else { |
11945 | 1802 |
RETURN ( true ); |
1 | 1803 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1804 |
%}. |
7355 | 1805 |
^ super ~= aNumber |
1 | 1806 |
! ! |
1807 |
||
24191 | 1808 |
!Float methodsFor:'copying'! |
1809 |
||
1810 |
deepCopy |
|
1811 |
"return a deep copy of myself |
|
1812 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
1813 |
||
1814 |
^ self |
|
1815 |
! |
|
1816 |
||
1817 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
1818 |
"return a deep copy of myself |
|
1819 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
1820 |
||
1821 |
^ self |
|
1822 |
! |
|
1823 |
||
1824 |
shallowCopy |
|
1825 |
"return a shallow copy of the receiver" |
|
1826 |
||
1827 |
^ self |
|
1828 |
! |
|
1829 |
||
1830 |
simpleDeepCopy |
|
1831 |
"return a deep copy of the receiver |
|
1832 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
1833 |
||
1834 |
^ self |
|
1835 |
! ! |
|
1836 |
||
1 | 1837 |
!Float methodsFor:'mathematical functions'! |
1838 |
||
17218 | 1839 |
cbrt |
1840 |
"return the cubic root of myself." |
|
1841 |
||
1842 |
%{ /* NOCONTEXT */ |
|
1843 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
1844 |
#ifndef __win32__ /* seems to be not avail. in WIN32 math lib */ |
17218 | 1845 |
double val, rslt; |
1846 |
OBJ newFloat; |
|
1847 |
||
1848 |
val = __floatVal(self); |
|
1849 |
||
1850 |
{ |
|
1851 |
__threadErrno = 0; |
|
1852 |
rslt = cbrt(val); |
|
1853 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
1854 |
{ |
|
1855 |
if (__threadErrno == 0) { |
|
1856 |
__qMKFLOAT(newFloat, rslt); |
|
1857 |
RETURN ( newFloat ); |
|
1858 |
} |
|
1859 |
} |
|
1860 |
} |
|
1861 |
# endif /* WIN32 */ |
|
1862 |
%}. |
|
1863 |
^ super cbrt |
|
1864 |
||
1865 |
" |
|
1866 |
8 cbrt |
|
1867 |
-8 cbrt |
|
1868 |
" |
|
1869 |
! |
|
1870 |
||
701 | 1871 |
exp |
1872 |
"return e raised to the power of the receiver" |
|
1873 |
||
1874 |
%{ /* NOCONTEXT */ |
|
1875 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1876 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1877 |
OBJ newFloat; |
701 | 1878 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1879 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1880 |
rslt = exp(__floatVal(self)); |
7393 | 1881 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
1882 |
{ |
|
11945 | 1883 |
if (__threadErrno == 0) { |
1884 |
__qMKFLOAT(newFloat, rslt); |
|
1885 |
RETURN ( newFloat ); |
|
1886 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1887 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1888 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1889 |
^ self class |
11945 | 1890 |
raise:#domainErrorSignal |
1891 |
receiver:self |
|
1892 |
selector:#exp |
|
1893 |
arguments:#() |
|
1894 |
errorString:'bad receiver in exp' |
|
6195 | 1895 |
|
1896 |
"Modified: / 16.11.2001 / 14:14:29 / cg" |
|
701 | 1897 |
! |
1898 |
||
21832 | 1899 |
ldexp:exp |
1900 |
"multiply the receiver by an integral power of 2. |
|
1901 |
I.e. return self * (2 ^ exp)" |
|
1902 |
||
1903 |
%{ /* NOCONTEXT */ |
|
1904 |
#ifndef __SCHTEAM__ |
|
1905 |
double val, rslt; |
|
1906 |
OBJ newFloat; |
|
1907 |
||
1908 |
if (__isSmallInteger(exp)) { |
|
21868 | 1909 |
int __exp = __intVal(exp); |
1910 |
||
1911 |
val = __floatVal(self); |
|
1912 |
||
1913 |
{ |
|
1914 |
__threadErrno = 0; |
|
1915 |
rslt = ldexp(val, __exp); |
|
1916 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
1917 |
{ |
|
1918 |
if (__threadErrno == 0) { |
|
1919 |
__qMKFLOAT(newFloat, rslt); |
|
1920 |
RETURN ( newFloat ); |
|
1921 |
} |
|
1922 |
} |
|
1923 |
} |
|
21832 | 1924 |
} |
1925 |
#endif |
|
1926 |
%}. |
|
21835 | 1927 |
^ super ldexp:exp |
21832 | 1928 |
|
1929 |
" |
|
1930 |
1.0 ldexp:16 |
|
1931 |
" |
|
1932 |
||
1933 |
"Created: / 19-06-2017 / 01:42:22 / cg" |
|
21835 | 1934 |
"Modified: / 19-06-2017 / 09:16:32 / cg" |
21832 | 1935 |
! |
1936 |
||
1 | 1937 |
ln |
6193 | 1938 |
"return the natural logarithm of myself. |
1939 |
Raises an exception, if the receiver is less or equal to zero." |
|
1 | 1940 |
|
1941 |
%{ /* NOCONTEXT */ |
|
18296 | 1942 |
#ifdef __SCHTEAM__ |
18299 | 1943 |
return context._RETURN( self.log() ); |
18296 | 1944 |
#else |
1 | 1945 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1946 |
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
|
1947 |
OBJ newFloat; |
1 | 1948 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1949 |
val = __floatVal(self); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1950 |
|
22578 | 1951 |
/* |
1952 |
* to suppress the warnBox opened by win32 |
|
21952 | 1953 |
* to avoid returning -INF from some unix math libs (__osx__) |
1954 |
*/ |
|
1955 |
if (val > 0.0) { |
|
22578 | 1956 |
__threadErrno = 0; |
1957 |
rslt = log(val); |
|
1958 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
1959 |
{ |
|
1960 |
if (__threadErrno == 0) { |
|
1961 |
__qMKFLOAT(newFloat, rslt); |
|
1962 |
RETURN ( newFloat ); |
|
1963 |
} |
|
1964 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1965 |
} |
18296 | 1966 |
#endif |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1967 |
%}. |
142 | 1968 |
" |
1969 |
an invalid value for logarithm |
|
21970 | 1970 |
if you need -INF for a zero receiver, try Number trapInfinity:[...] |
142 | 1971 |
" |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1972 |
^ self class |
22578 | 1973 |
raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal]) |
1974 |
receiver:self |
|
1975 |
selector:#ln |
|
1976 |
arguments:#() |
|
1977 |
errorString:'bad receiver in ln (not strictly positive)' |
|
21952 | 1978 |
|
21970 | 1979 |
"Modified (comment): / 03-07-2017 / 15:58:17 / cg" |
1 | 1980 |
! |
1981 |
||
7373 | 1982 |
log10 |
21824 | 1983 |
"return the base-10 logarithm of the receiver. |
7373 | 1984 |
Raises an exception, if the receiver is less or equal to zero." |
1985 |
||
1986 |
%{ /* NOCONTEXT */ |
|
18296 | 1987 |
#ifdef __SCHTEAM__ |
18299 | 1988 |
return context._RETURN( self.log10() ); |
18296 | 1989 |
#else |
7373 | 1990 |
|
1991 |
double val, rslt; |
|
1992 |
OBJ newFloat; |
|
1993 |
||
1994 |
val = __floatVal(self); |
|
1995 |
||
22578 | 1996 |
/* |
1997 |
* to suppress the warnBox opened by win32 |
|
21953 | 1998 |
* to avoid returning -INF from some unix math libs (__osx__) |
1999 |
*/ |
|
2000 |
if (val > 0.0) { |
|
22578 | 2001 |
__threadErrno = 0; |
2002 |
rslt = log10(val); |
|
2003 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2004 |
{ |
|
2005 |
if (__threadErrno == 0) { |
|
2006 |
__qMKFLOAT(newFloat, rslt); |
|
2007 |
RETURN ( newFloat ); |
|
2008 |
} |
|
2009 |
} |
|
7373 | 2010 |
} |
18296 | 2011 |
#endif |
7373 | 2012 |
%}. |
2013 |
" |
|
2014 |
an invalid value for logarithm |
|
21970 | 2015 |
if you need -INF for a zero receiver, try Number trapInfinity:[...] |
7373 | 2016 |
" |
2017 |
^ self class |
|
22578 | 2018 |
raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal]) |
2019 |
receiver:self |
|
2020 |
selector:#log10 |
|
2021 |
arguments:#() |
|
2022 |
errorString:'bad receiver in log10 (not strictly positive)' |
|
21953 | 2023 |
|
21970 | 2024 |
"Modified (comment): / 03-07-2017 / 15:58:21 / cg" |
7373 | 2025 |
! |
2026 |
||
1 | 2027 |
raisedTo:aNumber |
2028 |
"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
|
2029 |
|
1 | 2030 |
%{ |
21936 | 2031 |
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
|
2032 |
OBJ newFloat; |
1 | 2033 |
|
21936 | 2034 |
if (__isFloatLike(aNumber)) { |
22578 | 2035 |
_n = __floatVal(aNumber); |
21936 | 2036 |
} else if (__isSmallInteger(aNumber)) { |
22578 | 2037 |
_n = (double)__intVal(aNumber); |
21936 | 2038 |
} else { |
22578 | 2039 |
goto notEasy; |
2040 |
} |
|
21936 | 2041 |
__threadErrno = 0; |
2042 |
rslt = pow(__floatVal(self), _n); |
|
2043 |
if (! isnan(rslt)) { /* Currently all our systems support isnan() */ |
|
22578 | 2044 |
if (__threadErrno == 0) { |
2045 |
__qMKFLOAT(newFloat, rslt); |
|
2046 |
RETURN ( newFloat ); |
|
2047 |
} |
|
1 | 2048 |
} |
22578 | 2049 |
notEasy: ; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2050 |
%}. |
21913 | 2051 |
"/ the c-library pow function, has a bug: |
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
2052 |
"/ it does not deal correctly with negative numbers. |
19091 | 2053 |
"/ I.e. it raises an error on -8^(1/3) instead of returning a negative -2 |
2054 |
"/ work around with a kludge: |
|
2055 |
self < 0 ifTrue:[ |
|
22578 | 2056 |
^ (self negated raisedTo:aNumber) negated |
19091 | 2057 |
]. |
2058 |
||
21936 | 2059 |
^ aNumber raisedFromFloat:self |
2060 |
||
2061 |
"Modified: / 01-07-2017 / 21:58:26 / cg" |
|
1 | 2062 |
! |
2063 |
||
2064 |
sqrt |
|
6193 | 2065 |
"return the square root of myself. |
2066 |
Raises an exception, if the receiver is less than zero." |
|
1 | 2067 |
|
2068 |
%{ /* NOCONTEXT */ |
|
2069 |
||
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2070 |
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
|
2071 |
OBJ newFloat; |
1 | 2072 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2073 |
val = __floatVal(self); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2074 |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
2075 |
#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
|
2076 |
if (val >= 0.0) |
3889
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
2077 |
#endif |
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
2078 |
{ |
11945 | 2079 |
__threadErrno = 0; |
2080 |
rslt = sqrt(val); |
|
2081 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2082 |
{ |
|
2083 |
if (__threadErrno == 0) { |
|
2084 |
__qMKFLOAT(newFloat, rslt); |
|
2085 |
RETURN ( newFloat ); |
|
2086 |
} |
|
2087 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2088 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2089 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
2090 |
^ self class |
11945 | 2091 |
raise:#imaginaryResultSignal |
2092 |
receiver:self |
|
2093 |
selector:#sqrt |
|
2094 |
arguments:#() |
|
2095 |
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
|
2096 |
|
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
2097 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
2098 |
10 sqrt |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
2099 |
-10 sqrt |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
2100 |
" |
6193 | 2101 |
|
6195 | 2102 |
"Modified: / 16.11.2001 / 14:14:43 / cg" |
13 | 2103 |
! ! |
2104 |
||
92 | 2105 |
!Float methodsFor:'printing & storing'! |
1 | 2106 |
|
22301 | 2107 |
printOn:aStream |
2108 |
"append a printed representation of the receiver to |
|
2109 |
the argument, aStream. |
|
2110 |
||
2111 |
I use #printString instead of #printOn: as basic print mechanism." |
|
2112 |
||
2113 |
aStream nextPutAll:self printString |
|
2114 |
||
2115 |
"Created: / 10-10-2017 / 14:05:13 / cg" |
|
2116 |
! |
|
2117 |
||
1 | 2118 |
printString |
2358 | 2119 |
"return a printed representation of the receiver; |
2120 |
if not specified otherwise (by setting DefaultPrintFormat), |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
2121 |
6 valid digits are printed. |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
2122 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
2123 |
#printOn: as basic print mechanism." |
1 | 2124 |
|
21868 | 2125 |
^ self printStringWithFormat:self class defaultPrintFormat |
18138 | 2126 |
|
2127 |
" |
|
22578 | 2128 |
Float pi printString. |
2129 |
1.0 printString |
|
2130 |
1.234 printString |
|
2131 |
1e10 printString |
|
2132 |
1e-60 printString |
|
2133 |
1.2e3 printString |
|
2134 |
1.2e30 printString |
|
2135 |
(1.0 uncheckedDivide:0) printString |
|
2136 |
(0.0 uncheckedDivide:0) printString |
|
2137 |
self pi printString. |
|
2138 |
||
2139 |
DecimalPointCharacter := $,. |
|
2140 |
1.234 printString. |
|
2141 |
1.0 printString. |
|
2142 |
1e10 printString. |
|
2143 |
1.2e3 printString. |
|
2144 |
1.2e30 printString. |
|
2145 |
(1.0 uncheckedDivide:0) printString. |
|
2146 |
(0.0 uncheckedDivide:0) printString. |
|
2147 |
DecimalPointCharacter := $. |
|
18138 | 2148 |
" |
21877 | 2149 |
|
2150 |
"Modified (comment): / 21-06-2017 / 09:46:01 / cg" |
|
18138 | 2151 |
! |
2152 |
||
2153 |
printStringWithFormat:format |
|
2154 |
"return a printed representation of the receiver; |
|
2155 |
fmt must be of the form: .nn, where nn is the number of digits. |
|
2156 |
To print 6 valid digits, use printStringWithFormat:'.6' |
|
2157 |
For Floats, the default used in printString, is 15 (because its a double); |
|
2158 |
for ShortFloats, it is 6 (because it is a float)" |
|
2159 |
||
1 | 2160 |
%{ /* NOCONTEXT */ |
2161 |
||
13 | 2162 |
char buffer[64]; |
1 | 2163 |
REGISTER char *cp; |
314 | 2164 |
OBJ s; |
2358 | 2165 |
char *fmt; |
2166 |
char fmtBuffer[20]; |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2167 |
int len; |
2358 | 2168 |
|
18138 | 2169 |
if (__isStringLike(format)) { |
18296 | 2170 |
fmt = (char *) __stringVal(format); |
2358 | 2171 |
} else { |
18296 | 2172 |
/* |
2173 |
* in case we get called with garbage ... |
|
2174 |
*/ |
|
2175 |
fmt = ".15"; |
|
2358 | 2176 |
} |
2177 |
||
2178 |
/* |
|
2179 |
* build a printf format string |
|
2180 |
*/ |
|
2181 |
fmtBuffer[0] = '%'; |
|
2182 |
strncpy(fmtBuffer+1, fmt, 10); |
|
2183 |
#ifdef SYSV |
|
2184 |
strcat(fmtBuffer, "lg"); |
|
2185 |
#else |
|
2186 |
strcat(fmtBuffer, "G"); |
|
2187 |
#endif |
|
314 | 2188 |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2189 |
__BEGIN_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2190 |
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
|
2191 |
__END_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2192 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2193 |
if (len >= 0 && len < sizeof(buffer)-3) { |
18296 | 2194 |
/* |
2195 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
|
2196 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
|
2197 |
*/ |
|
2198 |
for (cp = buffer; *cp; cp++) { |
|
2199 |
if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break; |
|
2200 |
} |
|
2201 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
|
2202 |
if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
|
2203 |
*cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
|
2204 |
} else { |
|
2205 |
*cp++ = '.'; |
|
2206 |
} |
|
2207 |
*cp++ = '0'; |
|
2208 |
*cp = '\0'; |
|
2209 |
} else { |
|
2210 |
if (cp && ((*cp == '.') || (*cp == ','))) { |
|
2211 |
if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
|
2212 |
*cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
|
2213 |
} |
|
2214 |
} |
|
2215 |
} |
|
2216 |
||
2217 |
s = __MKSTRING(buffer); |
|
2218 |
if (s != nil) { |
|
2219 |
RETURN (s); |
|
2220 |
} |
|
314 | 2221 |
} |
2222 |
%}. |
|
2223 |
" |
|
2224 |
memory allocation (for the new string) failed. |
|
2225 |
When we arrive here, there was no memory, even after a garbage collect. |
|
2226 |
This means, that the VM wanted to get some more memory from the |
|
2227 |
OS, which was not kind enough to give it. |
|
2228 |
Bad luck - you should increase the swap space on your machine. |
|
2229 |
" |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20415
diff
changeset
|
2230 |
^ AllocationFailure raise. |
314 | 2231 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2232 |
" |
18296 | 2233 |
1.0 printString |
2234 |
1.234 printString |
|
2235 |
1e10 printString |
|
2236 |
1.2e3 printString |
|
2237 |
1.2e30 printString |
|
2238 |
(1.0 uncheckedDivide:0) printString |
|
2239 |
(0.0 uncheckedDivide:0) printString |
|
2240 |
self pi printString. |
|
2241 |
||
2242 |
DecimalPointCharacter := $,. |
|
2243 |
1.234 printString. |
|
2244 |
1.0 printString. |
|
2245 |
1e10 printString. |
|
2246 |
1.2e3 printString. |
|
2247 |
1.2e30 printString. |
|
2248 |
(1.0 uncheckedDivide:0) printString. |
|
2249 |
(0.0 uncheckedDivide:0) printString. |
|
2250 |
DecimalPointCharacter := $. |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2251 |
" |
1 | 2252 |
! |
2253 |
||
2254 |
printfPrintString:formatString |
|
7746 | 2255 |
"non-standard: return a printed representation of the receiver |
1 | 2256 |
as specified by formatString, which is defined by printf. |
22578 | 2257 |
|
31 | 2258 |
If you use this, be aware, that specifying doubles differs on |
11945 | 2259 |
systems; on SYSV machines you have to give something like %lf, |
13 | 2260 |
while on BSD systems the format string has to be %F. |
31 | 2261 |
Also, the resulting string may not be longer than 255 bytes - |
20415 | 2262 |
since that's the (static) size of the buffer. |
21909 | 2263 |
|
11926
295e8bb99fde
changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents:
11733
diff
changeset
|
2264 |
This method is NONSTANDARD and may be removed without notice. |
295e8bb99fde
changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents:
11733
diff
changeset
|
2265 |
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
|
2266 |
Please use the printf: method, which is safe as it is completely implemented in Smalltalk." |
1 | 2267 |
|
13 | 2268 |
%{ /* STACK: 400 */ |
1 | 2269 |
char buffer[256]; |
314 | 2270 |
OBJ s; |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2271 |
int len; |
1 | 2272 |
|
12478
e8051030cda6
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12423
diff
changeset
|
2273 |
if (__isStringLike(formatString)) { |
22578 | 2274 |
/* |
2275 |
* actually only needed on sparc: since thisContext is |
|
2276 |
* in a global register, which gets destroyed by printf, |
|
2277 |
* manually save it here - very stupid ... |
|
2278 |
*/ |
|
2279 |
__BEGIN_PROTECT_REGISTERS__ |
|
2280 |
||
2281 |
len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __floatVal(self)); |
|
2282 |
||
2283 |
__END_PROTECT_REGISTERS__ |
|
2284 |
||
2285 |
if (len < 0) goto fail; |
|
2286 |
if (len >= sizeof(buffer)) goto fail; |
|
2287 |
||
2288 |
s = __MKSTRING_L(buffer, len); |
|
2289 |
if (s != nil) { |
|
2290 |
RETURN (s); |
|
2291 |
} |
|
1 | 2292 |
} |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
2293 |
fail: ; |
314 | 2294 |
%}. |
21909 | 2295 |
^ super printfPrintString:formatString |
1 | 2296 |
|
7355 | 2297 |
" |
2298 |
Float pi printfPrintString:'%%lg -> %lg' |
|
2299 |
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
|
2300 |
Float pi printfPrintString:'%%7.15lg -> %7.15lg' |
7355 | 2301 |
Float pi printfPrintString:'%%7.5lf -> %7.5lf' |
2302 |
Float pi printfPrintString:'%%G -> %G' |
|
2303 |
Float pi printfPrintString:'%%F -> %F' |
|
2304 |
Float pi printfPrintString:'%%7.5G -> %7.5G' |
|
2305 |
Float pi printfPrintString:'%%7.5F -> %7.5F' |
|
22578 | 2306 |
|
21952 | 2307 |
Float pi printfPrintString:'%%7.5f -> %7.5f' |
2308 |
Float pi printfPrintString:'%%100.98f -> %100.98f' |
|
2309 |
Float pi printfPrintString:'%%100.6f -> %100.6f' |
|
2310 |
Float pi printfPrintString:'%%300.6f -> %300.6f' |
|
22578 | 2311 |
|
21952 | 2312 |
Float pi printfPrintString:'%%-100.98f -> %-100.98f' |
2313 |
Float pi printfPrintString:'%%300.298f -> %300.298f' |
|
2314 |
Float pi printfPrintString:'%%-300.298f -> %-300.298f' |
|
2315 |
||
2316 |
Float pi printfPrintString:'%%100.6f -> <%100.6f>' |
|
2317 |
Float pi printfPrintString:'%%300.6f -> <%300.6f>' |
|
2318 |
||
2319 |
Float pi printfPrintString:'%%100.6f -> <%100.6>' |
|
2320 |
Float pi printfPrintString:'%%300.6f -> <%300.6>' |
|
7355 | 2321 |
" |
21909 | 2322 |
|
21952 | 2323 |
"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
|
2324 |
! |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2325 |
|
22301 | 2326 |
storeOn:aStream |
2327 |
"append a printed representation of the receiver to |
|
2328 |
the argument, aStream. |
|
2329 |
||
2330 |
I use #storeString instead of #storeOn: as basic store mechanism." |
|
2331 |
||
2332 |
aStream nextPutAll:self storeString |
|
2333 |
||
2334 |
"Created: / 10-10-2017 / 14:06:39 / cg" |
|
2335 |
! |
|
2336 |
||
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2337 |
storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2338 |
"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
|
2339 |
all valid digits are printed. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2340 |
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
|
2341 |
#storeOn: as basic print mechanism." |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2342 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2343 |
%{ /* NOCONTEXT */ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2344 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2345 |
char buffer[64]; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2346 |
REGISTER char *cp; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2347 |
OBJ s; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2348 |
int len; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2349 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2350 |
__BEGIN_PROTECT_REGISTERS__ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2351 |
#ifdef SYSV |
16658 | 2352 |
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
|
2353 |
#else |
16658 | 2354 |
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
|
2355 |
#endif |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2356 |
__END_PROTECT_REGISTERS__ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2357 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2358 |
if (len >= 0 && len < sizeof(buffer)-3) { |
17199 | 2359 |
/* |
2360 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
|
2361 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
|
2362 |
*/ |
|
2363 |
for (cp = buffer; *cp; cp++) { |
|
2364 |
if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break; |
|
2365 |
} |
|
2366 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
|
2367 |
*cp++ = '.'; |
|
2368 |
*cp++ = '0'; |
|
2369 |
*cp = '\0'; |
|
2370 |
} |
|
2371 |
||
2372 |
s = __MKSTRING(buffer); |
|
2373 |
if (s != nil) { |
|
2374 |
RETURN (s); |
|
2375 |
} |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2376 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2377 |
%}. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2378 |
" |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2379 |
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
|
2380 |
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
|
2381 |
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
|
2382 |
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
|
2383 |
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
|
2384 |
" |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20415
diff
changeset
|
2385 |
^ AllocationFailure raise. |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2386 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2387 |
" |
17199 | 2388 |
1.0 storeString |
2389 |
0.1 storeString |
|
2390 |
((Array new:10 withAll:0.1) inject:0 into:[:v :sumSoFar| sumSoFar + v]) storeString |
|
2391 |
1.234 storeString |
|
2392 |
1e10 storeString |
|
2393 |
1.2e3 storeString |
|
2394 |
1.2e30 storeString |
|
2395 |
Float pi storeString |
|
2396 |
(1.0 uncheckedDivide:0) storeString |
|
2397 |
(0.0 uncheckedDivide:0) storeString |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2398 |
|
9124 | 2399 |
notice that the storeString is NOT affected by DecimalPointCharacterForPrinting: |
2400 |
||
17199 | 2401 |
DecimalPointCharacterForPrinting := $,. |
2402 |
1.234 storeString. |
|
2403 |
1.0 storeString. |
|
2404 |
1e10 storeString. |
|
2405 |
1.2e3 storeString. |
|
2406 |
1.2e30 storeString. |
|
2407 |
(1.0 uncheckedDivide:0) storeString. |
|
2408 |
(0.0 uncheckedDivide:0) storeString. |
|
2409 |
DecimalPointCharacterForPrinting := $. |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
2410 |
" |
1 | 2411 |
! ! |
701 | 2412 |
|
11926
295e8bb99fde
changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents:
11733
diff
changeset
|
2413 |
|
7258 | 2414 |
!Float methodsFor:'private-accessing'! |
701 | 2415 |
|
2416 |
basicAt:index |
|
2417 |
"return an internal byte of the float. |
|
2418 |
The value returned here depends on byte order, float representation etc. |
|
2419 |
Therefore, this method should be used strictly private. |
|
2420 |
||
11945 | 2421 |
Notice: |
2422 |
the need to redefine this method here is due to the |
|
2423 |
inability of many machines to store floats in non-double aligned memory. |
|
2424 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
2425 |
and the actual float is stored at index 5 .. 12. |
|
2426 |
To hide this at one place, this method knows about that, and returns |
|
2427 |
values as if this filler wasnt present." |
|
701 | 2428 |
|
2429 |
%{ /* NOCONTEXT */ |
|
2430 |
||
2431 |
register int indx; |
|
2432 |
unsigned char *cp; |
|
2433 |
||
2434 |
/* |
|
2435 |
* notice the missing test for self being a nonNilObject - |
|
2436 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
2437 |
* and SmallInteger |
|
2438 |
*/ |
|
2439 |
if (__isSmallInteger(index)) { |
|
11945 | 2440 |
indx = __intVal(index) - 1; |
2441 |
if (((unsigned)(indx)) < sizeof(double)) { |
|
2442 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
|
2443 |
RETURN ( __mkSmallInteger(cp[indx] & 0xFF) ); |
|
2444 |
} |
|
701 | 2445 |
} |
2446 |
%}. |
|
7217 | 2447 |
^ self indexNotIntegerOrOutOfBounds:index |
701 | 2448 |
! |
2449 |
||
2450 |
basicAt:index put:value |
|
2451 |
"set an internal byte of the float. |
|
2452 |
The value to be stored here depends on byte order, float representation etc. |
|
2453 |
Therefore, this method should be used strictly private. |
|
2454 |
||
11945 | 2455 |
Notice: |
2456 |
the need to redefine this method here is due to the |
|
2457 |
inability of many machines to store floats in non-double aligned memory. |
|
2458 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
2459 |
and the actual float is stored at index 5 .. 12. |
|
2460 |
To hide this at one place, this method knows about that, and returns |
|
2461 |
values as if this filler wasnt present." |
|
701 | 2462 |
|
2463 |
%{ /* NOCONTEXT */ |
|
2464 |
register int indx, val; |
|
2465 |
unsigned char *cp; |
|
2466 |
||
2467 |
/* |
|
2468 |
* notice the missing test for self being a nonNilObject - |
|
2469 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
2470 |
* and SmallInteger |
|
2471 |
*/ |
|
2472 |
if (__bothSmallInteger(index, value)) { |
|
11945 | 2473 |
val = __intVal(value); |
2474 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
2475 |
indx = __intVal(index) - 1; |
|
2476 |
if (((unsigned)(indx)) < sizeof(double)) { |
|
2477 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
|
2478 |
cp[indx] = val; |
|
2479 |
RETURN ( value ); |
|
2480 |
} |
|
2481 |
} |
|
701 | 2482 |
} |
2483 |
%}. |
|
2484 |
value isInteger ifFalse:[ |
|
11945 | 2485 |
" |
2486 |
the object to store should be an integer number |
|
2487 |
" |
|
2488 |
^ self elementNotInteger |
|
701 | 2489 |
]. |
2490 |
(value between:0 and:255) ifFalse:[ |
|
11945 | 2491 |
" |
2492 |
the object to store must be a bytes value |
|
2493 |
" |
|
2494 |
^ self elementBoundsError:value |
|
701 | 2495 |
]. |
7217 | 2496 |
^ self indexNotIntegerOrOutOfBounds:index |
16658 | 2497 |
! |
4592 | 2498 |
|
2499 |
basicSize |
|
2500 |
"return the size in bytes of the float. |
|
2501 |
||
11945 | 2502 |
Notice: |
17199 | 2503 |
the need to redefine this method here is due to the |
2504 |
inability of many machines to store floats in non-double aligned memory. |
|
2505 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
2506 |
and the actual float is stored at index 5 .. 12. |
|
2507 |
To hide this at one place, this method knows about that, and returns |
|
2508 |
values as if this filler wasn't present." |
|
4592 | 2509 |
|
2510 |
%{ /* NOCONTEXT */ |
|
2511 |
||
8913 | 2512 |
RETURN (__mkSmallInteger(sizeof(double))); |
4592 | 2513 |
%}. |
22260 | 2514 |
! |
2515 |
||
2516 |
byteAt:index |
|
2517 |
^ self basicAt:index |
|
2518 |
! |
|
2519 |
||
2520 |
byteAt:index put:newByte |
|
2521 |
self shouldNotImplement |
|
701 | 2522 |
! ! |
2523 |
||
16658 | 2524 |
!Float methodsFor:'queries'! |
2525 |
||
2526 |
nextFloat:count |
|
2527 |
"answer the next float count places after (or before if count is negative) myself" |
|
2528 |
||
2529 |
%{ |
|
2530 |
union { |
|
17199 | 2531 |
double d; |
2532 |
INT64 i; |
|
16658 | 2533 |
} this; |
2534 |
||
2535 |
if (__isSmallInteger(count)) { |
|
17199 | 2536 |
this.d = __floatVal(self); |
2537 |
if (isfinite(this.d)) |
|
2538 |
this.i += __intVal(count); |
|
2539 |
||
2540 |
RETURN(__MKFLOAT(this.d)); |
|
16658 | 2541 |
} |
2542 |
%}. |
|
2543 |
self primitiveFailed:#badArgument |
|
2544 |
||
2545 |
" |
|
2546 |
(1.0 nextFloat:1) storeString |
|
2547 |
(67329.234 nextFloat:1) storeString |
|
2548 |
(67329.234 asShortFloat nextFloat:1) storeString |
|
2549 |
Float NaN nextFloat:100000 |
|
2550 |
Float infinity nextFloat:100000 |
|
2551 |
" |
|
2552 |
! ! |
|
2553 |
||
3896 | 2554 |
!Float methodsFor:'special access'! |
2555 |
||
2556 |
exponent |
|
21849 | 2557 |
"extract a normalized float's exponent. |
3896 | 2558 |
The returned value depends on the float-representation of |
2559 |
the underlying machine and is therefore highly unportable. |
|
2560 |
This is not for general use. |
|
2561 |
This assumes that the mantissa is normalized to |
|
12423 | 2562 |
0.5 .. 1.0 and the float's value is: mantissa * 2^exp" |
3896 | 2563 |
|
2564 |
%{ /* NOCONTEXT */ |
|
21849 | 2565 |
double myVal; |
3896 | 2566 |
double frac; |
8913 | 2567 |
int exp; |
3896 | 2568 |
|
21849 | 2569 |
myVal = __floatVal(self); |
2570 |
// ouch: math libs seem to not care for NaN here; |
|
2571 |
#if 1 |
|
2572 |
// should we? |
|
2573 |
if (! (isnan(myVal) || isinf(myVal))) |
|
2574 |
#endif |
|
2575 |
{ |
|
21868 | 2576 |
frac = frexp(myVal, &exp); |
2577 |
RETURN (__mkSmallInteger(exp)); |
|
21849 | 2578 |
} |
3896 | 2579 |
%}. |
21849 | 2580 |
^ super exponent |
3896 | 2581 |
|
2582 |
" |
|
14672
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2583 |
1.0 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2584 |
2.0 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2585 |
3.0 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2586 |
4.0 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2587 |
0.5 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2588 |
0.4 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2589 |
0.25 exponent |
8abd84f0951a
setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents:
14630
diff
changeset
|
2590 |
0.2 exponent |
11945 | 2591 |
0.00000011111 exponent |
21849 | 2592 |
0.0 exponent |
2593 |
1e1000 exponent |
|
3896 | 2594 |
" |
21849 | 2595 |
|
2596 |
"Modified: / 20-06-2017 / 11:34:43 / cg" |
|
3896 | 2597 |
! |
2598 |
||
2599 |
mantissa |
|
24152 | 2600 |
"extract a normalized float's mantissa. |
3896 | 2601 |
The returned value depends on the float-representation of |
2602 |
the underlying machine and is therefore highly unportable. |
|
2603 |
This is not for general use. |
|
2604 |
This assumes that the mantissa is normalized to |
|
24152 | 2605 |
0.5 .. 1.0 and the float's value is mantissa * 2^exp" |
3896 | 2606 |
|
2607 |
%{ /* NOCONTEXT */ |
|
21849 | 2608 |
double myVal; |
3896 | 2609 |
double frac; |
8913 | 2610 |
int exp; |
3896 | 2611 |
|
21849 | 2612 |
myVal = __floatVal(self); |
2613 |
// ouch: math libs seem to not care for NaN here; |
|
2614 |
#if 1 |
|
2615 |
// should we? |
|
2616 |
if (! (isnan(myVal) || isinf(myVal))) |
|
2617 |
#endif |
|
2618 |
{ |
|
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
2619 |
frac = frexp(myVal, &exp); |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
2620 |
RETURN (__MKFLOAT(frac)); |
21868 | 2621 |
} |
3896 | 2622 |
%}. |
20009 | 2623 |
^ super mantissa |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20415
diff
changeset
|
2624 |
|
3896 | 2625 |
" |
11945 | 2626 |
1.0 exponent |
2627 |
1.0 mantissa |
|
2628 |
||
2629 |
0.25 exponent |
|
2630 |
0.25 mantissa |
|
2631 |
||
2632 |
0.00000011111 exponent |
|
2633 |
0.00000011111 mantissa |
|
21849 | 2634 |
|
2635 |
1e1000 mantissa |
|
3896 | 2636 |
" |
21849 | 2637 |
|
2638 |
"Modified: / 20-06-2017 / 11:37:13 / cg" |
|
24152 | 2639 |
"Modified (comment): / 26-05-2019 / 03:12:55 / Claus Gittinger" |
3896 | 2640 |
! ! |
2641 |
||
701 | 2642 |
!Float methodsFor:'testing'! |
2643 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2644 |
isFinite |
11945 | 2645 |
"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
|
2646 |
i.e. not NaN and not infinite." |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2647 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2648 |
%{ /* NOCONTEXT */ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2649 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
2650 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
2651 |
* notice: on machines which do not provide |
11945 | 2652 |
* a finite() macro or function (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
2653 |
* 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
|
2654 |
*/ |
17384 | 2655 |
RETURN (isfinite(__floatVal(self)) ? true : false) |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2656 |
%}. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2657 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2658 |
" |
18296 | 2659 |
1.0 isFinite |
2660 |
self NaN isFinite |
|
2661 |
self infinity isFinite |
|
2662 |
(0.0 uncheckedDivide: 0.0) isFinite |
|
2663 |
(1.0 uncheckedDivide: 0.0) isFinite |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2664 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2665 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2666 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2667 |
isInfinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2668 |
"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
|
2669 |
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
|
2670 |
however, inline C-code could produce them ... |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2671 |
Redefined here for speed" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2672 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2673 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2674 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2675 |
double dV = __floatVal(self); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2676 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
2677 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
2678 |
* notice: on machines which do not provide |
11945 | 2679 |
* finite() & isnan() macros or functions (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
2680 |
* 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
|
2681 |
*/ |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2682 |
#if defined(isinf) |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2683 |
if (isinf(dV)) { RETURN (true); } |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2684 |
#else |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
2685 |
if (!isfinite(dV) && !isnan(dV)) { RETURN (true); } |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2686 |
#endif |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2687 |
%}. |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2688 |
^ false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2689 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2690 |
" |
11945 | 2691 |
1.0 isInfinite |
2692 |
(0.0 uncheckedDivide: 0.0) isInfinite |
|
2693 |
(1.0 uncheckedDivide: 0.0) isInfinite |
|
2694 |
(-1.0 uncheckedDivide: 0.0) isInfinite |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2695 |
" |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2696 |
! |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2697 |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2698 |
isLiteral |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2699 |
"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
|
2700 |
(i.e. can be used in constant arrays)" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2701 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2702 |
^ true |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2703 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2704 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2705 |
! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2706 |
|
2387 | 2707 |
isNaN |
2708 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
2709 |
These are not created by ST/X float operations (they raise an exception); |
|
2710 |
however, inline C-code could produce them ..." |
|
2711 |
||
2712 |
%{ /* NOCONTEXT */ |
|
2713 |
||
17384 | 2714 |
RETURN (isnan(__floatVal(self)) ? true : false) |
2392 | 2715 |
%}. |
3139 | 2716 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2717 |
" |
18296 | 2718 |
self NaN isNaN |
2719 |
1.0 isNaN |
|
2720 |
(0.0 uncheckedDivide: 0.0) isNaN |
|
2721 |
(1.0 uncheckedDivide: 0.0) isNaN |
|
2722 |
(-1.0 uncheckedDivide: 0.0) isNaN |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
2723 |
" |
2387 | 2724 |
! |
2725 |
||
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2726 |
isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2727 |
"many systems have two float.Pnt zeros" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2728 |
|
18296 | 2729 |
%{ /* NOCONTEXT */ |
17389 | 2730 |
|
17392 | 2731 |
#if defined(__BORLANDC__) |
2732 |
union { double d; int i[2]; } __u; |
|
2733 |
__u.d = __floatVal(self); |
|
2734 |
RETURN ( (__u.d == 0.0 && __u.i[1] < 0) ? true : false ); |
|
17389 | 2735 |
#else |
17384 | 2736 |
RETURN ( (__floatVal(self) == 0.0 && signbit(__floatVal(self)) != 0) ? true : false ); |
17389 | 2737 |
#endif |
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2738 |
%}. |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2739 |
|
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2740 |
" |
11945 | 2741 |
0.0 isNegativeZero |
2742 |
-0.0 isNegativeZero |
|
2743 |
-1.0 isNegativeZero |
|
2744 |
1.0 isNegativeZero |
|
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2745 |
" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2746 |
! |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2747 |
|
701 | 2748 |
negative |
17384 | 2749 |
"return true if the receiver is less than zero. |
2750 |
-0.0 is positive for now." |
|
701 | 2751 |
|
2752 |
%{ /* NOCONTEXT */ |
|
2753 |
||
17384 | 2754 |
RETURN ( __floatVal(self) < 0.0 ? true : false ); |
2755 |
// RETURN ( signbit(__floatVal(self)) != 0 ? true : false ); |
|
5411 | 2756 |
%}. |
17384 | 2757 |
|
2758 |
" |
|
18296 | 2759 |
0.0 negative |
2760 |
-0.0 negative |
|
2761 |
1.0 negative |
|
2762 |
-1.0 negative |
|
2763 |
(1.0 uncheckedDivide: 0.0) negative |
|
2764 |
(-1.0 uncheckedDivide: 0.0) negative |
|
17384 | 2765 |
" |
701 | 2766 |
! |
2767 |
||
5357 | 2768 |
numberOfBits |
2769 |
"return the size (in bits) of the real; |
|
2770 |
typically, 64 is returned here, |
|
2771 |
but who knows ..." |
|
2772 |
||
2773 |
%{ /* NOCONTEXT */ |
|
2774 |
||
8913 | 2775 |
RETURN (__mkSmallInteger (sizeof(double) * 8)); |
5357 | 2776 |
%} |
2777 |
||
2778 |
" |
|
11945 | 2779 |
1.2 numberOfBits |
2780 |
1.2 asShortFloat numberOfBits |
|
5357 | 2781 |
" |
2782 |
! |
|
2783 |
||
701 | 2784 |
positive |
18857 | 2785 |
"return true if the receiver is greater or equal to zero (not negative). |
17384 | 2786 |
0.0 and -0.0 are positive for now." |
701 | 2787 |
|
2788 |
%{ /* NOCONTEXT */ |
|
2789 |
||
17384 | 2790 |
RETURN ( __floatVal(self) >= 0.0 ? true : false ); |
2791 |
// RETURN ( signbit(__floatVal(self)) == 0 ? true : false ); |
|
2792 |
%}. |
|
2793 |
||
2794 |
" |
|
19570
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
2795 |
0.0 positive |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
2796 |
-0.0 positive |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
2797 |
1.0 positive |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
2798 |
-1.0 positive |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
2799 |
(1.0 uncheckedDivide: 0.0) positive |
017c53457288
lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents:
19358
diff
changeset
|
2800 |
(-1.0 uncheckedDivide: 0.0) positive |
17384 | 2801 |
" |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2802 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2803 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2804 |
strictlyPositive |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2805 |
"return true if the receiver is greater than zero" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2806 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2807 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2808 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2809 |
RETURN ( (__floatVal(self) > 0.0) ? true : false ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2810 |
%} |
701 | 2811 |
! ! |
2812 |
||
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2813 |
!Float methodsFor:'tracing'! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2814 |
|
4682 | 2815 |
traceInto:aRequestor level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2816 |
"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
|
2817 |
|
4682 | 2818 |
^ aRequestor traceFloat:self level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2819 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2820 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2821 |
! ! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
2822 |
|
7385 | 2823 |
!Float methodsFor:'trigonometric'! |
2824 |
||
2825 |
arcCos |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2826 |
"return the arccosine of the receiver (as radians). |
7385 | 2827 |
Raises an exception, if the receiver is not in -1..1" |
2828 |
||
2829 |
%{ /* NOCONTEXT */ |
|
18296 | 2830 |
#ifdef __SCHTEAM__ |
18299 | 2831 |
return context._RETURN( self.acos() ); |
18296 | 2832 |
#else |
7385 | 2833 |
|
2834 |
double val, rslt; |
|
2835 |
OBJ newFloat; |
|
2836 |
||
2837 |
val = __floatVal(self); |
|
2838 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
2839 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7385 | 2840 |
if ((val >= -1.0) && (val <= 1.0)) |
18296 | 2841 |
# endif |
7385 | 2842 |
{ |
11945 | 2843 |
__threadErrno = 0; |
2844 |
rslt = acos(val); |
|
2845 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2846 |
{ |
|
2847 |
if (__threadErrno == 0) { |
|
2848 |
__qMKFLOAT(newFloat, rslt); |
|
2849 |
RETURN ( newFloat ); |
|
2850 |
} |
|
2851 |
} |
|
7385 | 2852 |
} |
18296 | 2853 |
#endif |
7385 | 2854 |
%}. |
2855 |
^ self class |
|
11945 | 2856 |
raise:#domainErrorSignal |
2857 |
receiver:self |
|
2858 |
selector:#arcCos |
|
2859 |
arguments:#() |
|
2860 |
errorString:'bad receiver in arcCos' |
|
7385 | 2861 |
|
2862 |
" |
|
2863 |
-10 arcCos |
|
11945 | 2864 |
1 arcCos |
7385 | 2865 |
" |
2866 |
||
2867 |
"Modified: / 16.11.2001 / 14:14:13 / cg" |
|
2868 |
! |
|
2869 |
||
2870 |
arcCosh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2871 |
"return the hyperbolic arccosine of the receiver." |
7385 | 2872 |
|
7410 | 2873 |
|useFallBack| |
2874 |
||
2875 |
%{ |
|
2876 |
#ifdef NO_ACOSH |
|
2877 |
useFallBack = true; |
|
2878 |
#else |
|
7385 | 2879 |
double val, rslt; |
2880 |
OBJ newFloat; |
|
2881 |
||
2882 |
val = __floatVal(self); |
|
2883 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
2884 |
# 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
|
2885 |
if (val >= 1.0) |
7410 | 2886 |
# endif |
7385 | 2887 |
{ |
11945 | 2888 |
__threadErrno = 0; |
2889 |
rslt = acosh(val); |
|
2890 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2891 |
{ |
|
2892 |
if (__threadErrno == 0) { |
|
2893 |
__qMKFLOAT(newFloat, rslt); |
|
2894 |
RETURN ( newFloat ); |
|
2895 |
} |
|
2896 |
} |
|
7385 | 2897 |
} |
7410 | 2898 |
#endif |
7385 | 2899 |
%}. |
7410 | 2900 |
useFallBack notNil ifTrue:[ |
2901 |
^ super arcCosh |
|
2902 |
]. |
|
2903 |
||
7385 | 2904 |
^ self class |
11945 | 2905 |
raise:#domainErrorSignal |
2906 |
receiver:self |
|
2907 |
selector:#arcCosh |
|
2908 |
arguments:#() |
|
2909 |
errorString:'bad receiver in arcCosh' |
|
7385 | 2910 |
|
2911 |
" |
|
2912 |
-10.0 arcCosh |
|
11945 | 2913 |
1.0 arcCosh |
7385 | 2914 |
" |
2915 |
||
2916 |
"Modified: / 16.11.2001 / 14:14:13 / cg" |
|
2917 |
! |
|
2918 |
||
2919 |
arcSin |
|
2920 |
"return the arcsine of myself (I am interpreted as radians). |
|
2921 |
Raises an exception, if the receiver is not in -1..1" |
|
2922 |
||
2923 |
%{ /* NOCONTEXT */ |
|
18296 | 2924 |
#ifdef __SCHTEAM__ |
18299 | 2925 |
return context._RETURN( self.asin() ); |
18296 | 2926 |
#else |
7385 | 2927 |
|
2928 |
double val, rslt; |
|
2929 |
OBJ newFloat; |
|
2930 |
||
2931 |
val = __floatVal(self); |
|
2932 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
2933 |
# ifdef __win32__ /* to suppress the warnBox opened by win32 */ |
7385 | 2934 |
if ((val >= -1.0) && (val <= 1.0)) |
18296 | 2935 |
# endif |
7385 | 2936 |
{ |
11945 | 2937 |
__threadErrno = 0; |
2938 |
rslt = asin(val); |
|
2939 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2940 |
{ |
|
2941 |
if (__threadErrno == 0) { |
|
2942 |
__qMKFLOAT(newFloat, rslt); |
|
2943 |
RETURN ( newFloat ); |
|
2944 |
} |
|
2945 |
} |
|
7385 | 2946 |
} |
18296 | 2947 |
#endif |
7385 | 2948 |
%}. |
2949 |
^ self class |
|
11945 | 2950 |
raise:#domainErrorSignal |
2951 |
receiver:self |
|
2952 |
selector:#arcSin |
|
2953 |
arguments:#() |
|
2954 |
errorString:'bad receiver in arcSin' |
|
7385 | 2955 |
|
2956 |
" |
|
2957 |
-10 arcSin |
|
11945 | 2958 |
1 arcSin |
7385 | 2959 |
" |
2960 |
||
2961 |
"Modified: / 16.11.2001 / 14:14:18 / cg" |
|
2962 |
! |
|
2963 |
||
2964 |
arcSinh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2965 |
"return the hyperbolic arcsine of the receiver." |
7385 | 2966 |
|
7410 | 2967 |
|useFallBack| |
2968 |
%{ |
|
2969 |
#ifdef NO_ASINH |
|
2970 |
useFallBack = true; |
|
2971 |
#else |
|
7385 | 2972 |
double val, rslt; |
2973 |
OBJ newFloat; |
|
2974 |
||
2975 |
val = __floatVal(self); |
|
2976 |
||
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
2977 |
# 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
|
2978 |
if (val >= 1.0) |
7410 | 2979 |
# endif |
7385 | 2980 |
{ |
11945 | 2981 |
__threadErrno = 0; |
2982 |
rslt = asinh(val); |
|
2983 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
2984 |
{ |
|
2985 |
if (__threadErrno == 0) { |
|
2986 |
__qMKFLOAT(newFloat, rslt); |
|
2987 |
RETURN ( newFloat ); |
|
2988 |
} |
|
2989 |
} |
|
7385 | 2990 |
} |
7410 | 2991 |
#endif |
7385 | 2992 |
%}. |
7410 | 2993 |
useFallBack notNil ifTrue:[ |
2994 |
^ super arcSinh |
|
2995 |
]. |
|
7385 | 2996 |
^ self class |
11945 | 2997 |
raise:#domainErrorSignal |
2998 |
receiver:self |
|
2999 |
selector:#arcSinh |
|
3000 |
arguments:#() |
|
3001 |
errorString:'bad receiver in arcSinh' |
|
7385 | 3002 |
|
3003 |
" |
|
3004 |
-10.0 arcSinh |
|
11945 | 3005 |
1.0 arcSinh |
7385 | 3006 |
" |
3007 |
! |
|
3008 |
||
3009 |
arcTan |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3010 |
"return the arctangent of the receiver (as radians)" |
7385 | 3011 |
|
3012 |
%{ /* NOCONTEXT */ |
|
18296 | 3013 |
#ifdef __SCHTEAM__ |
18299 | 3014 |
return context._RETURN( self.atan() ); |
18296 | 3015 |
#else |
7385 | 3016 |
|
3017 |
double rslt; |
|
3018 |
OBJ newFloat; |
|
3019 |
||
3020 |
__threadErrno = 0; |
|
3021 |
rslt = atan(__floatVal(self)); |
|
7393 | 3022 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3023 |
{ |
|
11945 | 3024 |
if (__threadErrno == 0) { |
3025 |
__qMKFLOAT(newFloat, rslt); |
|
3026 |
RETURN ( newFloat ); |
|
3027 |
} |
|
7385 | 3028 |
} |
18296 | 3029 |
#endif |
7385 | 3030 |
%}. |
3031 |
^ self class |
|
11945 | 3032 |
raise:#domainErrorSignal |
3033 |
receiver:self |
|
3034 |
selector:#arcTan |
|
3035 |
arguments:#() |
|
3036 |
errorString:'bad receiver in arcTan' |
|
7385 | 3037 |
|
3038 |
"Modified: / 16.11.2001 / 14:14:22 / cg" |
|
3039 |
! |
|
3040 |
||
11487 | 3041 |
arcTan2:x |
3042 |
"return the atan2(self,x)" |
|
3043 |
||
3044 |
%{ /* NOCONTEXT */ |
|
3045 |
||
3046 |
double rslt; |
|
3047 |
OBJ newFloat; |
|
3048 |
||
3049 |
if (__isFloat(x)) { |
|
11945 | 3050 |
__threadErrno = 0; |
3051 |
rslt = atan2(__floatVal(self),__floatVal(x)); |
|
3052 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
|
3053 |
{ |
|
3054 |
if (__threadErrno == 0) { |
|
3055 |
__qMKFLOAT(newFloat, rslt); |
|
3056 |
RETURN ( newFloat ); |
|
3057 |
} |
|
3058 |
} |
|
11487 | 3059 |
} |
3060 |
%}. |
|
3061 |
x isFloat ifFalse:[ |
|
11945 | 3062 |
^ self arcTan2:(x asFloat). |
11487 | 3063 |
]. |
3064 |
||
3065 |
^ self class |
|
11945 | 3066 |
raise:#domainErrorSignal |
3067 |
receiver:self |
|
3068 |
selector:#arcTan2: |
|
3069 |
arguments:(Array with:x) |
|
3070 |
errorString:'bad receiver in arcTan2:' |
|
11487 | 3071 |
! |
3072 |
||
10604 | 3073 |
arcTan: denominator |
22728 | 3074 |
"Evaluate the four quadrant arc tangent of the argument denominator (x) and the receiver (y)." |
3075 |
||
11945 | 3076 |
(self = 0.0) ifTrue: [ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3077 |
(denominator > 0.0) |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3078 |
ifTrue: [ ^ 0 ] |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3079 |
ifFalse: [ ^ Pi ] |
10604 | 3080 |
]. |
11945 | 3081 |
(denominator = 0.0) ifTrue: [ |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3082 |
(self > 0.0) |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3083 |
ifTrue: [ ^ Halfpi ] |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3084 |
ifFalse: [ ^ HalfpiNegative ] |
10604 | 3085 |
]. |
11945 | 3086 |
(denominator > 0) |
24249
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3087 |
ifTrue: [ ^ (self / denominator) arcTan ] |
17326e1df17f
raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents:
24230
diff
changeset
|
3088 |
ifFalse: [ ^ ((self / denominator) arcTan) + Pi ] |
10604 | 3089 |
|
3090 |
"Created: / 07-06-2007 / 21:10:32 / cg" |
|
3091 |
"Modified: / 11-06-2007 / 12:58:34 / cg" |
|
3092 |
! |
|
3093 |
||
7385 | 3094 |
arcTanh |
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3095 |
"return the hyperbolic arctangent of the receiver." |
7385 | 3096 |
|
7410 | 3097 |
|useFallBack| |
3098 |
%{ |
|
3099 |
#ifdef NO_ATANH |
|
3100 |
useFallBack = true; |
|
3101 |
#else |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3102 |
double val, rslt; |
7385 | 3103 |
OBJ newFloat; |
3104 |
||
3105 |
__threadErrno = 0; |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3106 |
val = __floatVal(self); |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
3107 |
# 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
|
3108 |
if ((val >= -1.0) && (val <= 1.0)) |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3109 |
# endif |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3110 |
{ |
22578 | 3111 |
rslt = atanh(val); |
3112 |
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
|
3113 |
# ifdef __osx__ |
22578 | 3114 |
if (! isinf(rslt)) |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19616
diff
changeset
|
3115 |
# endif |
22578 | 3116 |
{ |
3117 |
if (__threadErrno == 0) { |
|
3118 |
__qMKFLOAT(newFloat, rslt); |
|
3119 |
RETURN ( newFloat ); |
|
3120 |
} |
|
3121 |
} |
|
7385 | 3122 |
} |
7410 | 3123 |
#endif |
7385 | 3124 |
%}. |
7410 | 3125 |
useFallBack notNil ifTrue:[ |
22578 | 3126 |
^ super arcTanh |
7410 | 3127 |
]. |
7385 | 3128 |
^ self class |
22578 | 3129 |
raise:#domainErrorSignal |
3130 |
receiver:self |
|
3131 |
selector:#arcTanh |
|
3132 |
arguments:#() |
|
3133 |
errorString:'bad receiver in arcTanh' |
|
7385 | 3134 |
! |
3135 |
||
3136 |
cos |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3137 |
"return the cosine of the receiver (interpreted as radians)" |
7385 | 3138 |
|
3139 |
%{ /* NOCONTEXT */ |
|
18296 | 3140 |
#ifdef __SCHTEAM__ |
18299 | 3141 |
return context._RETURN( self.cos() ); |
18296 | 3142 |
#else |
7385 | 3143 |
|
3144 |
double rslt; |
|
3145 |
OBJ newFloat; |
|
3146 |
||
3147 |
__threadErrno = 0; |
|
3148 |
rslt = cos(__floatVal(self)); |
|
7393 | 3149 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3150 |
{ |
|
11945 | 3151 |
if (__threadErrno == 0) { |
3152 |
__qMKFLOAT(newFloat, rslt); |
|
3153 |
RETURN ( newFloat ); |
|
3154 |
} |
|
7385 | 3155 |
} |
18296 | 3156 |
#endif |
7385 | 3157 |
%}. |
3158 |
^ self class |
|
11945 | 3159 |
raise:#domainErrorSignal |
3160 |
receiver:self |
|
3161 |
selector:#cos |
|
3162 |
arguments:#() |
|
3163 |
errorString:'bad receiver in cos' |
|
7385 | 3164 |
|
3165 |
"Modified: / 16.11.2001 / 14:14:26 / cg" |
|
3166 |
! |
|
3167 |
||
3168 |
cosh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3169 |
"return the hyperbolic cosine of the receiver" |
7385 | 3170 |
|
3171 |
%{ /* NOCONTEXT */ |
|
18296 | 3172 |
#ifdef __SCHTEAM__ |
18299 | 3173 |
return context._RETURN( self.cosh() ); |
18296 | 3174 |
#else |
7385 | 3175 |
|
3176 |
double rslt; |
|
3177 |
OBJ newFloat; |
|
3178 |
||
3179 |
__threadErrno = 0; |
|
3180 |
rslt = cosh(__floatVal(self)); |
|
7393 | 3181 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3182 |
{ |
|
11945 | 3183 |
if (__threadErrno == 0) { |
3184 |
__qMKFLOAT(newFloat, rslt); |
|
3185 |
RETURN ( newFloat ); |
|
3186 |
} |
|
7385 | 3187 |
} |
18296 | 3188 |
#endif |
7385 | 3189 |
%}. |
3190 |
^ self class |
|
11945 | 3191 |
raise:#domainErrorSignal |
3192 |
receiver:self |
|
3193 |
selector:#cosh |
|
3194 |
arguments:#() |
|
3195 |
errorString:'bad receiver in cosh' |
|
7385 | 3196 |
! |
3197 |
||
3198 |
sin |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3199 |
"return the sine of the receiver (interpreted as radians)" |
7385 | 3200 |
|
3201 |
%{ /* NOCONTEXT */ |
|
18296 | 3202 |
#ifdef __SCHTEAM__ |
18299 | 3203 |
return context._RETURN( self.sin() ); |
18296 | 3204 |
#else |
7385 | 3205 |
|
3206 |
double rslt; |
|
3207 |
OBJ newFloat; |
|
3208 |
||
3209 |
__threadErrno = 0; |
|
3210 |
rslt = sin(__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:#sin |
|
3224 |
arguments:#() |
|
3225 |
errorString:'bad receiver in sin' |
|
7385 | 3226 |
|
3227 |
"Modified: / 16.11.2001 / 14:14:37 / cg" |
|
3228 |
! |
|
3229 |
||
3230 |
sinh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3231 |
"return the hyperbolic sine of the receiver" |
7385 | 3232 |
|
3233 |
%{ /* NOCONTEXT */ |
|
18296 | 3234 |
#ifdef __SCHTEAM__ |
18299 | 3235 |
return context._RETURN( self.sinh() ); |
18296 | 3236 |
#else |
7385 | 3237 |
|
3238 |
double rslt; |
|
3239 |
OBJ newFloat; |
|
3240 |
||
3241 |
__threadErrno = 0; |
|
3242 |
rslt = sinh(__floatVal(self)); |
|
7393 | 3243 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3244 |
{ |
|
11945 | 3245 |
if (__threadErrno == 0) { |
3246 |
__qMKFLOAT(newFloat, rslt); |
|
3247 |
RETURN ( newFloat ); |
|
3248 |
} |
|
7385 | 3249 |
} |
18296 | 3250 |
#endif |
7385 | 3251 |
%}. |
3252 |
^ self class |
|
11945 | 3253 |
raise:#domainErrorSignal |
3254 |
receiver:self |
|
3255 |
selector:#sinh |
|
3256 |
arguments:#() |
|
3257 |
errorString:'bad receiver in sinh' |
|
7385 | 3258 |
! |
3259 |
||
3260 |
tan |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3261 |
"return the tangens of the receiver (interpreted as radians)" |
7385 | 3262 |
|
3263 |
%{ /* NOCONTEXT */ |
|
18296 | 3264 |
#ifdef __SCHTEAM__ |
18299 | 3265 |
return context._RETURN( self.tan() ); |
18296 | 3266 |
#else |
7385 | 3267 |
|
3268 |
double rslt; |
|
3269 |
OBJ newFloat; |
|
3270 |
||
3271 |
__threadErrno = 0; |
|
3272 |
rslt = tan(__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:#tan |
|
3286 |
arguments:#() |
|
3287 |
errorString:'bad receiver in tan' |
|
7385 | 3288 |
|
3289 |
"Modified: / 16.11.2001 / 14:14:49 / cg" |
|
3290 |
! |
|
3291 |
||
3292 |
tanh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
3293 |
"return the hyperbolic tangens of the receiver" |
7385 | 3294 |
|
3295 |
%{ /* NOCONTEXT */ |
|
3296 |
||
3297 |
double rslt; |
|
3298 |
OBJ newFloat; |
|
3299 |
||
3300 |
__threadErrno = 0; |
|
3301 |
rslt = tanh(__floatVal(self)); |
|
7393 | 3302 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
3303 |
{ |
|
11945 | 3304 |
if (__threadErrno == 0) { |
3305 |
__qMKFLOAT(newFloat, rslt); |
|
3306 |
RETURN ( newFloat ); |
|
3307 |
} |
|
7385 | 3308 |
} |
3309 |
%}. |
|
3310 |
^ self class |
|
11945 | 3311 |
raise:#domainErrorSignal |
3312 |
receiver:self |
|
3313 |
selector:#tanh |
|
3314 |
arguments:#() |
|
3315 |
errorString:'bad receiver in tanh' |
|
7385 | 3316 |
! ! |
3317 |
||
5552 | 3318 |
!Float methodsFor:'truncation & rounding'! |
701 | 3319 |
|
3320 |
ceiling |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3321 |
"return the smallest integer which is greater or equal to the receiver." |
701 | 3322 |
|
3323 |
|val| |
|
3324 |
||
3325 |
%{ |
|
18296 | 3326 |
#ifdef __SCHTEAM__ |
3327 |
ERROR("unimplemented"); |
|
3328 |
#else |
|
701 | 3329 |
double dVal; |
3330 |
||
7355 | 3331 |
dVal = ceil(__floatVal(self)); |
701 | 3332 |
/* |
3333 |
* ST-80 (and X3J20) returns integer. |
|
3334 |
*/ |
|
3335 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
11945 | 3336 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 3337 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3338 |
__qMKFLOAT(val, dVal); |
18296 | 3339 |
#endif |
701 | 3340 |
%}. |
3341 |
^ val asInteger |
|
3342 |
! |
|
3343 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3344 |
ceilingAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3345 |
"return the smallest integer-valued float greater or equal to the receiver. |
11945 | 3346 |
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
|
3347 |
of the result to an integer. |
7355 | 3348 |
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
|
3349 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3350 |
%{ /* NOCONTEXT */ |
18296 | 3351 |
#ifdef __SCHTEAM__ |
18299 | 3352 |
return context._RETURN( self.ceiling() ); |
18296 | 3353 |
#else |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3354 |
double dVal; |
7355 | 3355 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3356 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3357 |
dVal = ceil(__floatVal(self)); |
7355 | 3358 |
__qMKFLOAT(v, dVal); |
3359 |
RETURN (v); |
|
18296 | 3360 |
#endif |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3361 |
%} |
7355 | 3362 |
" |
11945 | 3363 |
0.5 ceilingAsFloat |
3364 |
-0.5 ceilingAsFloat |
|
3365 |
-1.5 ceilingAsFloat |
|
7355 | 3366 |
" |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3367 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3368 |
|
701 | 3369 |
floor |
3370 |
"return the integer nearest the receiver towards negative infinity." |
|
3371 |
||
3372 |
|val| |
|
3373 |
||
3374 |
%{ |
|
18296 | 3375 |
#ifdef __SCHTEAM__ |
3376 |
ERROR("unimplemented"); |
|
3377 |
#else |
|
701 | 3378 |
double dVal; |
3379 |
||
7355 | 3380 |
dVal = floor(__floatVal(self)); |
701 | 3381 |
/* |
3382 |
* ST-80 (and X3J20) returns integer. |
|
3383 |
*/ |
|
3384 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
11945 | 3385 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 3386 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3387 |
__qMKFLOAT(val, dVal); |
18296 | 3388 |
#endif |
701 | 3389 |
%}. |
3390 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3391 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3392 |
" |
11945 | 3393 |
0.5 floor |
3394 |
0.5 floorAsFloat |
|
3395 |
-0.5 floor |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3396 |
-0.5 floorAsFloat |
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 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3399 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3400 |
floorAsFloat |
7355 | 3401 |
"return the integer nearest the receiver towards negative infinity as a float. |
11945 | 3402 |
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
|
3403 |
of the result to an integer. |
7355 | 3404 |
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
|
3405 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3406 |
%{ /* NOCONTEXT */ |
18296 | 3407 |
#ifdef __SCHTEAM__ |
18299 | 3408 |
return context._RETURN( self.floor() ); |
18296 | 3409 |
#else |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3410 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3411 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3412 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3413 |
dVal = floor(__floatVal(self)); |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3414 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3415 |
RETURN (v); |
18296 | 3416 |
#endif |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3417 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3418 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3419 |
" |
11945 | 3420 |
0.5 floor |
3421 |
0.5 floorAsFloat |
|
3422 |
-0.5 floor |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3423 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3424 |
" |
701 | 3425 |
! |
3426 |
||
3896 | 3427 |
fractionPart |
3428 |
"extract the after-decimal fraction part. |
|
7355 | 3429 |
such that (self truncated + self fractionPart) = self" |
3896 | 3430 |
|
3431 |
%{ /* NOCONTEXT */ |
|
3432 |
||
14728 | 3433 |
double modf(double, double*); |
3896 | 3434 |
double frac, trunc; |
3435 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
3436 |
__threadErrno = 0; |
3896 | 3437 |
frac = modf(__floatVal(self), &trunc); |
11945 | 3438 |
if (! isnan(frac)) { |
3439 |
if (__threadErrno == 0) { |
|
3440 |
RETURN (__MKFLOAT(frac)); |
|
3441 |
} |
|
3896 | 3442 |
} |
3443 |
%}. |
|
7403 | 3444 |
^ self class |
11945 | 3445 |
raise:#domainErrorSignal |
3446 |
receiver:self |
|
3447 |
selector:#fractionPart |
|
3448 |
arguments:#() |
|
3449 |
errorString:'bad receiver in fractionPart' |
|
3896 | 3450 |
|
3451 |
" |
|
11945 | 3452 |
1.6 fractionPart + 1.6 truncated |
3453 |
-1.6 fractionPart + -1.6 truncated |
|
3454 |
||
3455 |
1.0 fractionPart |
|
3456 |
2.0 fractionPart |
|
3457 |
3.0 fractionPart |
|
3458 |
4.0 fractionPart |
|
3459 |
0.5 fractionPart |
|
3460 |
0.25 fractionPart |
|
3461 |
3.14159 fractionPart |
|
3462 |
12345673.14159 fractionPart |
|
3463 |
123456731231231231.14159 fractionPart |
|
3464 |
||
3465 |
3.14159 fractionPart + 3.14159 truncated |
|
3466 |
||
3467 |
12345673.14159 fractionPart + 12345673.14159 truncated |
|
3468 |
||
3469 |
123456731231231231.14159 fractionPart + 123456731231231231.14159 truncated |
|
3896 | 3470 |
" |
3471 |
! |
|
3472 |
||
701 | 3473 |
rounded |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3474 |
"return the receiver rounded to the nearest integer" |
701 | 3475 |
|
3476 |
|val| |
|
3477 |
||
11945 | 3478 |
%{ |
18296 | 3479 |
#ifdef __SCHTEAM__ |
3480 |
ERROR("unimplemented"); |
|
3481 |
#else |
|
701 | 3482 |
double dVal; |
3483 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3484 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3485 |
if (dVal < 0.0) { |
11945 | 3486 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3487 |
} else { |
11945 | 3488 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3489 |
} |
701 | 3490 |
/* |
3491 |
* ST-80 (and X3J20) returns integer. |
|
3492 |
*/ |
|
3493 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
11945 | 3494 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 3495 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3496 |
__qMKFLOAT(val, dVal); |
18296 | 3497 |
#endif |
701 | 3498 |
%}. |
7355 | 3499 |
^ val asInteger |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3500 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3501 |
" |
11945 | 3502 |
0.4 rounded |
3503 |
0.5 rounded |
|
3504 |
0.6 rounded |
|
3505 |
-0.4 rounded |
|
3506 |
-0.5 rounded |
|
3507 |
-0.6 rounded |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3508 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3509 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3510 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3511 |
roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3512 |
"return the receiver rounded to the nearest integer as a float. |
11945 | 3513 |
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
|
3514 |
of the result to an integer. |
11945 | 3515 |
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
|
3516 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3517 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3518 |
|val| |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3519 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3520 |
%{ /* NOCONTEXT */ |
18296 | 3521 |
#ifdef __SCHTEAM__ |
18299 | 3522 |
return context._RETURN( self.round() ); |
18296 | 3523 |
#else |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3524 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3525 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3526 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3527 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3528 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3529 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3530 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3531 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3532 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3533 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3534 |
RETURN (v); |
18296 | 3535 |
#endif |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3536 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3537 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3538 |
" |
11945 | 3539 |
0.5 rounded |
3540 |
-0.5 rounded |
|
3541 |
0.5 roundedAsFloat |
|
3542 |
-0.5 roundedAsFloat |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3543 |
" |
701 | 3544 |
! |
3545 |
||
3546 |
truncated |
|
3547 |
"return the receiver truncated towards zero as an integer" |
|
3548 |
||
3549 |
|val| |
|
3550 |
||
3551 |
%{ |
|
18296 | 3552 |
#ifdef __SCHTEAM__ |
3553 |
ERROR("unimplemented"); |
|
3554 |
#else |
|
701 | 3555 |
double dVal; |
3556 |
||
1133 | 3557 |
dVal = __floatVal(self); |
701 | 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); |
701 | 3560 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3561 |
dVal = floor(dVal); |
701 | 3562 |
} |
3563 |
||
3564 |
/* |
|
3565 |
* ST-80 (and X3J20) returns integer. |
|
3566 |
*/ |
|
3567 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
8913 | 3568 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 3569 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3570 |
__qMKFLOAT(val, dVal); |
18296 | 3571 |
#endif |
701 | 3572 |
%}. |
3573 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3574 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3575 |
" |
11945 | 3576 |
0.5 truncated |
3577 |
-0.5 truncated |
|
3578 |
0.5 truncatedAsFloat |
|
3579 |
-0.5 truncatedAsFloat |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3580 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3581 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3582 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3583 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3584 |
truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3585 |
"return the receiver truncated towards zero as a float. |
11945 | 3586 |
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
|
3587 |
of the result to an integer. |
11945 | 3588 |
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
|
3589 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3590 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3591 |
%{ /* NOCONTEXT */ |
18296 | 3592 |
#ifdef __SCHTEAM__ |
18300 | 3593 |
return context._RETURN( self.truncated() ); |
18296 | 3594 |
#else |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3595 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3596 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3597 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3598 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3599 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3600 |
dVal = ceil(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3601 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
3602 |
dVal = floor(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3603 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3604 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
3605 |
RETURN (v); |
18296 | 3606 |
#endif |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3607 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3608 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3609 |
" |
11945 | 3610 |
0.5 truncated |
3611 |
-0.5 truncated |
|
3612 |
0.5 truncatedAsFloat |
|
3613 |
-0.5 truncatedAsFloat |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3614 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3615 |
|
701 | 3616 |
! ! |
3617 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
3618 |
!Float class methodsFor:'documentation'! |
701 | 3619 |
|
3620 |
version |
|
18492 | 3621 |
^ '$Header$' |
12423 | 3622 |
! |
3623 |
||
3624 |
version_CVS |
|
18492 | 3625 |
^ '$Header$' |
701 | 3626 |
! ! |
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
3627 |
|
14599 | 3628 |
|
2387 | 3629 |
Float initialize! |