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