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