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