Float.st
author Claus Gittinger <cg@exept.de>
Thu, 28 Nov 2019 16:19:31 +0100
changeset 25002 34d9021dd872
parent 24981 2bf781ee06db
child 25008 89196028f729
permissions -rw-r--r--
fmin/fmax missing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5411
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
    12
"{ Package: 'stx:libbasic' }"
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
    13
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
    14
"{ NameSpace: Smalltalk }"
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
    15
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 47
diff changeset
    16
LimitedPrecisionReal variableByteSubclass:#Float
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
    17
	instanceVariableNames:''
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
    18
	classVariableNames:'DefaultPrintFormat DefaultPrintfFormat E Epsilon Halfpi
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
    19
		HalfpiNegative Ln10 Ln2 MaxSmallInteger NaN NegativeInfinity Pi
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
    20
		PositiveInfinity RadiansPerDegree Sqrt2 Twopi'
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
    21
	poolDictionaries:''
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
    22
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    25
!Float primitiveDefinitions!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    26
%{
14751
991d38458125 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 14728
diff changeset
    27
#include <stdio.h>
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    28
#include <errno.h>
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    29
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    30
#ifndef __OPTIMIZE__
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    31
# define __OPTIMIZE__
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    32
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    33
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    34
#define __USE_ISOC9X 1
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
    35
#define __USE_ISOC99 1
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    36
#include <math.h>
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
    37
#include <float.h>
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    38
16669
8488266c39e5 class: Float
Stefan Vogel <sv@exept.de>
parents: 16667
diff changeset
    39
#ifndef INT64
8488266c39e5 class: Float
Stefan Vogel <sv@exept.de>
parents: 16667
diff changeset
    40
# ifdef HAS_LONGLONG
8488266c39e5 class: Float
Stefan Vogel <sv@exept.de>
parents: 16667
diff changeset
    41
#  define INT64 long long int
8488266c39e5 class: Float
Stefan Vogel <sv@exept.de>
parents: 16667
diff changeset
    42
# else
8488266c39e5 class: Float
Stefan Vogel <sv@exept.de>
parents: 16667
diff changeset
    43
# define INT64 __int64
8488266c39e5 class: Float
Stefan Vogel <sv@exept.de>
parents: 16667
diff changeset
    44
# endif
8488266c39e5 class: Float
Stefan Vogel <sv@exept.de>
parents: 16667
diff changeset
    45
#endif
8488266c39e5 class: Float
Stefan Vogel <sv@exept.de>
parents: 16667
diff changeset
    46
8488266c39e5 class: Float
Stefan Vogel <sv@exept.de>
parents: 16667
diff changeset
    47
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    48
/*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    49
 * on some systems errno is a macro ... check for it here
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    50
 */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    51
#ifndef errno
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    52
 extern errno;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    53
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    54
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
    55
#if !defined (__win32__)
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
    56
# include <locale.h>
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
    57
#endif
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
    58
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
    59
#if defined (__aix__)
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    60
# include <float.h>
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    61
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    62
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
    63
#if defined(__irix__)
2395
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    64
# include <nan.h>
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    65
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    66
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
    67
#if defined(__linux__)
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    68
# ifndef NAN
5822
4e56f8aadda5 Get nan.h from bits/nan.h for Linux
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
    69
#  include <bits/nan.h>
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    70
# endif
2396
646ea118eaf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2395
diff changeset
    71
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    72
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
    73
#if defined(__solaris__) || defined(__sunos__)
2398
652c9f2a13fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2397
diff changeset
    74
# include <nan.h>
652c9f2a13fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2397
diff changeset
    75
#endif
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    76
3129
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    77
/*
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    78
 * sigh - some systems define that stuff; others dont.
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    79
 * (AIX even declares them as macros, so an external decl
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    80
 *  will not work below ...
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    81
 */
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
    82
#if !defined(__aix__) && !defined(__NEXT3__)
3129
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    83
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    84
# ifdef acos
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    85
  double acos();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    86
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    87
# ifdef asin
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    88
  double asin();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    89
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    90
# ifndef atan
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    91
  double atan();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    92
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    93
# ifndef cos
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    94
  double cos();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    95
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    96
# ifndef sin
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    97
  double sin();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    98
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    99
# ifndef pow
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   100
  double pow();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   101
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   102
# ifndef log
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   103
  double log();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   104
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   105
# ifndef exp
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   106
  double exp();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   107
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   108
# ifndef sqrt
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   109
  double sqrt();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   110
# endif
17199
63d9a071e8ff added cbrt
Claus Gittinger <cg@exept.de>
parents: 16669
diff changeset
   111
# ifndef cbrt
17200
3f919ff62213 cbrt is not avail in win32's math library
Claus Gittinger <cg@exept.de>
parents: 17199
diff changeset
   112
#  ifndef WIN32
17199
63d9a071e8ff added cbrt
Claus Gittinger <cg@exept.de>
parents: 16669
diff changeset
   113
  double cbrt();
17200
3f919ff62213 cbrt is not avail in win32's math library
Claus Gittinger <cg@exept.de>
parents: 17199
diff changeset
   114
#  endif
17199
63d9a071e8ff added cbrt
Claus Gittinger <cg@exept.de>
parents: 16669
diff changeset
   115
# endif
3129
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   116
# ifndef tan
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   117
  double tan();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   118
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   119
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   120
#endif /* not AIX */
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   121
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
   122
#ifdef __win32__
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   123
/*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   124
 * no finite(x) ?
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   125
 * no isnan(x) ?
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   126
 */
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   127
# ifndef isnan
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   128
#  define isnan(x)      \
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   129
	((((unsigned int *)(&x))[0] == 0x00000000) && \
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   130
	 (((unsigned int *)(&x))[1] == 0xFFF80000))
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   131
# endif
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   132
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   133
# ifndef isPositiveInfinity
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   134
#  define isPositiveInfinity(x) \
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   135
	((((unsigned int *)(&x))[0] == 0x00000000) && \
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   136
	 (((unsigned int *)(&x))[1] == 0x7FF00000))
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   137
# endif
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   138
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   139
# ifndef isNegativeInfinity
14931
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14926
diff changeset
   140
#  define isNegativeInfinity(x) \
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   141
	((((unsigned int *)(&x))[0] == 0x00000000) && \
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   142
	 (((unsigned int *)(&x))[1] == 0xFFF00000))
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   143
# endif
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   144
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   145
# ifndef isinf
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   146
#  define isinf(x) \
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   147
	((((unsigned int *)(&x))[0] == 0x00000000) && \
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   148
	 ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   149
# endif
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   150
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
   151
# ifndef isfinite
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
   152
#  define isfinite(x) (!isinf(x) && !isnan(x))
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   153
# endif
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   154
7411
45c19db66503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7410
diff changeset
   155
# define NO_ASINH
45c19db66503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7410
diff changeset
   156
# define NO_ACOSH
45c19db66503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7410
diff changeset
   157
# define NO_ATANH
14931
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14926
diff changeset
   158
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14926
diff changeset
   159
# ifdef __MINGW__
22491
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 22301
diff changeset
   160
#  ifndef _STRING_H_INCLUDED_
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 22301
diff changeset
   161
#   include <string.h>
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 22301
diff changeset
   162
#   define _STRING_H_INCLUDED_
e3e465028518 string.h handling (OSX)
Claus Gittinger <cg@exept.de>
parents: 22301
diff changeset
   163
#  endif
14931
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14926
diff changeset
   164
# endif
0de2fc03f23a mingw fixes
Claus Gittinger <cg@exept.de>
parents: 14926
diff changeset
   165
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
   166
#endif /* __win32__ */
8984
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   167
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   168
#ifdef solaris
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   169
# ifndef isfinite
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   170
#  define isfinite(f) finite((double)(f))
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   171
# endif
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   172
#endif
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   173
3414
d9aefd18c10d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3399
diff changeset
   174
#ifdef realIX
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   175
# ifndef isfinite
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
   176
#  define isfinite(x)     1
3414
d9aefd18c10d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3399
diff changeset
   177
# endif
d9aefd18c10d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3399
diff changeset
   178
#endif
d9aefd18c10d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3399
diff changeset
   179
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
   180
#ifndef __NEXT3__
3241
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   181
# ifndef ceil
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   182
double ceil();
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   183
double floor();
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   184
# endif
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   185
#endif
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   186
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   187
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   188
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   189
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   190
!Float class methodsFor:'documentation'!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   191
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   192
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   193
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   194
 COPYRIGHT (c) 1988 by Claus Gittinger
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   195
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   196
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   197
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   198
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   199
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   200
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   201
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   202
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   203
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   204
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   205
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   206
documentation
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   207
"
15016
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   208
    Floats represent rational numbers with limited precision.
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   209
    They use the C-compiler's 'double' format,
24461
6bb78b5e6b15 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24452
diff changeset
   210
    which is usually the 8byte IEEE double float format.
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   211
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   212
    Floats give you 64 bit floats.
15016
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   213
    In contrast to ShortFloats (32bit) and LongFloats (>=64bit).
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   214
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   215
    WARNING:
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   216
	The layout of Float instances is known by the runtime system and the compiler;
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   217
	you may not add instance variables here.
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   218
	Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats,
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   219
	and does some float-checks by an identity compare with the Float-class.
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   220
	(i.e. your subclasses instances may not be recognized as float-like objects,
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   221
	 thus mixed mode arithmetic will always coerce them, effectively slowing things down).
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   222
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   223
    Notice, that Floats are defined as Byte-array to prevent the garbage collector
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   224
    from going into the value ... otherwise I needed a special case in many places.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   225
16632
871ced71895b class: Float
Stefan Vogel <sv@exept.de>
parents: 16447
diff changeset
   226
    Also notice, that ST/X Floats are what Doubles are in ST-80. The reason for doing this
871ced71895b class: Float
Stefan Vogel <sv@exept.de>
parents: 16447
diff changeset
   227
    was to be compatible to both Digitalk, Squeak AND ParcPlace smalltalk implementations
6674
c383bfa3dc8c documentation comment
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
   228
    (ParcPlace uses a 4-byte Float and an 8-byte Double class, in contrast to
15016
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   229
     Digitalk and Squeak, which have an 8-byte Float class).
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   230
    Thus, by providing an 8-byte Float class, code would not loose precicion
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   231
    (although some memory is wasted when porting from VW).
6674
c383bfa3dc8c documentation comment
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
   232
    Notice that ST/X provides an alias called Double, and an extra ShortFloat class, which has 4-byte
c383bfa3dc8c documentation comment
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
   233
    instances.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   234
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1879
diff changeset
   235
    Mixed mode arithmetic:
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   236
	float op float       -> float
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   237
	float op fix         -> float
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   238
	float op fraction    -> float
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   239
	float op integer     -> float
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   240
	float op shortFloat  -> float
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   241
	float op longFloat   -> longFloat
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   242
	float op complex     -> complex
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1879
diff changeset
   243
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   244
    Representation:
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   245
	    64bit double precision IEEE floats
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   246
	    52 bit mantissa + 1 hidden bit providing 53 bits of precision,
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   247
	    11 bit exponent,
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   248
	    15 decimal digits (approx.)
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   249
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   250
    Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
85
claus
parents: 77
diff changeset
   251
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   252
    [author:]
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   253
	Claus Gittinger
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   254
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   255
    [see also:]
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   256
	Number
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   257
	ShortFloat LongFloat Fraction FixedPoint Integer Complex
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   258
	FloatArray DoubleArray
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   259
"
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   260
!
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   261
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   262
errorHandling
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   263
"
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   264
    Floating point error handling and signalling depends on the systems
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   265
    (actually: the C-runtime systems) ability to handle floating point errors.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   266
    Most systems report errors by raising an OS floatingPoint exception,
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   267
    which is mapped to a fpExceptionInterrupt in ST/X.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   268
    However, some systems do return NaN as result.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   269
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   270
    Currently, ST/X does not care specially for these systems - it maybe added
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   271
    easily, if there is sufficient customer interest, though.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   272
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   273
    Try:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   274
	|f1 f2|
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   275
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   276
	f1 := 1.0.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   277
	f2 := 0.0.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   278
	f1 / f2
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   279
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   280
    or:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   281
	2 arcSin
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   282
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   283
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   284
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   285
!Float class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   286
a27a279701f8 Initial revision
claus
parents:
diff changeset
   287
basicNew
a27a279701f8 Initial revision
claus
parents:
diff changeset
   288
    "return a new float - here we return 0.0
a27a279701f8 Initial revision
claus
parents:
diff changeset
   289
     - floats are usually NOT created this way ...
a27a279701f8 Initial revision
claus
parents:
diff changeset
   290
     Its implemented here to allow things like binary store & load
a27a279701f8 Initial revision
claus
parents:
diff changeset
   291
     of floats. (but even this support will go away eventually, its not
a27a279701f8 Initial revision
claus
parents:
diff changeset
   292
     a good idea to store the bits of a float - the reader might have a
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   293
     totally different representation - so floats will eventually be
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   294
     binary stored in a device independent format."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   295
a27a279701f8 Initial revision
claus
parents:
diff changeset
   296
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
   297
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
   298
    ERROR("trying to instantiate a float");
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
   299
#else
1206
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   300
    OBJ newFloat;
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   301
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   302
    __qMKFLOAT(newFloat, 0.0);
1206
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   303
    RETURN (newFloat);
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
   304
#endif /* not SCHTEAM */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   305
%}
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   306
!
1206
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   307
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   308
fastFromString:aString at:startIndex
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   309
    "return the next Float from the string starting at startIndex.
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   310
     No spaces are skipped.
23477
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   311
     Raises an exception, if the startIndex is not valid.
23943
aa4b209ef165 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23477
diff changeset
   312
     Returns garbage if the argument string is not a valid double float number.
23477
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   313
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   314
     This is a specially tuned entry (using a low-level C-call to atof).
24249
17326e1df17f raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents: 24230
diff changeset
   315
     It has been added to allow high speed string decomposition
23477
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   316
     into numbers, especially for mass-data (reading millions of floats)."
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   317
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   318
%{   /* NOCONTEXT */
23477
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   319
     int idx = __intVal(startIndex) - 1;
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   320
12478
e8051030cda6 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12423
diff changeset
   321
     if (__isStringLike(aString) && __isSmallInteger(startIndex)) {
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   322
	char *cp = (char *)(__stringVal(aString));
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   323
	double val;
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   324
	OBJ newFloat;
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   325
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   326
	if ((unsigned)idx < __stringSize(aString)) {
24974
58dffe3baf29 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24969
diff changeset
   327
#ifndef NO_STRTOD
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   328
	    double strtod(const char *, char**);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   329
	    val = strtod(cp+idx, NULL);
24974
58dffe3baf29 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24969
diff changeset
   330
#else
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   331
	    double atof();
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   332
	    val = atof(cp + idx);
24974
58dffe3baf29 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24969
diff changeset
   333
#endif
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   334
	    __qMKFLOAT(newFloat, val);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   335
	    RETURN (newFloat);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   336
	}
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   337
     }
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   338
%}.
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   339
     self primitiveFailed.
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   340
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   341
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   342
     Float fastFromString:'123.45' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   343
     Float fastFromString:'123.45' at:2
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   344
     Float fastFromString:'123.45' at:3
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   345
     Float fastFromString:'123.45' at:4
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   346
     Float fastFromString:'123.45' at:5
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   347
     Float fastFromString:'123.45' at:6
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   348
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   349
     Float fastFromString:'123.45E4' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   350
     Float fastFromString:'hello123.45E4' at:6
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   351
     Float fastFromString:'12345' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   352
     Float fastFromString:'12345' at:2
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   353
     Float fastFromString:'12345' at:3
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   354
     Float fastFromString:'12345' at:4
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   355
     Float fastFromString:'12345' at:5
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   356
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   357
     Float fastFromString:'12345' at:6          -> error
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   358
     Float fastFromString:'12345' at:0          -> error
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   359
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   360
     Float fastFromString:'hello123.45E4' at:1  -> 0
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   361
23477
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   362
     Float fastFromString:'1.7976931348623157e+308'
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   363
     Float fastFromString:'Nan'
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   364
     Float fastFromString:'+Inf'
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   365
     Float fastFromString:'-Inf'
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   366
    "
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   367
7965dfb1ed1b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22854
diff changeset
   368
    "
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   369
     Time millisecondsToRun:[
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   370
	1000000 timesRepeat:[
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   371
	    Float readFrom:'123.45'
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   372
	]
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   373
     ]
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   374
    "
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   375
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   376
    "
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   377
     Time millisecondsToRun:[
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   378
	1000000 timesRepeat:[
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   379
	    Float fastFromString:'123.45' at:1
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   380
	]
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   381
     ]
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   382
    "
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   383
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   384
    "Modified (comment): / 21-06-2017 / 09:24:32 / cg"
23943
aa4b209ef165 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23477
diff changeset
   385
    "Modified (comment): / 20-03-2019 / 13:45:12 / Claus Gittinger"
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   386
!
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   387
15016
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   388
fromIEEE32Bit: anInteger
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   389
    "creates a double, given the four native float bytes as an integer"
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   390
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   391
%{  /* NOCONTEXT */
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   392
#ifndef __SCHTEAM__
15016
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   393
    REGISTER union {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   394
	unsigned int    i;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   395
	float           f;
15016
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   396
    } r;
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   397
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   398
    r.i = __unsignedLongIntVal( anInteger );
15017
d16c28f26b4f class: Float
Claus Gittinger <cg@exept.de>
parents: 15016
diff changeset
   399
    RETURN( __MKFLOAT((double)(r.f)) );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
   400
#endif
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   401
%}.
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   402
    self primitiveFailed.
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   403
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   404
    "
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   405
     ShortFloat fromIEEE32Bit:((ShortFloat pi digitBytesMSB:true) asIntegerMSB:true)
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   406
    "
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   407
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   408
    "Modified (comment): / 21-06-2017 / 09:26:41 / cg"
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   409
!
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   410
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   411
fromIEEE64Bit: anInteger
21875
aaf7afa7bb0f #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21870
diff changeset
   412
    "creates a double, given the eight native double bytes as an integer"
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   413
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   414
%{  /* NOCONTEXT */
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   415
#ifndef __SCHTEAM__
21876
52fb77cd4093 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21875
diff changeset
   416
    extern int __unsignedLong64IntVal(OBJ o, __uint64__ *pI);
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   417
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   418
    REGISTER union {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   419
	__uint64__  u64;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   420
	double      d;
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   421
    } r;
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   422
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   423
    if (__unsignedLong64IntVal(anInteger, &r.u64))  {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   424
	RETURN( __MKFLOAT(r.d) );
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   425
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
   426
#endif
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   427
%}.
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   428
    self primitiveFailed.
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   429
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   430
    "
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   431
	Float fromIEEE64Bit:((Float pi digitBytesMSB:true) asIntegerMSB:true)
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
   432
    "
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   433
21876
52fb77cd4093 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21875
diff changeset
   434
    "Modified: / 21-06-2017 / 09:37:47 / cg"
15016
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   435
!
27471b4d9776 class: Float
Claus Gittinger <cg@exept.de>
parents: 15013
diff changeset
   436
19358
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   437
fromInteger:anInteger
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   438
    "return a new float, given an integer value"
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   439
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   440
%{  /* NOCONTEXT */
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   441
#ifdef __SCHTEAM__
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   442
    if (anInteger.isSmallInteger()) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   443
	return __c__._RETURN( STDouble._new( (double)(anInteger.longValue()) ));
19358
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   444
    }
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   445
#else
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   446
    OBJ newFloat;
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   447
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   448
    if (__isSmallInteger(anInteger)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   449
	double f = (double)__smallIntegerVal(anInteger);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   450
	__qMKFLOAT(newFloat, f);   /* OBJECT ALLOCATION */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   451
	RETURN (newFloat);
19358
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   452
    }
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   453
#endif /* not SCHTEAM */
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   454
%}.
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   455
    ^ super fromInteger:anInteger
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   456
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   457
    "
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   458
     Float fromInteger:123
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   459
     Float fromInteger:(100 factorial)
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19358
diff changeset
   460
     (100 factorial) asFloat
19358
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   461
    "
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   462
!
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   463
17653
ae0a317ee190 class: Float
Claus Gittinger <cg@exept.de>
parents: 17583
diff changeset
   464
fromNumber:aNumber
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   465
    "return aNumber coerced to Float"
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
   466
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   467
    ^ aNumber asFloat
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   468
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   469
    "Modified (comment): / 21-06-2017 / 08:55:15 / cg"
17653
ae0a317ee190 class: Float
Claus Gittinger <cg@exept.de>
parents: 17583
diff changeset
   470
!
ae0a317ee190 class: Float
Claus Gittinger <cg@exept.de>
parents: 17583
diff changeset
   471
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   472
fromVAXFloatBytes:b1 b2:b2 b3:b3 b4:b4
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   473
    "creates a double, given the four vax F-format float bytes to an ieee double.
3427
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   474
     For NaNs and Infinity, nil is returned.
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   475
     To get an idea of how big the floating-point zoo really is,
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   476
     see: http://www.quadibloc.com/comp/cp0201.htm
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   477
    "
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   478
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   479
%{  /* NOCONTEXT */
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   480
#ifndef __SCHTEAM__
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   481
    REGISTER union {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   482
	unsigned char   b[4];
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   483
	unsigned int    l;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   484
	float           f;
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   485
    } r;
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   486
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
   487
# ifdef __LSBFIRST__
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   488
    r.b[3] = __intVal( b2 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   489
    r.b[2] = __intVal( b1 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   490
    r.b[1] = __intVal( b4 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   491
    r.b[0] = __intVal( b3 );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
   492
# else
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   493
    r.b[0] = __intVal( b2 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   494
    r.b[1] = __intVal( b1 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   495
    r.b[2] = __intVal( b4 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   496
    r.b[3] = __intVal( b3 );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
   497
# endif
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   498
    if( (r.l & 0xff800000) != 0x80000000 ) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   499
	if( (r.l & 0x7f800000) > 0x01000000 )
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   500
	    r.l -= 0x01000000;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   501
	else
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   502
	    r.l = 0;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   503
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   504
	RETURN( __MKFLOAT(r.f) );
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   505
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   506
	// add code to handle NaN and Inf
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   507
	RETURN( nil );
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   508
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
   509
#endif
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   510
%}.
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   511
    ^ self primitiveFailed
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   512
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   513
    "Modified: / 21-06-2017 / 09:21:55 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   514
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   515
12916
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   516
!Float class methodsFor:'accessing'!
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   517
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   518
defaultPrintFormat
24954
04f672a40ad9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24930
diff changeset
   519
    "/ by default, I will print 15 digits
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   520
    "/  ShortFloat pi   -> 3.141593
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   521
    "/  Float pi        -> 3.14159265358979
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   522
    "/  LongFloat pi    -> 3.141592653589793239
24954
04f672a40ad9 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24930
diff changeset
   523
12916
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   524
    ^ DefaultPrintFormat
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   525
!
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   526
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   527
defaultPrintFormat:something
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   528
    DefaultPrintFormat := something.
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
   529
!
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
   530
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   531
defaultPrintfFormat
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   532
    ^ DefaultPrintfFormat
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   533
!
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   534
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   535
defaultPrintfFormat:something
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   536
    DefaultPrintfFormat := something.
12916
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   537
! !
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   538
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   539
!Float class methodsFor:'binary storage'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   540
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   541
readBinaryIEEEDoubleFrom:aStream
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   542
    "read a float from the binary stream, aStream,
14925
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   543
     interpreting the next bytes as an IEEE formatted 8-byte float.
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   544
     The bytes are read in the native byte order (i.e.lsb on intel)"
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   545
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   546
    |f|
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   547
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   548
    f := self basicNew.
15013
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   549
    self readBinaryIEEEDoubleFrom:aStream into:f MSB:(UninterpretedBytes isBigEndian).
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   550
    ^ f
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   551
9637
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   552
    "not part of libboss, as this is also used by others (TIFFReader)"
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   553
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   554
    "Created: / 16-04-1996 / 20:59:59 / cg"
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   555
    "Modified: / 23-08-2006 / 16:00:42 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   556
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   557
15013
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   558
readBinaryIEEEDoubleFrom:aStream MSB:msbFirst
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   559
    "read a float from the binary stream, aStream,
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   560
     interpreting the next bytes as an IEEE formatted 8-byte float.
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   561
     The bytes are read in the specified byte order"
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   562
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   563
    |f|
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   564
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   565
    f := self basicNew.
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   566
    self readBinaryIEEEDoubleFrom:aStream into:f MSB:msbFirst.
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   567
    ^ f
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   568
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   569
    "not part of libboss, as this is also used by others (TIFFReader)"
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   570
!
f049844b9f0a class: Float
Claus Gittinger <cg@exept.de>
parents: 14931
diff changeset
   571
19616
4844da24b225 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19570
diff changeset
   572
readBinaryIEEEDoubleFrom:aStream into:aBasicNewFloat
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   573
    "read the receiver's value from the binary stream, aStream,
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   574
     interpreting the next bytes as an IEEE formatted 8-byte float.
14925
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   575
     The bytes are read in the native byte order (i.e.lsb on intel)"
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   576
19616
4844da24b225 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19570
diff changeset
   577
    ^ self readBinaryIEEEDoubleFrom:aStream into:aBasicNewFloat MSB:(UninterpretedBytes isBigEndian)
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   578
!
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   579
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   580
readBinaryIEEEDoubleFrom:aStream into:aFloat MSB:msb
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   581
    "read the receiver's value from the binary stream, aStream,
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   582
     interpreting the next bytes as an IEEE formatted 8-byte float.
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   583
     If msb is true, the stream bytes are most-significant-first."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   584
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   585
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   586
     this implementation is wrong: does not work on non-IEEE machines
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   587
     (to date all machines where ST/X is running on use
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   588
      IEEE float format. Will need more here, when porting ST/X to 370's)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   589
    "
3427
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   590
    self isIEEEFormat ifFalse:[self error:'unsupported operation'].
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   591
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
   592
    (UninterpretedBytes isBigEndian == msb) ifFalse:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   593
	"swap the bytes"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   594
	8 to:1 by:-1 do:[:i |
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   595
	    aFloat basicAt:i put:(aStream next)
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   596
	].
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   597
	^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   598
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   599
    1 to:8 do:[:i |
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   600
	aFloat basicAt:i put:aStream next
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   601
    ]
9637
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   602
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   603
    "not part of libboss, as this is also used by others (TIFFReader)"
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   604
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   605
    "Modified: / 23-08-2006 / 16:00:37 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   606
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   607
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   608
storeBinaryIEEEDouble:aFloat on:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   609
    "store aFloat as an IEEE formatted 8-byte float
14925
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   610
     onto the binary stream, aStream.
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   611
     The bytes are written in the native byte order (i.e.lsb on intel)"
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   612
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   613
    self storeBinaryIEEEDouble:aFloat on:aStream MSB:(UninterpretedBytes isBigEndian)
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   614
!
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   615
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   616
storeBinaryIEEEDouble:aFloat on:aStream MSB:msb
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   617
    "store aFloat as an IEEE formatted 8-byte float
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   618
     onto the binary stream, aStream.
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   619
     If msb is true, the stream bytes are written most-significant-first."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   620
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   621
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   622
     this implementation is wrong: does not work on non-IEEE machines
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   623
     (to date all machines where ST/X is running on use
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   624
      IEEE float format. Need more here, when porting ST/X to 370's)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   625
    "
3427
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   626
    self isIEEEFormat ifFalse:[self error:'unsupported operation'].
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   627
14925
046356fde326 allow saving in msb
Claus Gittinger <cg@exept.de>
parents: 14923
diff changeset
   628
    (UninterpretedBytes isBigEndian == msb) ifFalse:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   629
	"swap the bytes"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   630
	8 to:1 by:-1 do:[:i |
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   631
	    aStream nextPut:(aFloat basicAt:i).
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   632
	].
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   633
	^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   634
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   635
    1 to:8 do:[:i |
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   636
	aStream nextPut:(aFloat basicAt:i).
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   637
    ].
9637
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   638
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   639
    "not part of libboss, as this is also used by others (TIFFReader)"
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   640
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   641
    "Modified: / 23-08-2006 / 16:00:47 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   642
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   643
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   644
!Float class methodsFor:'class initialization'!
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   645
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   646
initialize
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   647
    Pi isNil ifTrue:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   648
	DefaultPrintFormat := '.15'.  "/ print 15 valid digits
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   649
	DefaultPrintfFormat := '%15f'.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   650
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   651
	Pi := 3.14159265358979323846264338327950288419716939937510582097494459.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   652
	Halfpi := Pi / 2.0.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   653
	HalfpiNegative := Halfpi negated.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   654
	Twopi := Pi * 2.0.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   655
	E := 2.7182818284590452353602874713526625.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   656
	Sqrt2 := 1.41421356237309504880168872420969808.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   657
	RadiansPerDegree := Pi / 180.0.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   658
	Ln2 := 0.69314718055994530941723212145817657.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   659
	Ln10 := 10.0 ln.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   660
	MaxSmallInteger := super maxSmallInteger.
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   661
    ].
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   662
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   663
    "
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   664
     Pi := nil.
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   665
     self initialize
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   666
    "
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   667
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   668
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   669
     DefaultPrintFormat := '.9'.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   670
     Float pi printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   671
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   672
     DefaultPrintFormat := '.6'.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   673
     Float pi printString.
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   674
    "
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   675
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   676
    "Modified: / 07-06-2007 / 21:17:53 / cg"
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   677
! !
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   678
21870
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   679
!Float class methodsFor:'coercing & converting'!
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   680
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   681
coerce:aNumber
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   682
    "convert the argument aNumber into an instance of the receiver (class) and return it."
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   683
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   684
    ^ aNumber asFloat.
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   685
! !
46d6c8e28c70 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21869
diff changeset
   686
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   687
!Float class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   688
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   689
NaN
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   690
    "return the constant NaN (not a Number)"
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   691
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   692
    NaN isNil ifTrue:[
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   693
%{
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8635
diff changeset
   694
#if defined(LINUX) && defined(__i386__)
3955
ebf11ebe113e NAN for suseV6 nan.h
Claus Gittinger <cg@exept.de>
parents: 3945
diff changeset
   695
# ifdef NAN
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   696
	@global(Float:NaN) = __MKFLOAT(NAN);
3955
ebf11ebe113e NAN for suseV6 nan.h
Claus Gittinger <cg@exept.de>
parents: 3945
diff changeset
   697
# else
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   698
	@global(Float:NaN) = __MKFLOAT(_SNAN);
3955
ebf11ebe113e NAN for suseV6 nan.h
Claus Gittinger <cg@exept.de>
parents: 3945
diff changeset
   699
# endif
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   700
#endif
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   701
%}.
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   702
	NaN isNil ifTrue:[
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   703
	    NaN := super NaN.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   704
	].
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   705
    ].
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   706
    ^ NaN
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   707
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   708
    "
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   709
     Float NaN
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   710
     Float NaN + 0.0
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   711
     Float NaN + Float NaN
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   712
     0.0 + Float NaN
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   713
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   714
     it's a singleton:
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   715
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   716
     Float NaN == Float NaN
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   717
    "
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   718
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   719
    "Modified (format): / 20-06-2017 / 13:52:31 / cg"
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   720
!
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   721
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   722
e
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   723
    "return the constant e as Float"
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   724
20799
5dfe67b1daf1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
   725
    "/ don't expect this many valid digits on all machines;
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   726
    "/ The actual precision is very CPU specific.
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   727
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   728
    ^ 2.7182818284590452353602874713526625
6341
19a407a314da Raise more specific signals.
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   729
!
19a407a314da Raise more specific signals.
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   730
22725
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   731
halfpi
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   732
    "return the constant pi/2 as Float"
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   733
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   734
    "/ don't expect this many valid digits on all machines;
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   735
    "/ The actual precision is very CPU specific.
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   736
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   737
    ^ 1.570796326794896619231321691639751442098584699687552910
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   738
!
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   739
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   740
halfpiNegative
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   741
    "return the constant -pi/2 as Float"
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   742
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   743
    "/ don't expect this many valid digits on all machines;
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   744
    "/ The actual precision is very CPU specific.
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   745
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   746
    ^ -1.570796326794896619231321691639751442098584699687552910
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   747
!
70827545d34f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22578
diff changeset
   748
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   749
infinity
24302
ad24f2aec0c9 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24295
diff changeset
   750
    "return a float which represents positive infinity (for my instances).
ad24f2aec0c9 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24295
diff changeset
   751
     Warning: do not compare equal against infinities;
ad24f2aec0c9 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24295
diff changeset
   752
     instead, check using isFinite or isInfinite"
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   753
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   754
    PositiveInfinity isNil ifTrue:[
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   755
	PositiveInfinity := super infinity
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   756
    ].
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   757
    ^ PositiveInfinity
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   758
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   759
    "
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   760
     Float infinity == Float infinity
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   761
    "
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   762
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   763
    "Created: / 20-06-2017 / 13:56:07 / cg"
24302
ad24f2aec0c9 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24295
diff changeset
   764
    "Modified (comment): / 09-06-2019 / 12:54:54 / Claus Gittinger"
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   765
!
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   766
18492
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
   767
ln10
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
   768
    "return the natural logarithm of 10;
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
   769
     will return something like 2.30258509299405"
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
   770
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
   771
    ^ Ln10
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
   772
!
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
   773
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   774
ln2
18492
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
   775
    "return the natural logarithm of 2"
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
   776
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
   777
    "/ don't expect this many valid digits on all machines;
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   778
    "/ The actual precision is very CPU specific.
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   779
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   780
    ^ 0.69314718055994530941723212145817657.
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   781
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   782
    "Created: / 07-06-2007 / 21:11:55 / cg"
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   783
!
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   784
19358
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   785
maxSmallInteger
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   786
    "return the max. smallInteger value as a float"
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   787
19358
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   788
    ^ MaxSmallInteger
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   789
!
f9e7a37cffd9 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 19326
diff changeset
   790
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   791
negativeInfinity
24302
ad24f2aec0c9 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24295
diff changeset
   792
    "return a float which represents positive infinity (for my instances).
ad24f2aec0c9 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24295
diff changeset
   793
     Warning: do not compare equal against infinities;
ad24f2aec0c9 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24295
diff changeset
   794
     instead, check using isFinite or isInfinite"
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   795
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   796
    NegativeInfinity isNil ifTrue:[
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   797
	NegativeInfinity := super negativeInfinity
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   798
    ].
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   799
    ^ NegativeInfinity
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   800
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   801
    "
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
   802
     Float negativeInfinity == Float negativeInfinity
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   803
    "
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   804
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   805
    "Created: / 20-06-2017 / 13:56:35 / cg"
24302
ad24f2aec0c9 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24295
diff changeset
   806
    "Modified (comment): / 09-06-2019 / 12:55:10 / Claus Gittinger"
21859
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   807
!
6065925371a5 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21849
diff changeset
   808
24930
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   809
phi
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   810
    "return the constant phi as Float"
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   811
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   812
    "/ don't expect this many valid digits on all machines;
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   813
    "/ The actual precision is very CPU specific.
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   814
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   815
    ^ 1.618033988749894848204586834365638117720309179805762862135
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   816
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   817
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   818
!
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   819
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   820
pi
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   821
    "return the constant pi as Float"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   822
20799
5dfe67b1daf1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
   823
    "/ don't expect this many valid digits on all machines;
3244
9ba0abc1d217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3241
diff changeset
   824
    "/ The actual precision is very CPU specific.
9ba0abc1d217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3241
diff changeset
   825
6063
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   826
    ^ 3.14159265358979323846264338327950288419716939937510582097494459
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   827
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   828
    "Modified: 23.4.1996 / 09:27:02 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   829
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   830
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   831
sqrt2
20799
5dfe67b1daf1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
   832
    "/ don't expect this many valid digits on all machines;
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   833
    "/ The actual precision is very CPU specific.
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   834
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   835
    ^ 1.41421356237309504880168872420969808
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   836
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   837
    "Created: / 07-06-2007 / 21:12:33 / cg"
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   838
!
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   839
24930
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   840
sqrt5
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   841
    "/ don't expect this many valid digits on all machines;
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   842
    "/ The actual precision is very CPU specific.
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   843
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   844
    ^ 2.236067977499789696409173668731276235440618359611525724270
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   845
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   846
    "Created: / 07-06-2007 / 21:12:33 / cg"
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   847
!
b9f4cb048fe7 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24915
diff changeset
   848
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   849
unity
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   850
    "return the neutral element for multiplication (1.0) as Float"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   851
a27a279701f8 Initial revision
claus
parents:
diff changeset
   852
    ^ 1.0
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   853
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   854
    "Modified: 23.4.1996 / 09:27:09 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   855
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   856
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   857
zero
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   858
    "return the neutral element for addition (0.0) as Float"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   859
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   860
    ^ 0.0
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   861
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   862
    "Modified: 23.4.1996 / 09:27:15 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   863
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   864
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   865
!Float class methodsFor:'misc'!
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   866
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   867
getFPUControl
24169
db5c25cc1e42 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24152
diff changeset
   868
    "BORLAND only: get the fpu control word."
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   869
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   870
%{
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   871
#ifdef __BORLANDC__
14106
900bb7bce82f *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 14105
diff changeset
   872
    unsigned int _control87();
900bb7bce82f *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 14105
diff changeset
   873
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   874
    int result = _control87(0, 0);
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   875
    RETURN(__MKSMALLINT(result));
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   876
#endif
24169
db5c25cc1e42 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24152
diff changeset
   877
%}.
db5c25cc1e42 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24152
diff changeset
   878
    ^ 0 "/ otherwise an arbitrary value
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   879
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   880
    "
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
   881
     self getFPUControl
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   882
    "
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
   883
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
   884
    "Modified (comment): / 20-06-2017 / 11:51:58 / cg"
24169
db5c25cc1e42 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24152
diff changeset
   885
    "Modified (comment): / 27-05-2019 / 08:58:54 / Claus Gittinger"
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   886
!
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   887
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   888
setFPUControl
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
   889
    "BORLAND only: set the fpu control word for 64 bit precision for long doubles here"
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   890
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   891
%{
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   892
#ifdef __BORLANDC__
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   893
#include <float.h>
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   894
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   895
    // Set precision to long double / 64bit
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   896
    int result = _control87(PC_64, MCW_PC);
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   897
    RETURN(__MKSMALLINT(result));
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   898
#endif
24169
db5c25cc1e42 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24152
diff changeset
   899
%}.
db5c25cc1e42 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24152
diff changeset
   900
    "/ otherwise ignored
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   901
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   902
    "
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
   903
     self setFPUControl
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   904
    "
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
   905
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
   906
    "Modified (comment): / 20-06-2017 / 11:51:54 / cg"
24169
db5c25cc1e42 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24152
diff changeset
   907
    "Modified (comment): / 27-05-2019 / 08:58:35 / Claus Gittinger"
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   908
! !
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   909
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   910
!Float class methodsFor:'queries'!
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   911
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   912
eBias
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   913
    "Answer the exponent's bias;
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   914
     that is the offset of the zero exponent when stored"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   915
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   916
    ^ 1023
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   917
!
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   918
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   919
emax
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   920
    "Answer the maximum exponent for this representation."
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   921
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   922
    ^1023
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   923
!
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   924
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   925
emin
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   926
    "Answer the minimum exponent for this representation."
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   927
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   928
    ^ -1022
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   929
!
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   930
24320
904fbd4fc461 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24302
diff changeset
   931
epsilon
904fbd4fc461 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24302
diff changeset
   932
    "return the maximum relative spacing of instances of mySelf
24957
a1db6c71ca91 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24954
diff changeset
   933
     (i.e. the value-delta of the least significant bit).
a1db6c71ca91 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24954
diff changeset
   934
     see https://en.wikipedia.org/wiki/Machine_epsilon"
24320
904fbd4fc461 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24302
diff changeset
   935
904fbd4fc461 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24302
diff changeset
   936
    Epsilon isNil ifTrue:[
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   937
	Epsilon := self computeEpsilon.
24320
904fbd4fc461 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24302
diff changeset
   938
    ].
904fbd4fc461 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24302
diff changeset
   939
    ^ Epsilon
904fbd4fc461 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24302
diff changeset
   940
24915
9b05c18790b2 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24875
diff changeset
   941
    "
9b05c18790b2 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24875
diff changeset
   942
     Float epsilon      -> 1.11022302462516E-16
9b05c18790b2 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24875
diff changeset
   943
     ShortFloat epsilon -> 5.960464e-08
9b05c18790b2 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24875
diff changeset
   944
     LongFloat epsilon  -> 5.42101086242752217E-20
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   945
     QuadFloat epsilon  ->
24915
9b05c18790b2 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24875
diff changeset
   946
    "
9b05c18790b2 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24875
diff changeset
   947
24320
904fbd4fc461 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24302
diff changeset
   948
    "Modified (comment): / 22-06-2017 / 13:44:12 / cg"
904fbd4fc461 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24302
diff changeset
   949
!
904fbd4fc461 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24302
diff changeset
   950
6898
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   951
exponentCharacter
24326
de53dbf87153 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24320
diff changeset
   952
    "return the character used to print between mantissa an exponent.
de53dbf87153 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24320
diff changeset
   953
     Also used by the scanner when reading numbers."
de53dbf87153 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24320
diff changeset
   954
6898
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   955
    ^ $d
24326
de53dbf87153 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24320
diff changeset
   956
de53dbf87153 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24320
diff changeset
   957
    "Modified (comment): / 10-06-2019 / 21:27:46 / Claus Gittinger"
6898
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   958
!
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   959
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   960
fmin
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   961
%{
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   962
    RETURN(__MKFLOAT(DBL_MIN));
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   963
%}.
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   964
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   965
    "
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   966
     Float fmin
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   967
    "
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   968
!
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   969
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   970
fmax
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   971
%{
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   972
    RETURN(__MKFLOAT(DBL_MAX));
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   973
%}.
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   974
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   975
    "
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   976
     Float fmax
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   977
    "
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   978
!
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
   979
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   980
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   981
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   982
     Here, true is returned for myself, false for subclasses."
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   983
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   984
    ^ self == Float
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   985
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   986
    "Modified: 23.4.1996 / 15:59:04 / cg"
3427
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   987
!
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   988
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   989
numBitsInExponent
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   990
    "answer the number of bits in the exponent
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   991
     This is an IEEE float, where 11 bits are available:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
   992
	seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   993
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   994
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   995
    ^ 11
24206
e281086bb292 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24191
diff changeset
   996
e281086bb292 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24191
diff changeset
   997
    "
e281086bb292 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24191
diff changeset
   998
     1.0 numBitsInExponent
e281086bb292 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24191
diff changeset
   999
    "
e281086bb292 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24191
diff changeset
  1000
e281086bb292 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24191
diff changeset
  1001
    "Modified (format): / 28-05-2019 / 08:55:51 / Claus Gittinger"
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1002
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1003
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1004
numBitsInMantissa
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1005
    "answer the number of bits in the mantissa.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1006
     This is an IEEE double, where 52 bits (the hidden one is not counted here) are available:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1007
	seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1008
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1009
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1010
     ^ 52
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1011
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1012
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1013
precision
24266
e7a43fdfc447 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24255
diff changeset
  1014
    "answer the precision (the number of bits in the mantissa) of a Float (in bits)
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1015
     This is an IEEE double, where only the fraction from the normalized mantissa is stored
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1016
     and so there is a hidden bit and the mantissa is actually represented
9150
550cef1b935a comment
Claus Gittinger <cg@exept.de>
parents: 9124
diff changeset
  1017
     by 53 binary digits (although only 52 are needed in the binary representation)"
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1018
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1019
    ^  53
19326
aa152894e736 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19091
diff changeset
  1020
aa152894e736 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19091
diff changeset
  1021
    "
aa152894e736 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19091
diff changeset
  1022
     self numBitsInMantissa + 1
aa152894e736 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19091
diff changeset
  1023
     self precision
aa152894e736 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19091
diff changeset
  1024
    "
24266
e7a43fdfc447 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24255
diff changeset
  1025
e7a43fdfc447 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24255
diff changeset
  1026
    "Modified (comment): / 06-06-2019 / 13:23:58 / Claus Gittinger"
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1027
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1028
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1029
radix
24440
aa298221eb96 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24328
diff changeset
  1030
    "answer the radix of a Float's exponent
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1031
     This is an IEEE float, which is represented as binary"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1032
8635
38674ba49a14 comment
Claus Gittinger <cg@exept.de>
parents: 8422
diff changeset
  1033
    ^ 2 "must be careful here, whenever ST/X is used on VAX or a 370"
24440
aa298221eb96 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24328
diff changeset
  1034
aa298221eb96 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24328
diff changeset
  1035
    "Modified (comment): / 19-07-2019 / 17:28:11 / Claus Gittinger"
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
  1036
! !
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
  1037
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1038
!Float methodsFor:'arithmetic'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1039
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1040
* aNumber
11733
fe4717d35e0c comment
Claus Gittinger <cg@exept.de>
parents: 11721
diff changeset
  1041
    "return the product of the receiver and the argument."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1042
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1043
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1044
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1045
    if (aNumber.isNumber()) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1046
	return context._RETURN( self.times(aNumber) );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1047
    }
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1048
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1049
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1050
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1051
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1052
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1053
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1054
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1055
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1056
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1057
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1058
     */
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1059
    OBJ newFloat;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1060
    double result;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1061
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1062
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1063
	result = __floatVal(self) * (double)(__intVal(aNumber));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1064
retResult:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1065
	__qMKFLOAT(newFloat, result);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1066
	RETURN ( newFloat );
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1067
    }
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1068
    /* knowing that aNumber is not a SmallInt, we only need to check for nil;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1069
     * then can use qIsXXX macros which saves us some checks
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1070
     */
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1071
    if (aNumber != nil) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1072
	if (__qIsFloatLike(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1073
	    result = __floatVal(self) * __floatVal(aNumber);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1074
	    goto retResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1075
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1076
	if (__qIsShortFloat(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1077
	    result = __floatVal(self) * (double)(__shortFloatVal(aNumber));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1078
	    goto retResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1079
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1080
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1081
#endif
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
  1082
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1083
    ^ aNumber productFromFloat:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1084
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1085
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1086
+ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1087
    "return the sum of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1088
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1089
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1090
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1091
    if (aNumber.isNumber()) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1092
	return context._RETURN( self.plus(aNumber) );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1093
    }
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1094
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1095
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1096
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1097
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1098
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1099
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1100
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1101
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1102
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1103
     */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1104
    OBJ newFloat;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1105
    double result;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1106
250
a5deb61ffdac *** empty log message ***
claus
parents: 224
diff changeset
  1107
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1108
	result = __floatVal(self) + (double)(__intVal(aNumber));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1109
retResult:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1110
	__qMKFLOAT(newFloat, result);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1111
	RETURN ( newFloat );
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1112
    }
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1113
    /* knowing that aNumber is not a SmallInt, we only need to check for nil;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1114
     * then can use qIsXXX macros which saves us some checks
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1115
     */
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1116
    if (aNumber != nil) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1117
	if (__qIsFloatLike(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1118
	    result = __floatVal(self) + __floatVal(aNumber);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1119
	    goto retResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1120
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1121
	if (__qIsShortFloat(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1122
	    result = __floatVal(self) + (double)(__shortFloatVal(aNumber));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1123
	    goto retResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1124
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1125
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1126
#endif
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
  1127
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1128
    ^ aNumber sumFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1129
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1130
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1131
- aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1132
    "return the difference of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1133
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1134
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1135
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1136
    if (aNumber.isNumber()) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1137
	return context._RETURN( self.minus(aNumber) );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1138
    }
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1139
#else
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1140
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1141
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1142
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1143
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1144
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1145
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1146
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1147
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1148
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1149
     */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1150
    OBJ newFloat;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1151
    double result;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1152
250
a5deb61ffdac *** empty log message ***
claus
parents: 224
diff changeset
  1153
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1154
	result = __floatVal(self) - (double)(__intVal(aNumber));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1155
retResult:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1156
	__qMKFLOAT(newFloat, result);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1157
	RETURN ( newFloat );
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1158
    }
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1159
    /* knowing that aNumber is not a SmallInt, we only need to check for nil;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1160
     * then can use qIsXXX macros which saves us some checks
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1161
     */
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1162
    if (aNumber != nil) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1163
	if (__qIsFloatLike(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1164
	    result = __floatVal(self) - __floatVal(aNumber);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1165
	    goto retResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1166
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1167
	if (__qIsShortFloat(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1168
	    result = __floatVal(self) - (double)(__shortFloatVal(aNumber));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1169
	    goto retResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1170
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1171
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1172
#endif
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
  1173
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1174
    ^ aNumber differenceFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1175
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1176
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1177
/ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1178
    "return the quotient of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1179
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1180
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1181
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1182
    if (aNumber.isNumber()) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1183
	return context._RETURN( self.quotient(aNumber) );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1184
    }
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1185
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1186
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1187
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1188
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1189
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1190
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1191
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1192
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1193
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1194
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
  1195
     */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1196
    OBJ newFloat;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1197
    double result, val;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1198
250
a5deb61ffdac *** empty log message ***
claus
parents: 224
diff changeset
  1199
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1200
	if (aNumber != __mkSmallInteger(0)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1201
	    result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1202
retResult:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1203
	    __qMKFLOAT(newFloat, result);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1204
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1205
	}
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
  1206
    } else if (__isFloatLike(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1207
	val = __floatVal(aNumber);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1208
	if (val != 0.0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1209
	    result = __floatVal(self) / val;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1210
	    goto retResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1211
	}
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
  1212
    } else if (__isShortFloat(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1213
	val = (double)(__shortFloatVal(aNumber));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1214
	if (val != 0.0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1215
	    result = __floatVal(self) / val;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1216
	    goto retResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1217
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1218
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1219
#endif
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
  1220
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1221
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1222
	"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1223
	 No, you shalt not divide by zero
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1224
	"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1225
	^ ZeroDivide raiseRequestWith:thisContext.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1226
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1227
    ^ aNumber quotientFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1228
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1229
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1230
abs
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1231
    "return the absolute value of the receiver
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1232
     reimplemented here for speed"
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1233
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1234
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1235
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1236
    return context._RETURN( self.abs() );
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1237
#else
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1238
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1239
    OBJ newFloat;
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1240
    double val =__floatVal(self);
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1241
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1242
    if (val < 0.0) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1243
	__qMKFLOAT(newFloat, -val);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1244
	RETURN ( newFloat );
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1245
    }
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1246
    RETURN (self);
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1247
#endif
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1248
%}.
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1249
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1250
    "
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1251
     3.0 abs
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1252
     -3.0 abs
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1253
    "
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1254
!
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1255
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1256
negated
17226
cb6ca4b18f06 class: Float
Claus Gittinger <cg@exept.de>
parents: 17218
diff changeset
  1257
    "return the receiver negated"
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1258
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1259
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1260
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1261
    return context._RETURN( self.negated() );
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1262
#else
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1263
    OBJ newFloat;
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1264
    double rslt = - __floatVal(self);
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1265
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1266
    __qMKFLOAT(newFloat, rslt);
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1267
    RETURN ( newFloat );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1268
#endif
14923
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1269
%}.
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1270
!
d17a1105f17c class: Float
Claus Gittinger <cg@exept.de>
parents: 14751
diff changeset
  1271
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1272
rem: aNumber
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1273
    "return the floating point remainder of the receiver and the argument, aNumber"
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1274
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1275
%{  /* NOCONTEXT */
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1276
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1277
    /*
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1278
     * notice:
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1279
     * the following inline code handles some common cases,
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1280
     * and exists as an optimization, to speed up those cases.
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1281
     *
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1282
     * Conceptionally, (and for most other argument types),
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1283
     * mixed arithmetic is implemented by double dispatching
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1284
     * (see the message send at the bottom)
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1285
     */
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1286
    OBJ newFloat;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1287
    double result, val;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1288
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1289
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1290
	if (aNumber != __mkSmallInteger(0)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1291
	    val = (double)__intVal(aNumber);
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1292
computeResult:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1293
	    result = fmod(__floatVal(self), val) ;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1294
	    __qMKFLOAT(newFloat, result);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1295
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1296
	}
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1297
    } else if (__isFloatLike(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1298
	val = __floatVal(aNumber);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1299
	if (val != 0.0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1300
	    goto computeResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1301
	}
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1302
    } else if (__isShortFloat(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1303
	val = (double)(__shortFloatVal(aNumber));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1304
	if (val != 0.0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1305
	    goto computeResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1306
	}
14720
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
  1307
#ifdef LONGFLOAT_KNOWN_HERE
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
  1308
    } else if (__isLongFloat(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1309
	long double lval;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1310
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1311
	lval = (long double)(__longFloatVal(aNumber));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1312
	if (val != 0.0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1313
	    long double lResult;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1314
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1315
	    lResult = fmodl((long double)(__floatVal(self)), lval);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1316
	    __qMKLFLOAT(newFloat, lResult);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1317
	    RETURN (newFloat);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1318
	}
14720
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
  1319
#endif
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1320
    }
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1321
%}.
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1322
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1323
	"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1324
	 No, you shalt not divide by zero
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1325
	"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1326
	^ ZeroDivide raiseRequestWith:thisContext.
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1327
    ].
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1328
    ^ aNumber remainderFromFloat:self
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1329
!
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
  1330
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1331
uncheckedDivide:aNumber
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1332
    "return the quotient of the receiver and the argument, aNumber.
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7441
diff changeset
  1333
     Do not check for divide by zero (return NaN or Infinity).
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1334
     This operation is provided for emulators of other languages/semantics,
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1335
     where no exception is raised for these results (i.e. Java).
18838
20220bfa6867 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18492
diff changeset
  1336
     It is only defined if the argument's type is the same as the receiver's."
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1337
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1338
%{  /* NOCONTEXT */
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1339
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1340
    OBJ newFloat;
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1341
    double result, val;
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1342
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1343
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1344
	result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1345
retResult:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1346
	__qMKFLOAT(newFloat, result);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1347
	RETURN ( newFloat );
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1348
    }
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1349
    if (__isFloatLike(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1350
	val = __floatVal(aNumber);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1351
	result = __floatVal(self) / val;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1352
	goto retResult;
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1353
    }
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1354
    if (__isShortFloat(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1355
	val = (double)(__shortFloatVal(aNumber));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1356
	result = __floatVal(self) / val;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1357
	goto retResult;
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1358
    }
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1359
%}.
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1360
    ^ aNumber quotientFromFloat:self
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1361
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1362
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1363
      0.0 uncheckedDivide:0.0
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1364
      1.0 uncheckedDivide:0.0
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1365
      -1.0 uncheckedDivide:0.0
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1366
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1367
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1368
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1369
5238
f7a816a660a3 categories
Claus Gittinger <cg@exept.de>
parents: 5120
diff changeset
  1370
!Float methodsFor:'coercing & converting'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1371
3014
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
  1372
asDouble
17226
cb6ca4b18f06 class: Float
Claus Gittinger <cg@exept.de>
parents: 17218
diff changeset
  1373
    "ST80 compatibility: return a double with the receiver's value.
cb6ca4b18f06 class: Float
Claus Gittinger <cg@exept.de>
parents: 17218
diff changeset
  1374
     In ST/X, floats are the equivalent to ST80 doubles"
3014
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
  1375
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
  1376
    ^ self
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
  1377
!
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
  1378
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1379
asFloat
24280
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1380
    "return a Float with same value - that's me"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1381
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1382
    ^ self
24280
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1383
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1384
    "Modified (comment): / 07-06-2019 / 02:34:18 / Claus Gittinger"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1385
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1386
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1387
asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1388
    "return an integer with same value - might truncate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1389
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1390
%{  /* NOCONTEXT */
1670
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1391
    double dVal;
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1392
1670
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1393
    dVal = __floatVal(self);
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
  1394
#ifdef __win32__
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1395
    if (! isnan(dVal))
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
  1396
#endif
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
  1397
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1398
	if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1399
	    RETURN ( __mkSmallInteger( (INT)dVal) );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1400
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1401
    }
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1402
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1403
    ^ super asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1404
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1405
    "12345.0 asInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1406
    "1e15 asInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1407
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1408
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1409
asLongFloat
24280
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1410
    "return a LongFloat with same value as receiver"
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1411
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1412
    ^ LongFloat fromFloat:self
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1413
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1414
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1415
     123 asFloat asLongFloat
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1416
    "
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1417
24280
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1418
    "Created: / 07-09-2001 / 13:43:04 / cg"
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1419
    "Modified (comment): / 07-06-2019 / 02:34:07 / Claus Gittinger"
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1420
!
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1421
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1422
asShortFloat
24280
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1423
    "return a ShortFloat with same value as receiver.
24249
17326e1df17f raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents: 24230
diff changeset
  1424
     Raises an error if the receiver exceeds the float range."
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1425
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1426
%{  /* NOCONTEXT */
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1427
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1428
    OBJ dummy = @global(ShortFloat);
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1429
    OBJ newFloat;
24255
82a37ed5a27c oops - converting NaN
Claus Gittinger <cg@exept.de>
parents: 24249
diff changeset
  1430
    double dVal = __floatVal(self);
82a37ed5a27c oops - converting NaN
Claus Gittinger <cg@exept.de>
parents: 24249
diff changeset
  1431
    float fVal = (float)dVal;
82a37ed5a27c oops - converting NaN
Claus Gittinger <cg@exept.de>
parents: 24249
diff changeset
  1432
82a37ed5a27c oops - converting NaN
Claus Gittinger <cg@exept.de>
parents: 24249
diff changeset
  1433
    if (isfinite(fVal) || !isfinite(dVal)) {
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1434
	__qMKSFLOAT(newFloat, fVal);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1435
	RETURN ( newFloat );
24249
17326e1df17f raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents: 24230
diff changeset
  1436
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1437
%}.
24249
17326e1df17f raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents: 24230
diff changeset
  1438
    "
17326e1df17f raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents: 24230
diff changeset
  1439
     value out of range
17326e1df17f raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents: 24230
diff changeset
  1440
     if you need -INF for a zero receiver, try Number trapInfinity:[...]
17326e1df17f raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents: 24230
diff changeset
  1441
    "
17326e1df17f raise exception on out-of-range in asShortFloat / asFloat
Claus Gittinger <cg@exept.de>
parents: 24230
diff changeset
  1442
    ^ self class
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1443
	raise:#infiniteResultSignal
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1444
	receiver:self
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1445
	selector:#asShortFloat
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1446
	arguments:#()
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1447
	errorString:'receiver is out of the single-precision float range'
24280
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1448
95d601984b32 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24266
diff changeset
  1449
    "Modified: / 07-06-2019 / 02:34:14 / Claus Gittinger"
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1450
!
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1451
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1452
asTrueFraction
17226
cb6ca4b18f06 class: Float
Claus Gittinger <cg@exept.de>
parents: 17218
diff changeset
  1453
    "Answer a fraction or integer that EXACTLY represents the receiver,
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1454
     a double precision IEEE floating point number.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1455
     Floats are stored in the same form on all platforms.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1456
     (Does not handle gradual underflow or NANs.)
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1457
     By David N. Smith with significant performance
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1458
     improvements by Luciano Esteban Notarfrancesco.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1459
     (Version of 11April97)"
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1460
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1461
    |shifty sign expPart exp fraction fractionPart result zeroBitsCount|
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1462
6344
f49b43e5b724 Raise more specific errors
Stefan Vogel <sv@exept.de>
parents: 6341
diff changeset
  1463
    self isFinite ifFalse:[
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1464
	^ self asMetaNumber
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1465
"/        ^ self class
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1466
"/            raise:#domainErrorSignal
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1467
"/            receiver:self
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1468
"/            selector:#asTrueFraction
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1469
"/            arguments:#()
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1470
"/            errorString:'Cannot represent non-finite float as a fraction'.
6341
19a407a314da Raise more specific signals.
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
  1471
    ].
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1472
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1473
    "Extract the bits of an IEEE double float "
6341
19a407a314da Raise more specific signals.
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
  1474
    shifty := LargeInteger basicNew numberOfDigits:8.
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1475
    UninterpretedBytes isBigEndian ifTrue:[
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1476
	"/ shifty := ((self longWordAt: 1) bitShift: 32) + (self longWordAt: 2).
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1477
	1 to:8 do:[:i | shifty digitAt:(9-i) put:(self basicAt:i)].
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1478
    ] ifFalse:[
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1479
	1 to:8 do:[:i | shifty digitAt:i put:(self basicAt:i)].
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1480
    ].
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1481
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1482
    " Extract the sign and the biased exponent "
24745
c64356429753 #TUNING by exept
Claus Gittinger <cg@exept.de>
parents: 24710
diff changeset
  1483
    sign := (shifty bitShift: -63) == 0 ifTrue: [1] ifFalse: [-1].
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1484
    expPart := (shifty bitShift: -52) bitAnd: 16r7FF.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1485
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1486
    " Extract fractional part; answer 0 if this is a true 0.0 value "
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1487
    fractionPart := shifty bitAnd:  16r000FFFFFFFFFFFFF.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1488
    ( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0  ].
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1489
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1490
    " Replace omitted leading 1 in fraction "
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1491
    fraction := fractionPart bitOr: 16r0010000000000000.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1492
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1493
    "Unbias exponent: 16r3FF is bias; 52 is fraction width"
7480
74f8bf8628e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1494
    exp := 16r3FF - expPart + 52.
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1495
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1496
    " Form the result. When exp>52, the exponent is adjusted by
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1497
      the number of trailing zero bits in the fraction to minimize
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1498
      the (huge) time otherwise spent in #gcd:. "
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1499
    exp negative ifTrue: [
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1500
	result := sign * (fraction bitShift: exp negated)
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1501
    ] ifFalse:[
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1502
	zeroBitsCount := fraction lowBit - 1.
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1503
	exp := exp - zeroBitsCount.
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1504
	exp <= 0 ifTrue: [
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1505
	    zeroBitsCount := zeroBitsCount + exp.
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1506
	    "exp := 0."   " Not needed; exp not refernced again "
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1507
	    result := sign * (fraction bitShift:zeroBitsCount negated)
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1508
	] ifFalse: [
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1509
	    result := Fraction
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1510
		    numerator: (sign * (fraction bitShift: zeroBitsCount negated))
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1511
		    denominator: (1 bitShift:exp)
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1512
	]
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1513
    ].
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1514
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1515
    "Low cost validation omitted after extensive testing"
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1516
    "(result asFloat = self) ifFalse: [self error: 'asTrueFraction validation failed']."
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1517
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1518
    ^ result
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1519
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1520
    "
17226
cb6ca4b18f06 class: Float
Claus Gittinger <cg@exept.de>
parents: 17218
diff changeset
  1521
     0.3 asTrueFraction          - as you can see, Float is not able to represent this exactly
cb6ca4b18f06 class: Float
Claus Gittinger <cg@exept.de>
parents: 17218
diff changeset
  1522
     1.25 asTrueFraction         - but this one (it is a sum of powers of two)
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1523
     0.25 asTrueFraction
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1524
     -0.25 asTrueFraction
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1525
     3e37 asTrueFraction
17226
cb6ca4b18f06 class: Float
Claus Gittinger <cg@exept.de>
parents: 17218
diff changeset
  1526
     2e37 asTrueFraction
cb6ca4b18f06 class: Float
Claus Gittinger <cg@exept.de>
parents: 17218
diff changeset
  1527
     1e37 asTrueFraction
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1528
     1e30 asTrueFraction
6341
19a407a314da Raise more specific signals.
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
  1529
     Float NaN asTrueFraction
6344
f49b43e5b724 Raise more specific errors
Stefan Vogel <sv@exept.de>
parents: 6341
diff changeset
  1530
     Float infinity asTrueFraction
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1531
    "
24230
f51b6573478d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24206
diff changeset
  1532
f51b6573478d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24206
diff changeset
  1533
    "Modified (format): / 29-05-2019 / 03:12:55 / Claus Gittinger"
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1534
!
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1535
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1536
coerce:aNumber
18838
20220bfa6867 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18492
diff changeset
  1537
    "convert the argument aNumber into an instance of the receiver's class and return it."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1538
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1539
    ^ aNumber asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1540
!
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1541
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1542
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1543
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1544
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1545
    ^ 80
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1546
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1547
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1548
!Float methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1549
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1550
< aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1551
    "return true, if the argument is greater"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1552
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1553
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1554
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1555
    if (aNumber.isNumber()) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1556
	return context._RETURN( self.ltP(aNumber) );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1557
    }
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1558
#else
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1559
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1560
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1561
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1562
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1563
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1564
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1565
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1566
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1567
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1568
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1569
	RETURN ( (__floatVal(self) < (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1570
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1571
    if (aNumber != nil) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1572
	if (__qIsFloatLike(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1573
	    RETURN ( (__floatVal(self) < __floatVal(aNumber)) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1574
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1575
	if (__qIsShortFloat(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1576
	    RETURN ( (__floatVal(self) < (double)(__shortFloatVal(aNumber))) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1577
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1578
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1579
#endif
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1580
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1581
    ^ aNumber lessFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1582
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1583
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1584
<= aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1585
    "return true, if the argument is greater or equal"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1586
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1587
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1588
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1589
    if (aNumber.isNumber()) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1590
	return context._RETURN( self.leP(aNumber) );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1591
    }
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1592
#else
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1593
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1594
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1595
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1596
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1597
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1598
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1599
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1600
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1601
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1602
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1603
	RETURN ( (__floatVal(self) <= (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1604
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1605
    if (aNumber != nil) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1606
	if (__qIsFloatLike(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1607
	    RETURN ( (__floatVal(self) <= __floatVal(aNumber)) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1608
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1609
	if (__qIsShortFloat(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1610
	    RETURN ( (__floatVal(self) <= (double)(__shortFloatVal(aNumber))) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1611
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1612
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1613
#endif
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1614
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1615
    ^ self retry:#<= coercing:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1616
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1617
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1618
= aNumber
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1619
    "return true, if the argument represents the same numeric value
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1620
     as the receiver, false otherwise"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1621
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1622
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1623
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1624
    if (aNumber.isNumber()) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1625
	return context._RETURN( self.eqNrP(aNumber) );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1626
    }
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1627
#else
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1628
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1629
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1630
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1631
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1632
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1633
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1634
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1635
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1636
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1637
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1638
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1639
	RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1640
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1641
    if (aNumber != nil) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1642
	if (__qIsFloatLike(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1643
	    RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1644
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1645
	if (__qIsShortFloat(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1646
	    RETURN ( (__floatVal(self) == (double)(__shortFloatVal(aNumber))) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1647
	}
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1648
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1649
	RETURN (false);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1650
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1651
#endif
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1652
%}.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1653
    ^ aNumber equalFromFloat:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1654
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1655
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1656
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1657
    "return true, if the argument is less"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1658
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1659
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1660
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1661
    if (aNumber.isNumber()) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1662
	return context._RETURN( self.gtP(aNumber) );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1663
    }
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1664
#else
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1665
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1666
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1667
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1668
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1669
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1670
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1671
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1672
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1673
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1674
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1675
	RETURN ( (__floatVal(self) > (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1676
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1677
    if (aNumber != nil) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1678
	if (__qIsFloatLike(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1679
	    RETURN ( (__floatVal(self) > __floatVal(aNumber)) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1680
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1681
	if (__qIsShortFloat(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1682
	    RETURN ( (__floatVal(self) > (double)(__shortFloatVal(aNumber))) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1683
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1684
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1685
#endif
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1686
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1687
    ^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1688
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1689
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1690
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1691
    "return true, if the argument is less or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1692
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1693
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1694
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1695
    if (aNumber.isNumber()) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1696
	return context._RETURN( self.geP(aNumber) );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1697
    }
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1698
#else
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1699
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1700
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1701
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1702
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1703
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1704
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1705
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1706
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1707
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1708
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1709
	RETURN ( (__floatVal(self) >= (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1710
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1711
    if (aNumber != nil) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1712
	if (__qIsFloatLike(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1713
	    RETURN ( (__floatVal(self) >= __floatVal(aNumber)) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1714
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1715
	if (__qIsShortFloat(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1716
	    RETURN ( (__floatVal(self) >= (double)(__shortFloatVal(aNumber))) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1717
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1718
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  1719
#endif
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1720
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1721
    ^ self retry:#>= coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1722
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1723
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1724
hash
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1725
    "return a number for hashing; redefined, since floats compare
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1726
     by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same
4594
eb09f567a3bc float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents: 4593
diff changeset
  1727
     as 3 hash."
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1728
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
  1729
    |i|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1730
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1731
    (self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1732
	i := self asInteger.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1733
	self = i ifTrue:[
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1734
	    ^ i hash
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1735
	].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1736
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1737
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1738
    "
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
  1739
     mhmh take some of my value-bits to hash on
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1740
    "
4590
3db3bf4615bd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1741
    ^ (((self basicAt:8) bitAnd:16r1F) bitShift:24) +
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
  1742
      ((self basicAt:7) bitShift:16) +
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
  1743
      ((self basicAt:6) bitShift:8) +
4592
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  1744
      (((self basicAt:5) + (self basicAt:1) + (self basicAt:2)) bitAnd:16rFF)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1745
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1746
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1747
     3 hash
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1748
     3.0 hash
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1749
     3.1 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1750
     3.14159 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1751
     31.4159 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1752
     3.141591 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1753
     1.234567890123456 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1754
     1.234567890123457 hash
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1755
     Set withAll:#(3 3.0 99 99.0 3.1415)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1756
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1757
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1758
17199
63d9a071e8ff added cbrt
Claus Gittinger <cg@exept.de>
parents: 16669
diff changeset
  1759
isAlmostEqualTo:aNumber nEpsilon:nE
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1760
    "return true, if the argument, aNumber represents almost the same numeric value
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1761
     as the receiver, false otherwise.
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1762
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1763
     nE is the number of minimal float distances, that the numbers may differ and
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
  1764
     still be considered equal.
22559
ff1a09a98286 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
  1765
     That is an integer, which counts the delta-steps in the mantissa.
ff1a09a98286 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
  1766
     Notice, that the absolute value of the epsilon depends on the receiver
ff1a09a98286 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
  1767
     (i.e. with a receiver of 10^17, a mantissa-step is much larger than with 10^-17 as receiver)
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1768
17199
63d9a071e8ff added cbrt
Claus Gittinger <cg@exept.de>
parents: 16669
diff changeset
  1769
     For background information why floats need this
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1770
     read: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1771
    "
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1772
21148
2b7df33ee311 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20799
diff changeset
  1773
    Epsilon isNil ifTrue:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1774
	Epsilon := self class computeEpsilon.
21148
2b7df33ee311 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20799
diff changeset
  1775
    ].
2b7df33ee311 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20799
diff changeset
  1776
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1777
%{  /* NOCONTEXT */
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1778
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1779
    /*
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1780
     * notice:
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1781
     * the following inline code handles some common cases,
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1782
     * and exists as an optimization, to speed up those cases.
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1783
     *
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1784
     * Conceptionally, (and for most other argument types),
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1785
     * mixed arithmetic is implemented by double dispatching
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1786
     * (see the message send at the bottom)
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1787
     */
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1788
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1789
    INT64 ulpDiff;
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1790
    union {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1791
	double d;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1792
	INT64 i;
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1793
    } myself, otherFloat;
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1794
    int nEpsilon;
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1795
    double scaledEpsilon;
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1796
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1797
    if (!__isSmallInteger(nE)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1798
	goto tryHarder;
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1799
    }
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1800
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1801
    nEpsilon =  __intVal(nE);
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1802
    scaledEpsilon = nEpsilon *__floatVal(@global(Epsilon));
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1803
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1804
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1805
	otherFloat.d = (double)(__intVal(aNumber));
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1806
    } else if (aNumber == nil) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1807
	RETURN(false)
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1808
    } else if (__qIsFloatLike(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1809
	otherFloat.d = (double)(__floatVal(aNumber));
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1810
    } else if (__qIsShortFloat(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1811
	otherFloat.d = (double)(__shortFloatVal(aNumber));
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1812
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1813
	goto tryHarder;
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1814
    }
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1815
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1816
    myself.d = __floatVal(self);
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1817
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1818
    // Check if the numbers are really close -- needed
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1819
    // when comparing numbers near zero (ULP method below fails for numbers near 0!).
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1820
    if (fabs(myself.d - otherFloat.d) <= scaledEpsilon) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1821
	RETURN(true);
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1822
    }
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1823
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1824
    // if the signs differ, the numbers are different
16667
a659a8f95304 changes for borland
Claus Gittinger <cg@exept.de>
parents: 16661
diff changeset
  1825
    if ((myself.d >= 0) != (otherFloat.d >= 0)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1826
	RETURN(false);
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1827
    }
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1828
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1829
    // compute the difference of the 'units in the last place" ULP
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1830
    // (if ulpDiff == 1, two floats are adjecant)
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1831
    ulpDiff = myself.i - otherFloat.i;
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1832
    if (ulpDiff < 0) ulpDiff = -ulpDiff;
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1833
    if (ulpDiff <= nEpsilon) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1834
	RETURN(true);
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1835
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1836
	RETURN(false)
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1837
    }
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1838
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1839
tryHarder:;
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1840
%}.
22559
ff1a09a98286 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
  1841
    nE isInteger ifFalse:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1842
	self error:'nEpsilon argument must be an integer'.
22559
ff1a09a98286 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 22491
diff changeset
  1843
    ].
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1844
    ^ aNumber isAlmostEqualToFromFloat:self nEpsilon:nE
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1845
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1846
    "
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1847
	67329.234 isAlmostEqualTo:67329.23400000001 nEpsilon:1
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1848
	1.0 isAlmostEqualTo:1.0001 nEpsilon:1
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1849
	1.0 isAlmostEqualTo:-1.0 nEpsilon:1
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1850
	1 isAlmostEqualTo:1.000000000000001 nEpsilon:1
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1851
	1 isAlmostEqualTo:1.000000000000001 nEpsilon:10
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1852
	1.0 isAlmostEqualTo:1 nEpsilon:1
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1853
	1.0 isAlmostEqualTo:1 asFraction nEpsilon:1
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1854
	0.0 isAlmostEqualTo:0 nEpsilon:1
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1855
	0.0 isAlmostEqualTo:self epsilon nEpsilon:1
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1856
    "
22854
fad0230dcfcf #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22728
diff changeset
  1857
fad0230dcfcf #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22728
diff changeset
  1858
    "Modified: / 10-05-2018 / 00:48:57 / stefan"
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1859
!
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  1860
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1861
~= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1862
    "return true, if the arguments value are not equal"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1863
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1864
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1865
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1866
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1867
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1868
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1869
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1870
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1871
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1872
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1873
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1874
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1875
    if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1876
	RETURN ( (__floatVal(self) != (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1877
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1878
    if (aNumber != nil) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1879
	if (__qIsFloatLike(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1880
	    RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1881
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1882
	if (__qIsShortFloat(aNumber)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1883
	    RETURN ( (__floatVal(self) != (double)(__shortFloatVal(aNumber))) ? true : false );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1884
	}
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1885
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1886
	RETURN ( true );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1887
    }
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1888
%}.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1889
    ^ super ~= aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1890
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1891
24191
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1892
!Float methodsFor:'copying'!
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1893
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1894
deepCopy
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1895
    "return a deep copy of myself
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1896
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1897
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1898
    ^ self
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1899
!
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1900
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1901
deepCopyUsing:aDictionary postCopySelector:postCopySelector
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1902
    "return a deep copy of myself
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1903
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1904
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1905
    ^ self
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1906
!
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1907
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1908
shallowCopy
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1909
    "return a shallow copy of the receiver"
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1910
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1911
    ^ self
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1912
!
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1913
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1914
simpleDeepCopy
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1915
    "return a deep copy of the receiver
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1916
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1917
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1918
    ^ self
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1919
! !
43920a4e5002 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24169
diff changeset
  1920
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1921
!Float methodsFor:'mathematical functions'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1922
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1923
cbrt
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1924
    "return the cubic root of myself."
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1925
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1926
%{  /* NOCONTEXT */
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1927
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
  1928
#ifndef __win32__ /* seems to be not avail. in WIN32 math lib */
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1929
    double val, rslt;
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1930
    OBJ newFloat;
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1931
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1932
    val = __floatVal(self);
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1933
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1934
    {
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1935
	__threadErrno = 0;
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1936
	rslt = cbrt(val);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1937
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1938
	{
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1939
	    if (__threadErrno == 0) {
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1940
		__qMKFLOAT(newFloat, rslt);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1941
		RETURN ( newFloat );
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1942
	    }
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1943
	}
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1944
    }
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1945
# endif /* WIN32 */
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1946
%}.
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1947
    ^ super cbrt
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1948
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1949
    "
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1950
     8 cbrt
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1951
     -8 cbrt
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1952
     8.0 cbrt
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1953
     -8.0 cbrt
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1954
     8.0 raisedTo:(1/3)
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1955
     -8.0 raisedTo:(1/3)
17218
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1956
    "
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1957
!
3d97edbc08f8 class: Float
Stefan Vogel <sv@exept.de>
parents: 17200
diff changeset
  1958
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1959
exp
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1960
    "return e raised to the power of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1961
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1962
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1963
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1964
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1965
    OBJ newFloat;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1966
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1967
    __threadErrno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1968
    rslt = exp(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  1969
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  1970
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1971
	if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1972
	    __qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1973
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1974
	}
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1975
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1976
%}.
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3279
diff changeset
  1977
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1978
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1979
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1980
	selector:#exp
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1981
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  1982
	errorString:'bad receiver in exp'
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6193
diff changeset
  1983
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6193
diff changeset
  1984
    "Modified: / 16.11.2001 / 14:14:29 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1985
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1986
21832
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  1987
ldexp:exp
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  1988
    "multiply the receiver by an integral power of 2.
24974
58dffe3baf29 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24969
diff changeset
  1989
     I.e. return self * (2 ^ exp).
58dffe3baf29 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24969
diff changeset
  1990
     This is also the operation to reconstruct the original float from its
58dffe3baf29 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24969
diff changeset
  1991
     mantissa and exponent: (f mantissa ldexp:f exponent) = f"
21832
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  1992
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  1993
%{  /* NOCONTEXT */
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  1994
#ifndef __SCHTEAM__
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  1995
    double val, rslt;
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  1996
    OBJ newFloat;
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  1997
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  1998
    if (__isSmallInteger(exp)) {
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  1999
	int __exp = __intVal(exp);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2000
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2001
	val = __floatVal(self);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2003
	{
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2004
	    __threadErrno = 0;
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2005
	    rslt = ldexp(val, __exp);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2006
	    if (! isnan(rslt))  /* Currently all our systems support isnan() */
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2007
	    {
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2008
		if (__threadErrno == 0) {
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2009
		    __qMKFLOAT(newFloat, rslt);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2010
		    RETURN ( newFloat );
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2011
		}
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2012
	    }
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2013
	}
21832
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  2014
    }
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  2015
#endif
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  2016
%}.
21835
9bdc9ff693ef #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21832
diff changeset
  2017
    ^ super ldexp:exp
21832
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  2018
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  2019
    "
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2020
     1.0 mantissa ldexp:1.0 exponent
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2021
     -1.0 mantissa ldexp:-1.0 exponent
24974
58dffe3baf29 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24969
diff changeset
  2022
24958
6a9965ea9d85 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24957
diff changeset
  2023
     1.0 ldexp:16  -> 65536.0
6a9965ea9d85 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24957
diff changeset
  2024
     1.0 ldexp:100 -> 1.26765060022823E+30
6a9965ea9d85 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24957
diff changeset
  2025
     1 * (2 raisedToInteger:100) -> 1267650600228229401496703205376
6a9965ea9d85 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24957
diff changeset
  2026
     1.0 ldexp:200 -> 1.60693804425899E+60
21832
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  2027
    "
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  2028
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  2029
    "Created: / 19-06-2017 / 01:42:22 / cg"
21835
9bdc9ff693ef #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21832
diff changeset
  2030
    "Modified: / 19-06-2017 / 09:16:32 / cg"
21832
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  2031
!
ea2680fc4ea9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21824
diff changeset
  2032
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2033
ln
6193
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  2034
    "return the natural logarithm of myself.
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  2035
     Raises an exception, if the receiver is less or equal to zero."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2036
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2037
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2038
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  2039
    return context._RETURN( self.log() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2040
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2041
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  2042
    double val, rslt;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2043
    OBJ newFloat;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2044
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  2045
    val = __floatVal(self);
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  2046
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
  2047
    /*
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
  2048
     * to suppress the warnBox opened by win32
21952
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2049
     * to avoid returning -INF from some unix math libs (__osx__)
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2050
     */
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2051
    if (val > 0.0) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2052
	__threadErrno = 0;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2053
	rslt = log(val);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2054
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2055
	{
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2056
	    if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2057
		__qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2058
		RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2059
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2060
	}
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2061
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2062
#endif
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2063
%}.
142
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
  2064
    "
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
  2065
     an invalid value for logarithm
21970
c57071d829f7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21968
diff changeset
  2066
     if you need -INF for a zero receiver, try Number trapInfinity:[...]
142
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
  2067
    "
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3279
diff changeset
  2068
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2069
	raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2070
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2071
	selector:#ln
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2072
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2073
	errorString:'bad receiver in ln (not strictly positive)'
21952
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2074
21970
c57071d829f7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21968
diff changeset
  2075
    "Modified (comment): / 03-07-2017 / 15:58:17 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2076
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2077
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2078
log10
21824
a0ef855253f9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21148
diff changeset
  2079
    "return the base-10 logarithm of the receiver.
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2080
     Raises an exception, if the receiver is less or equal to zero."
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2081
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2082
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2083
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  2084
    return context._RETURN( self.log10() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2085
#else
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2086
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2087
    double val, rslt;
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2088
    OBJ newFloat;
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2089
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2090
    val = __floatVal(self);
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2091
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
  2092
    /*
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
  2093
     * to suppress the warnBox opened by win32
21953
ebaf440a6e48 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21952
diff changeset
  2094
     * to avoid returning -INF from some unix math libs (__osx__)
ebaf440a6e48 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21952
diff changeset
  2095
     */
ebaf440a6e48 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21952
diff changeset
  2096
    if (val > 0.0) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2097
	__threadErrno = 0;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2098
	rslt = log10(val);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2099
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2100
	{
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2101
	    if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2102
		__qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2103
		RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2104
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2105
	}
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2106
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2107
#endif
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2108
%}.
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2109
    "
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2110
     an invalid value for logarithm
21970
c57071d829f7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21968
diff changeset
  2111
     if you need -INF for a zero receiver, try Number trapInfinity:[...]
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2112
    "
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2113
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2114
	raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2115
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2116
	selector:#log10
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2117
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2118
	errorString:'bad receiver in log10 (not strictly positive)'
21953
ebaf440a6e48 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21952
diff changeset
  2119
21970
c57071d829f7 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21968
diff changeset
  2120
    "Modified (comment): / 03-07-2017 / 15:58:21 / cg"
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2121
!
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  2122
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2123
raisedTo:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2124
    "return self raised to the power of aNumber"
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2125
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2126
%{
21936
5a4a6a7c47d3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21913
diff changeset
  2127
    double _n, rslt;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2128
    OBJ newFloat;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2129
21936
5a4a6a7c47d3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21913
diff changeset
  2130
    if (__isFloatLike(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2131
	_n = __floatVal(aNumber);
21936
5a4a6a7c47d3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21913
diff changeset
  2132
    } else if (__isSmallInteger(aNumber)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2133
	_n = (double)__intVal(aNumber);
21936
5a4a6a7c47d3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21913
diff changeset
  2134
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2135
	goto notEasy;
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
  2136
    }
21936
5a4a6a7c47d3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21913
diff changeset
  2137
    __threadErrno = 0;
5a4a6a7c47d3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21913
diff changeset
  2138
    rslt = pow(__floatVal(self), _n);
5a4a6a7c47d3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21913
diff changeset
  2139
    if (! isnan(rslt)) { /* Currently all our systems support isnan() */
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2140
	if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2141
	    __qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2142
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2143
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2144
    }
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
  2145
notEasy: ;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2146
%}.
21913
018adffb2e93 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21909
diff changeset
  2147
    "/ the c-library pow function, has a bug:
19570
017c53457288 lazy computation of epsilon
Claus Gittinger <cg@exept.de>
parents: 19358
diff changeset
  2148
    "/ it does not deal correctly with negative numbers.
19091
12b1f7ebf405 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18857
diff changeset
  2149
    "/ I.e. it raises an error on -8^(1/3) instead of returning a negative -2
12b1f7ebf405 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18857
diff changeset
  2150
    "/ work around with a kludge:
12b1f7ebf405 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18857
diff changeset
  2151
    self < 0 ifTrue:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2152
	^ (self negated raisedTo:aNumber) negated
19091
12b1f7ebf405 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18857
diff changeset
  2153
    ].
12b1f7ebf405 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18857
diff changeset
  2154
21936
5a4a6a7c47d3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21913
diff changeset
  2155
    ^ aNumber raisedFromFloat:self
5a4a6a7c47d3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21913
diff changeset
  2156
5a4a6a7c47d3 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21913
diff changeset
  2157
    "Modified: / 01-07-2017 / 21:58:26 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2158
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2159
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2160
reciprocalLogBase2
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2161
    "optimized for self = 10, for use in conversion for printing"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2162
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2163
    ^ self = 10.0s
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2164
	ifTrue: [Ln2 / Ln10]
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2165
	ifFalse: [Ln2 / self ln]
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2166
!
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2167
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2168
sqrt
6193
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  2169
    "return the square root of myself.
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  2170
     Raises an exception, if the receiver is less than zero."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2171
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2172
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2173
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  2174
    double val, rslt;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2175
    OBJ newFloat;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2176
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  2177
    val = __floatVal(self);
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  2178
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
  2179
#ifdef __win32__ /* to suppress the warnBox opened by win32 */
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  2180
    if (val >= 0.0)
3889
3466554b639f manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents: 3632
diff changeset
  2181
#endif
3466554b639f manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents: 3632
diff changeset
  2182
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2183
	__threadErrno = 0;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2184
	rslt = sqrt(val);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2185
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2186
	{
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2187
	    if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2188
		__qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2189
		RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2190
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2191
	}
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2192
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2193
%}.
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3279
diff changeset
  2194
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2195
	raise:#imaginaryResultSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2196
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2197
	selector:#sqrt
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2198
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2199
	errorString:'bad (negative) receiver in sqrt'
3399
4f45ebb7bc60 oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
  2200
4f45ebb7bc60 oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
  2201
    "
4f45ebb7bc60 oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
  2202
     10 sqrt
4f45ebb7bc60 oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
  2203
     -10 sqrt
4f45ebb7bc60 oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
  2204
    "
6193
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  2205
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6193
diff changeset
  2206
    "Modified: / 16.11.2001 / 14:14:43 / cg"
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  2207
! !
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  2208
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2209
!Float methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2210
22301
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2211
printOn:aStream
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2212
    "append a printed representation of the receiver to
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2213
     the argument, aStream.
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2214
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2215
     I use #printString instead of #printOn: as basic print mechanism."
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2216
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2217
    aStream nextPutAll:self printString
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2218
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2219
    "Created: / 10-10-2017 / 14:05:13 / cg"
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2220
!
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2221
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2222
printString
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2223
    "return a printed representation of the receiver;
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2224
     if not specified otherwise (by setting DefaultPrintFormat),
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3163
diff changeset
  2225
     6 valid digits are printed.
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3163
diff changeset
  2226
     LimitedPrecisonReal and its subclasses use #printString instead of
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3163
diff changeset
  2227
     #printOn: as basic print mechanism."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2228
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
  2229
    ^ self printStringWithFormat:self class defaultPrintFormat
18138
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2230
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2231
    "
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2232
	Float pi printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2233
	1.0 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2234
	1.234 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2235
	1e10 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2236
	1e-60 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2237
	1.2e3 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2238
	1.2e30 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2239
	(1.0 uncheckedDivide:0) printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2240
	(0.0 uncheckedDivide:0) printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2241
	self pi printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2242
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2243
	DecimalPointCharacter := $,.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2244
	1.234 printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2245
	1.0 printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2246
	1e10 printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2247
	1.2e3 printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2248
	1.2e30 printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2249
	(1.0 uncheckedDivide:0) printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2250
	(0.0 uncheckedDivide:0) printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2251
	DecimalPointCharacter := $.
18138
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2252
    "
21877
3dd1362bd049 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21876
diff changeset
  2253
3dd1362bd049 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21876
diff changeset
  2254
    "Modified (comment): / 21-06-2017 / 09:46:01 / cg"
18138
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2255
!
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2256
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2257
printStringWithFormat:format
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2258
    "return a printed representation of the receiver;
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2259
     fmt must be of the form: .nn, where nn is the number of digits.
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2260
     To print 6 valid digits, use printStringWithFormat:'.6'
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2261
     For Floats, the default used in printString, is 15 (because its a double);
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2262
     for ShortFloats, it is 6 (because it is a float)"
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2263
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2264
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2265
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  2266
    char buffer[64];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2267
    REGISTER char *cp;
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2268
    OBJ s;
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2269
    char *fmt;
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2270
    char fmtBuffer[20];
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  2271
    int len;
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2272
18138
7b069a4727fd class: Float
Claus Gittinger <cg@exept.de>
parents: 18133
diff changeset
  2273
    if (__isStringLike(format)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2274
	fmt = (char *) __stringVal(format);
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2275
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2276
	/*
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2277
	 * in case we get called with garbage ...
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2278
	 */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2279
	fmt = ".15";
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2280
    }
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2281
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2282
    /*
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2283
     * build a printf format string
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2284
     */
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2285
    fmtBuffer[0] = '%';
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2286
    strncpy(fmtBuffer+1, fmt, 10);
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2287
#ifdef SYSV
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2288
    strcat(fmtBuffer, "lg");
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2289
#else
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2290
    strcat(fmtBuffer, "G");
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  2291
#endif
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2292
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  2293
    __BEGIN_PROTECT_REGISTERS__
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  2294
    len = snprintf(buffer, sizeof(buffer), fmtBuffer, __floatVal(self));
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  2295
    __END_PROTECT_REGISTERS__
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  2296
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  2297
    if (len >= 0 && len < sizeof(buffer)-3) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2298
	/*
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2299
	 * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2300
	 * (i.e. look if string contains '.' or 'e' and append '.0' if not)
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2301
	 */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2302
	for (cp = buffer; *cp; cp++) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2303
	    if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2304
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2305
	if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2306
	    if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2307
		*cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2308
	    } else {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2309
		*cp++ = '.';
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2310
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2311
	    *cp++ = '0';
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2312
	    *cp = '\0';
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2313
	} else {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2314
	    if (cp && ((*cp == '.') || (*cp == ','))) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2315
		if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2316
		    *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2317
		}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2318
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2319
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2320
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2321
	s = __MKSTRING(buffer);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2322
	if (s != nil) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2323
	    RETURN (s);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2324
	}
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2325
    }
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2326
%}.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2327
    "
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2328
     memory allocation (for the new string) failed.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2329
     When we arrive here, there was no memory, even after a garbage collect.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2330
     This means, that the VM wanted to get some more memory from the
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2331
     OS, which was not kind enough to give it.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2332
     Bad luck - you should increase the swap space on your machine.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2333
    "
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20415
diff changeset
  2334
    ^ AllocationFailure raise.
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2335
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2336
    "
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2337
	1.0 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2338
	1.234 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2339
	1e10 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2340
	1.2e3 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2341
	1.2e30 printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2342
	(1.0 uncheckedDivide:0) printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2343
	(0.0 uncheckedDivide:0) printString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2344
	self pi printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2345
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2346
	DecimalPointCharacter := $,.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2347
	1.234 printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2348
	1.0 printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2349
	1e10 printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2350
	1.2e3 printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2351
	1.2e30 printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2352
	(1.0 uncheckedDivide:0) printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2353
	(0.0 uncheckedDivide:0) printString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2354
	DecimalPointCharacter := $.
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2355
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2356
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2357
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2358
printfPrintString:formatString
24690
04c1c662e931 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24616
diff changeset
  2359
    <unsave>
04c1c662e931 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24616
diff changeset
  2360
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7724
diff changeset
  2361
    "non-standard: return a printed representation of the receiver
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2362
     as specified by formatString, which is defined by printf.
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
  2363
31
75f2b9f78be2 *** empty log message ***
claus
parents: 16
diff changeset
  2364
     If you use this, be aware, that specifying doubles differs on
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2365
     systems; on SYSV machines you have to give something like %lf,
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  2366
     while on BSD systems the format string has to be %F.
31
75f2b9f78be2 *** empty log message ***
claus
parents: 16
diff changeset
  2367
     Also, the resulting string may not be longer than 255 bytes -
20415
b4da57dd7252 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20059
diff changeset
  2368
     since that's the (static) size of the buffer.
21909
1d46683f40fc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21904
diff changeset
  2369
11926
295e8bb99fde changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11733
diff changeset
  2370
     This method is NONSTANDARD and may be removed without notice.
24690
04c1c662e931 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24616
diff changeset
  2371
04c1c662e931 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24616
diff changeset
  2372
     WARNING: this goes directly to the C-printf function and may therefore me inherently unsafe.
11926
295e8bb99fde changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11733
diff changeset
  2373
     Please use the printf: method, which is safe as it is completely implemented in Smalltalk."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2374
24690
04c1c662e931 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24616
diff changeset
  2375
%{  /* STACK: 8000 */
04c1c662e931 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24616
diff changeset
  2376
#ifndef __SCHTEAM__
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2377
    char buffer[256];
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2378
    OBJ s;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  2379
    int len;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2380
12478
e8051030cda6 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12423
diff changeset
  2381
    if (__isStringLike(formatString)) {
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2382
	/*
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2383
	 * actually only needed on sparc: since thisContext is
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2384
	 * in a global register, which gets destroyed by printf,
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2385
	 * manually save it here - very stupid ...
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2386
	 */
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2387
	__BEGIN_PROTECT_REGISTERS__
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2388
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2389
	len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __floatVal(self));
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2390
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2391
	__END_PROTECT_REGISTERS__
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2392
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2393
	if (len < 0) goto fail;
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2394
	if (len >= sizeof(buffer)) goto fail;
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2395
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2396
	s = __MKSTRING_L(buffer, len);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2397
	if (s != nil) {
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2398
	    RETURN (s);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2399
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2400
    }
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  2401
fail: ;
24690
04c1c662e931 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24616
diff changeset
  2402
#endif /* not __SCHTEAM__ */
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  2403
%}.
21909
1d46683f40fc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21904
diff changeset
  2404
    ^ super printfPrintString:formatString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2405
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2406
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2407
     Float pi printfPrintString:'%%lg -> %lg'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2408
     Float pi printfPrintString:'%%lf -> %lf'
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  2409
     Float pi printfPrintString:'%%7.15lg -> %7.15lg'
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2410
     Float pi printfPrintString:'%%7.5lf -> %7.5lf'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2411
     Float pi printfPrintString:'%%G -> %G'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2412
     Float pi printfPrintString:'%%F -> %F'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2413
     Float pi printfPrintString:'%%7.5G -> %7.5G'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2414
     Float pi printfPrintString:'%%7.5F -> %7.5F'
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
  2415
21952
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2416
     Float pi printfPrintString:'%%7.5f -> %7.5f'
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2417
     Float pi printfPrintString:'%%100.98f -> %100.98f'
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2418
     Float pi printfPrintString:'%%100.6f -> %100.6f'
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2419
     Float pi printfPrintString:'%%300.6f -> %300.6f'
22578
c31e7ac76ff5 os defs; osx fix
Claus Gittinger <cg@exept.de>
parents: 22560
diff changeset
  2420
21952
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2421
     Float pi printfPrintString:'%%-100.98f -> %-100.98f'
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2422
     Float pi printfPrintString:'%%300.298f -> %300.298f'
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2423
     Float pi printfPrintString:'%%-300.298f -> %-300.298f'
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2424
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2425
     Float pi printfPrintString:'%%100.6f -> <%100.6f>'
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2426
     Float pi printfPrintString:'%%300.6f -> <%300.6f>'
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2427
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2428
     Float pi printfPrintString:'%%100.6f -> <%100.6>'
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2429
     Float pi printfPrintString:'%%300.6f -> <%300.6>'
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2430
    "
21909
1d46683f40fc #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21904
diff changeset
  2431
21952
63418263e52b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21936
diff changeset
  2432
    "Modified (comment): / 03-07-2017 / 15:11:13 / cg"
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2433
!
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2434
22301
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2435
storeOn:aStream
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2436
    "append a printed representation of the receiver to
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2437
     the argument, aStream.
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2438
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2439
     I use #storeString instead of #storeOn: as basic store mechanism."
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2440
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2441
    aStream nextPutAll:self storeString
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2442
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2443
    "Created: / 10-10-2017 / 14:06:39 / cg"
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2444
!
d897877094e8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22260
diff changeset
  2445
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2446
storeString
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2447
    "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
  2448
     all valid digits are printed.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2449
     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
  2450
     #storeOn: as basic print mechanism."
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2451
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2452
%{  /* NOCONTEXT */
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2453
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2454
    char buffer[64];
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2455
    REGISTER char *cp;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2456
    OBJ s;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2457
    int len;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2458
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2459
    __BEGIN_PROTECT_REGISTERS__
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2460
#ifdef SYSV
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2461
    len = snprintf(buffer, sizeof(buffer), "%.17lg", __floatVal(self));
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2462
#else
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2463
    len = snprintf(buffer, sizeof(buffer), "%.17G", __floatVal(self));
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2464
#endif
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2465
    __END_PROTECT_REGISTERS__
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2466
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2467
    if (len >= 0 && len < sizeof(buffer)-3) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2468
	/*
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2469
	 * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2470
	 * (i.e. look if string contains '.' or 'e' and append '.0' if not)
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2471
	 */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2472
	for (cp = buffer; *cp; cp++) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2473
	    if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2474
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2475
	if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2476
	    *cp++ = '.';
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2477
	    *cp++ = '0';
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2478
	    *cp = '\0';
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2479
	}
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2480
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2481
	s = __MKSTRING(buffer);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2482
	if (s != nil) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2483
	    RETURN (s);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2484
	}
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2485
    }
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2486
%}.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2487
    "
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2488
     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
  2489
     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
  2490
     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
  2491
     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
  2492
     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
  2493
    "
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20415
diff changeset
  2494
    ^ AllocationFailure raise.
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2495
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2496
    "
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2497
	1.0 storeString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2498
	0.1 storeString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2499
	((Array new:10 withAll:0.1) inject:0 into:[:v :sumSoFar| sumSoFar + v]) storeString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2500
	1.234 storeString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2501
	1e10 storeString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2502
	1.2e3 storeString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2503
	1.2e30 storeString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2504
	Float pi storeString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2505
	(1.0 uncheckedDivide:0) storeString
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2506
	(0.0 uncheckedDivide:0) storeString
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2507
9124
1bc6bb791bdc decimalPoint control
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  2508
     notice that the storeString is NOT affected by DecimalPointCharacterForPrinting:
1bc6bb791bdc decimalPoint control
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  2509
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2510
	DecimalPointCharacterForPrinting := $,.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2511
	1.234 storeString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2512
	1.0 storeString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2513
	1e10 storeString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2514
	1.2e3 storeString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2515
	1.2e30 storeString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2516
	(1.0 uncheckedDivide:0) storeString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2517
	(0.0 uncheckedDivide:0) storeString.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2518
	DecimalPointCharacterForPrinting := $.
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  2519
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2520
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2521
11926
295e8bb99fde changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11733
diff changeset
  2522
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7217
diff changeset
  2523
!Float methodsFor:'private-accessing'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2524
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2525
basicAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2526
    "return an internal byte of the float.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2527
     The value returned here depends on byte order, float representation etc.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2528
     Therefore, this method should be used strictly private.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2529
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2530
     Notice:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2531
	the need to redefine this method here is due to the
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2532
	inability of many machines to store floats in non-double aligned memory.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2533
	Therefore, on some machines, the first 4 bytes of a float are left unused,
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2534
	and the actual float is stored at index 5 .. 12.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2535
	To hide this at one place, this method knows about that, and returns
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2536
	values as if this filler wasnt present."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2537
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2538
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2539
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2540
    register int indx;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2541
    unsigned char *cp;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2542
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2543
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2544
     * notice the missing test for self being a nonNilObject -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2545
     * this can be done since basicAt: is defined both in UndefinedObject
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2546
     * and SmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2547
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2548
    if (__isSmallInteger(index)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2549
	indx = __intVal(index) - 1;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2550
	if (((unsigned)(indx)) < sizeof(double)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2551
	    cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2552
	    RETURN ( __mkSmallInteger(cp[indx] & 0xFF) );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2553
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2554
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2555
%}.
7217
554bb9c2ba24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2556
    ^ self indexNotIntegerOrOutOfBounds:index
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2557
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2558
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2559
basicAt:index put:value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2560
    "set an internal byte of the float.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2561
     The value to be stored here depends on byte order, float representation etc.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2562
     Therefore, this method should be used strictly private.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2563
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2564
     Notice:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2565
	the need to redefine this method here is due to the
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2566
	inability of many machines to store floats in non-double aligned memory.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2567
	Therefore, on some machines, the first 4 bytes of a float are left unused,
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2568
	and the actual float is stored at index 5 .. 12.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2569
	To hide this at one place, this method knows about that, and returns
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2570
	values as if this filler wasnt present."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2571
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2572
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2573
    register int indx, val;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2574
    unsigned char *cp;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2575
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2576
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2577
     * notice the missing test for self being a nonNilObject -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2578
     * this can be done since basicAt: is defined both in UndefinedObject
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2579
     * and SmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2580
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2581
    if (__bothSmallInteger(index, value)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2582
	val = __intVal(value);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2583
	if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2584
	    indx = __intVal(index) - 1;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2585
	    if (((unsigned)(indx)) < sizeof(double)) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2586
		cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2587
		cp[indx] = val;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2588
		RETURN ( value );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2589
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2590
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2591
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2592
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2593
    value isInteger ifFalse:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2594
	"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2595
	 the object to store should be an integer number
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2596
	"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2597
	^ self elementNotInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2598
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2599
    (value between:0 and:255) ifFalse:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2600
	"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2601
	 the object to store must be a bytes value
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2602
	"
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2603
	^ self elementBoundsError:value
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2604
    ].
7217
554bb9c2ba24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  2605
    ^ self indexNotIntegerOrOutOfBounds:index
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2606
!
4592
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  2607
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  2608
basicSize
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  2609
    "return the size in bytes of the float.
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  2610
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2611
     Notice:
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2612
	the need to redefine this method here is due to the
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2613
	inability of many machines to store floats in non-double aligned memory.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2614
	Therefore, on some machines, the first 4 bytes of a float are left unused,
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2615
	and the actual float is stored at index 5 .. 12.
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2616
	To hide this at one place, this method knows about that, and returns
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2617
	values as if this filler wasn't present."
4592
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  2618
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  2619
%{  /* NOCONTEXT */
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  2620
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2621
    RETURN (__mkSmallInteger(sizeof(double)));
4592
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  2622
%}.
22260
067e256d2340 #BUGFIX by sr
sr
parents: 22200
diff changeset
  2623
!
067e256d2340 #BUGFIX by sr
sr
parents: 22200
diff changeset
  2624
067e256d2340 #BUGFIX by sr
sr
parents: 22200
diff changeset
  2625
byteAt:index
067e256d2340 #BUGFIX by sr
sr
parents: 22200
diff changeset
  2626
    ^ self basicAt:index
067e256d2340 #BUGFIX by sr
sr
parents: 22200
diff changeset
  2627
!
067e256d2340 #BUGFIX by sr
sr
parents: 22200
diff changeset
  2628
067e256d2340 #BUGFIX by sr
sr
parents: 22200
diff changeset
  2629
byteAt:index put:newByte
067e256d2340 #BUGFIX by sr
sr
parents: 22200
diff changeset
  2630
    self shouldNotImplement
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2631
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2632
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2633
!Float methodsFor:'queries'!
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2634
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2635
nextFloat:count
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2636
    "answer the next float count places after (or before if count is negative) myself"
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2637
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2638
%{
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2639
    union {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2640
	double d;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2641
	INT64 i;
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2642
    } this;
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2643
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2644
    if (__isSmallInteger(count)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2645
	this.d = __floatVal(self);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2646
	if (isfinite(this.d))
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2647
	    this.i += __intVal(count);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2648
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2649
	RETURN(__MKFLOAT(this.d));
16658
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2650
    }
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2651
%}.
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2652
    self primitiveFailed:#badArgument
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2653
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2654
  "
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2655
     (1.0 nextFloat:1) storeString
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2656
     (67329.234 nextFloat:1) storeString
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2657
     (67329.234 asShortFloat nextFloat:1) storeString
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2658
     Float NaN nextFloat:100000
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2659
     Float infinity nextFloat:100000
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2660
  "
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2661
! !
1c653a0a7e4d class: Float
Stefan Vogel <sv@exept.de>
parents: 16632
diff changeset
  2662
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2663
!Float methodsFor:'special access'!
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2664
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2665
exponent
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2666
    "extract a normalized float's (unbiased) exponent.
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2667
     The returned value depends on the float-representation of
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2668
     the underlying machine and is therefore highly unportable.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2669
     This is not for general use.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2670
     This assumes that the mantissa is normalized to
12423
a3c777accbb0 changed: #exponent
Claus Gittinger <cg@exept.de>
parents: 11945
diff changeset
  2671
     0.5 .. 1.0 and the float's value is: mantissa * 2^exp"
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2672
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2673
%{  /* NOCONTEXT */
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2674
    double myVal;
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2675
    double frac;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2676
    int exp;
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2677
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2678
    myVal = __floatVal(self);
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2679
    // ouch: math libs seem to not care for NaN here;
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2680
#if 1
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2681
    // should we?
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2682
    if (! (isnan(myVal) || isinf(myVal)))
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2683
#endif
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2684
    {
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2685
	frac = frexp(myVal, &exp);
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2686
	RETURN (__mkSmallInteger(exp));
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2687
    }
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2688
%}.
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2689
    ^ super exponent
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2690
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2691
    "
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2692
     1.0 exponent
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2693
     2.0 exponent
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  2694
     3.0 exponent
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2695
     3.0 mantissa
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2696
     3.0 mantissa * (2 raisedTo:3.0 exponent)
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2697
     4.0 exponent
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  2698
     0.5 exponent
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  2699
     0.4 exponent
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  2700
     0.25 exponent
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  2701
     0.2 exponent
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2702
     0.00000011111 exponent
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2703
     0.0 exponent
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2704
     1e1000 exponent
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2705
    "
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2706
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2707
    "Modified: / 20-06-2017 / 11:34:43 / cg"
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2708
!
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2709
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2710
mantissa
24152
16af84f4dd1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23943
diff changeset
  2711
    "extract a normalized float's mantissa.
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2712
     The returned value depends on the float-representation of
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2713
     the underlying machine and is therefore highly unportable.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2714
     This is not for general use.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2715
     This assumes that the mantissa is normalized to
24152
16af84f4dd1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23943
diff changeset
  2716
     0.5 .. 1.0 and the float's value is mantissa * 2^exp"
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2717
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2718
%{  /* NOCONTEXT */
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2719
    double myVal;
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2720
    double frac;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2721
    int exp;
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2722
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2723
    myVal = __floatVal(self);
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2724
    // ouch: math libs seem to not care for NaN here;
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2725
#if 1
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2726
    // should we?
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2727
    if (! (isnan(myVal) || isinf(myVal)))
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2728
#endif
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2729
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2730
	frac = frexp(myVal, &exp);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2731
	RETURN (__MKFLOAT(frac));
21868
f568817ef1d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21859
diff changeset
  2732
    }
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2733
%}.
20009
3ef6f589b6ad #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
  2734
    ^ super mantissa
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20415
diff changeset
  2735
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2736
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2737
     1.0 exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2738
     1.0 mantissa
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2739
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2740
     0.25 exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2741
     0.25 mantissa
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2742
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2743
     0.00000011111 exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2744
     0.00000011111 mantissa
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2745
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2746
     1e1000 mantissa
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2747
    "
21849
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2748
a47780970a70 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21835
diff changeset
  2749
    "Modified: / 20-06-2017 / 11:37:13 / cg"
24152
16af84f4dd1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23943
diff changeset
  2750
    "Modified (comment): / 26-05-2019 / 03:12:55 / Claus Gittinger"
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2751
! !
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2752
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2753
!Float methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2754
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2755
isFinite
24710
b4b46cdab297 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24696
diff changeset
  2756
    "return true, if the receiver is a finite float (not NaN and not +/-INF)"
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2757
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2758
%{  /* NOCONTEXT */
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2759
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2760
    /*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2761
     * notice: on machines which do not provide
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2762
     * a finite() macro or function (WIN32),
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
  2763
     * this may always ret true here ...
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2764
     */
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2765
    RETURN (isfinite(__floatVal(self)) ? true : false)
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2766
%}.
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2767
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2768
    "
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2769
     1.0 isFinite
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2770
     1 isFinite
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2771
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2772
     Float NaN isFinite
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2773
     Float infinity isFinite
24696
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2774
     Float negativeInfinity isFinite
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2775
     (0.0 uncheckedDivide: 0.0) isFinite
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2776
     (1.0 uncheckedDivide: 0.0) isFinite
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2777
    "
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2778
!
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2779
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2780
isInfinite
24710
b4b46cdab297 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24696
diff changeset
  2781
    "return true, if the receiver is an infinite float (+Inf or -Inf).
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2782
     These are not created by ST/X float operations (they raise an exception);
24710
b4b46cdab297 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24696
diff changeset
  2783
     however, inline C-code could produce them."
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2784
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2785
%{  /* NOCONTEXT */
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2786
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2787
    double dV = __floatVal(self);
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2788
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2789
    /*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2790
     * notice: on machines which do not provide
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2791
     * finite() & isnan() macros or functions (WIN32),
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
  2792
     * this may always ret false here ...
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2793
     */
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
  2794
#if defined(isinf)
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2795
    if (isinf(dV)) { RETURN (true); }
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2796
#else
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
  2797
    if (!isfinite(dV) && !isnan(dV)) { RETURN (true); }
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2798
#endif
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2799
%}.
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2800
    ^ false
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2801
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2802
    "
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2803
	1.0 isInfinite
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2804
	(0.0 uncheckedDivide: 0.0) isInfinite
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2805
	(1.0 uncheckedDivide: 0.0) isInfinite
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2806
	(-1.0 uncheckedDivide: 0.0) isInfinite
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2807
    "
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2808
!
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2809
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2810
isLiteral
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2811
    "return true, if the receiver can be used as a literal constant in ST syntax
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2812
     (i.e. can be used in constant arrays)"
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2813
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2814
    ^ true
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2815
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2816
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2817
!
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2818
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2819
isNaN
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2820
    "return true, if the receiver is an invalid float (NaN - not a number).
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2821
     These are not created by ST/X float operations (they raise an exception);
24710
b4b46cdab297 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24696
diff changeset
  2822
     however, inline C-code could produce them."
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2823
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2824
%{  /* NOCONTEXT */
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2825
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2826
    RETURN (isnan(__floatVal(self)) ? true : false)
2392
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  2827
%}.
3139
ca
parents: 3129
diff changeset
  2828
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2829
    "
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2830
	self NaN isNaN
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2831
	1.0 isNaN
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2832
	(0.0 uncheckedDivide: 0.0) isNaN
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2833
	(1.0 uncheckedDivide: 0.0) isNaN
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2834
	(-1.0 uncheckedDivide: 0.0) isNaN
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2835
    "
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2836
!
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2837
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2838
isNegativeZero
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2839
    "many systems have two float.Pnt zeros"
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2840
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2841
%{  /* NOCONTEXT */
17389
2b91cd882904 class: Float
Stefan Vogel <sv@exept.de>
parents: 17384
diff changeset
  2842
17392
76970f24faee class: Float
Stefan Vogel <sv@exept.de>
parents: 17389
diff changeset
  2843
#if defined(__BORLANDC__)
76970f24faee class: Float
Stefan Vogel <sv@exept.de>
parents: 17389
diff changeset
  2844
    union { double d; int i[2]; } __u;
76970f24faee class: Float
Stefan Vogel <sv@exept.de>
parents: 17389
diff changeset
  2845
   __u.d = __floatVal(self);
76970f24faee class: Float
Stefan Vogel <sv@exept.de>
parents: 17389
diff changeset
  2846
    RETURN ( (__u.d == 0.0 && __u.i[1] < 0) ? true : false );
17389
2b91cd882904 class: Float
Stefan Vogel <sv@exept.de>
parents: 17384
diff changeset
  2847
#else
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2848
    RETURN ( (__floatVal(self) == 0.0 && signbit(__floatVal(self)) != 0) ? true : false );
17389
2b91cd882904 class: Float
Stefan Vogel <sv@exept.de>
parents: 17384
diff changeset
  2849
#endif
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2850
%}.
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2851
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2852
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2853
     0.0 isNegativeZero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2854
     -0.0 isNegativeZero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2855
     -1.0 isNegativeZero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2856
     1.0 isNegativeZero
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2857
    "
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2858
!
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2859
24328
e16d587ddbd6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24326
diff changeset
  2860
isZero
e16d587ddbd6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24326
diff changeset
  2861
    "return true, if the receiver is zero"
e16d587ddbd6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24326
diff changeset
  2862
e16d587ddbd6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24326
diff changeset
  2863
    ^ self = 0.0
e16d587ddbd6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24326
diff changeset
  2864
e16d587ddbd6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24326
diff changeset
  2865
    "Created: / 10-06-2019 / 21:58:24 / Claus Gittinger"
e16d587ddbd6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24326
diff changeset
  2866
!
e16d587ddbd6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24326
diff changeset
  2867
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2868
negative
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2869
    "return true if the receiver is less than zero.
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2870
     -0.0 is positive for now."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2871
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2872
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2873
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2874
    RETURN ( __floatVal(self) < 0.0  ? true : false );
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2875
    // RETURN ( signbit(__floatVal(self)) != 0  ? true : false );
5411
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
  2876
%}.
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2877
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2878
    "
24696
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2879
     0.0 negative
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2880
     -0.0 negative
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2881
     1.0 negative
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2882
     -1.0 negative
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2883
     (1.0 uncheckedDivide: 0.0) negative
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2884
     (-1.0 uncheckedDivide: 0.0) negative
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2885
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2886
     Float infinity negative
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2887
     Float negativeInfinity negative
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2888
     Float NaN negative
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2889
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2890
     Float infinity positive
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2891
     Float negativeInfinity positive
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2892
     Float NaN positive
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2893
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2894
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2895
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2896
numberOfBits
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2897
    "return the size (in bits) of the real;
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2898
     typically, 64 is returned here,
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2899
     but who knows ..."
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2900
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2901
%{  /* NOCONTEXT */
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2902
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2903
    RETURN (__mkSmallInteger (sizeof(double) * 8));
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2904
%}
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2905
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2906
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2907
     1.2 numberOfBits
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2908
     1.2 asShortFloat numberOfBits
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2909
    "
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2910
!
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2911
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2912
positive
18857
7165f748d240 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18838
diff changeset
  2913
    "return true if the receiver is greater or equal to zero (not negative).
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2914
     0.0 and -0.0 are positive for now."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2915
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2916
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2917
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2918
    RETURN ( __floatVal(self) >= 0.0 ? true : false );
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2919
    // RETURN ( signbit(__floatVal(self)) == 0 ? true : false  );
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2920
%}.
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2921
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2922
    "
24696
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2923
     0.0 positive
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2924
     -0.0 positive
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2925
     1.0 positive
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2926
     -1.0 positive
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2927
     (1.0 uncheckedDivide: 0.0) positive
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2928
     (-1.0 uncheckedDivide: 0.0) positive
311a7cfb48b0 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24690
diff changeset
  2929
25002
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2930
     Float infinity positive
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2931
     Float negativeInfinity positive
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2932
     Float NaN positive
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2933
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2934
     Float infinity negative
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2935
     Float negativeInfinity negative
34d9021dd872 fmin/fmax missing
Claus Gittinger <cg@exept.de>
parents: 24981
diff changeset
  2936
     Float NaN negative
17384
36f55cb89897 class: Float
Stefan Vogel <sv@exept.de>
parents: 17226
diff changeset
  2937
    "
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2938
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2939
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2940
strictlyPositive
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2941
    "return true if the receiver is greater than zero"
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2942
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2943
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2944
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2945
    RETURN ( (__floatVal(self) > 0.0) ? true : false );
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2946
%}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2947
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2948
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2949
!Float methodsFor:'tracing'!
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2950
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4655
diff changeset
  2951
traceInto:aRequestor level:level from:referrer
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2952
    "double dispatch into tracer, passing my type implicitely in the selector"
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2953
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4655
diff changeset
  2954
    ^ aRequestor traceFloat:self level:level from:referrer
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2955
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2956
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2957
! !
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2958
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2959
!Float methodsFor:'trigonometric'!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2960
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2961
arcCos
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2962
    "return the arccosine of the receiver (as radians).
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2963
     Raises an exception, if the receiver is not in -1..1"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2964
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2965
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2966
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  2967
    return context._RETURN( self.acos() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2968
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2969
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2970
    double val, rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2971
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2972
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2973
    val = __floatVal(self);
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2974
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
  2975
# ifdef __win32__ /* to suppress the warnBox opened by win32 */
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2976
    if ((val >= -1.0) && (val <= 1.0))
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2977
# endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2978
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2979
	__threadErrno = 0;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2980
	rslt = acos(val);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2981
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2982
	{
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2983
	    if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2984
		__qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2985
		RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2986
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2987
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2988
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  2989
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2990
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2991
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2992
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2993
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2994
	selector:#arcCos
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2995
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  2996
	errorString:'bad receiver in arcCos'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2997
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2998
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2999
     -10 arcCos
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3000
     1 arcCos
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3001
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3002
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3003
    "Modified: / 16.11.2001 / 14:14:13 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3004
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3005
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3006
arcCosh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3007
    "return the hyperbolic arccosine of the receiver."
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3008
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3009
    |useFallBack|
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3010
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3011
%{
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3012
#ifdef NO_ACOSH
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3013
    useFallBack = true;
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3014
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3015
    double val, rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3016
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3017
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3018
    val = __floatVal(self);
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3019
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
  3020
# ifdef __win32__ /* to suppress the warnBox opened by win32 */
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3021
    if (val >= 1.0)
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3022
# endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3023
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3024
	__threadErrno = 0;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3025
	rslt = acosh(val);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3026
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3027
	{
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3028
	    if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3029
		__qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3030
		RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3031
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3032
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3033
    }
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3034
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3035
%}.
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3036
    useFallBack notNil ifTrue:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3037
	^ super arcCosh
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3038
    ].
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3039
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3040
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3041
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3042
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3043
	selector:#arcCosh
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3044
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3045
	errorString:'bad receiver in arcCosh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3046
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3047
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3048
     -10.0 arcCosh
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3049
     1.0 arcCosh
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3050
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3051
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3052
    "Modified: / 16.11.2001 / 14:14:13 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3053
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3054
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3055
arcSin
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3056
    "return the arcsine of myself (I am interpreted as radians).
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3057
     Raises an exception, if the receiver is not in -1..1"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3058
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3059
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3060
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  3061
    return context._RETURN( self.asin() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3062
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3063
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3064
    double val, rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3065
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3066
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3067
    val = __floatVal(self);
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3068
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
  3069
# ifdef __win32__ /* to suppress the warnBox opened by win32 */
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3070
    if ((val >= -1.0) && (val <= 1.0))
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3071
# endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3072
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3073
	__threadErrno = 0;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3074
	rslt = asin(val);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3075
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3076
	{
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3077
	    if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3078
		__qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3079
		RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3080
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3081
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3082
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3083
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3084
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3085
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3086
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3087
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3088
	selector:#arcSin
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3089
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3090
	errorString:'bad receiver in arcSin'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3091
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3092
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3093
     -10 arcSin
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3094
     1 arcSin
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3095
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3096
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3097
    "Modified: / 16.11.2001 / 14:14:18 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3098
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3099
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3100
arcSinh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3101
    "return the hyperbolic arcsine of the receiver."
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3102
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3103
    |useFallBack|
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3104
%{
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3105
#ifdef NO_ASINH
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3106
    useFallBack = true;
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3107
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3108
    double val, rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3109
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3110
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3111
    val = __floatVal(self);
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3112
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
  3113
# ifdef __win32__ /* to suppress the warnBox opened by win32 */
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3114
    if (val >= 1.0)
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3115
# endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3116
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3117
	__threadErrno = 0;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3118
	rslt = asinh(val);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3119
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3120
	{
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3121
	    if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3122
		__qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3123
		RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3124
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3125
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3126
    }
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3127
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3128
%}.
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3129
    useFallBack notNil ifTrue:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3130
	^ super arcSinh
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3131
    ].
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3132
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3133
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3134
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3135
	selector:#arcSinh
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3136
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3137
	errorString:'bad receiver in arcSinh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3138
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3139
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3140
     -10.0 arcSinh
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3141
     1.0 arcSinh
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3142
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3143
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3144
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3145
arcTan
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3146
    "return the arctangent of the receiver (as radians)"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3147
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3148
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3149
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  3150
    return context._RETURN( self.atan() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3151
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3152
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3153
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3154
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3155
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3156
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3157
    rslt = atan(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3158
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3159
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3160
	if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3161
	    __qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3162
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3163
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3164
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3165
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3166
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3167
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3168
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3169
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3170
	selector:#arcTan
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3171
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3172
	errorString:'bad receiver in arcTan'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3173
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3174
    "Modified: / 16.11.2001 / 14:14:22 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3175
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3176
11487
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3177
arcTan2:x
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3178
    "return the atan2(self,x)"
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3179
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3180
%{  /* NOCONTEXT */
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3181
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3182
    double rslt;
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3183
    OBJ newFloat;
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3184
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3185
    if (__isFloat(x)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3186
	__threadErrno = 0;
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3187
	rslt = atan2(__floatVal(self),__floatVal(x));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3188
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3189
	{
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3190
	    if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3191
		__qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3192
		RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3193
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3194
	}
11487
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3195
    }
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3196
%}.
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3197
    x isFloat ifFalse:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3198
	^ self arcTan2:(x asFloat).
11487
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3199
    ].
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3200
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3201
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3202
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3203
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3204
	selector:#arcTan2:
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3205
	arguments:(Array with:x)
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3206
	errorString:'bad receiver in arcTan2:'
11487
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3207
!
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  3208
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  3209
arcTan: denominator
22728
971b3721fa66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22725
diff changeset
  3210
    "Evaluate the four quadrant arc tangent of the argument denominator (x) and the receiver (y)."
971b3721fa66 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22725
diff changeset
  3211
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3212
    (self = 0.0) ifTrue: [
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3213
	(denominator > 0.0)
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3214
	    ifTrue: [ ^ 0 ]
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3215
	    ifFalse: [ ^ Pi ]
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  3216
    ].
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3217
    (denominator = 0.0) ifTrue: [
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3218
	(self > 0.0)
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3219
	    ifTrue: [ ^ Halfpi ]
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3220
	    ifFalse: [ ^ HalfpiNegative ]
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  3221
    ].
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3222
    (denominator > 0)
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3223
	ifTrue: [ ^ (self / denominator) arcTan ]
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3224
	ifFalse: [ ^ ((self / denominator) arcTan) + Pi ]
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  3225
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  3226
    "Created: / 07-06-2007 / 21:10:32 / cg"
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  3227
    "Modified: / 11-06-2007 / 12:58:34 / cg"
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  3228
!
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  3229
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3230
arcTanh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3231
    "return the hyperbolic arctangent of the receiver."
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3232
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3233
    |useFallBack|
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3234
%{
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3235
#ifdef NO_ATANH
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3236
    useFallBack = true;
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3237
#else
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3238
    double val, rslt;
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3239
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3240
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3241
    __threadErrno = 0;
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3242
    val = __floatVal(self);
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
  3243
# ifdef __win32__ /* to suppress the warnBox opened by win32 */
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3244
    if ((val >= -1.0) && (val <= 1.0))
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3245
# endif
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3246
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3247
	rslt = atanh(val);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3248
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
  3249
# ifdef __osx__
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3250
	if (! isinf(rslt))
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19616
diff changeset
  3251
# endif
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3252
	{
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3253
	    if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3254
		__qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3255
		RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3256
	    }
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3257
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3258
    }
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3259
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3260
%}.
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3261
    useFallBack notNil ifTrue:[
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3262
	^ super arcTanh
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  3263
    ].
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3264
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3265
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3266
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3267
	selector:#arcTanh
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3268
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3269
	errorString:'bad receiver in arcTanh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3270
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3271
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3272
cos
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3273
    "return the cosine of the receiver (interpreted as radians)"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3274
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3275
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3276
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  3277
    return context._RETURN( self.cos() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3278
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3279
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3280
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3281
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3282
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3283
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3284
    rslt = cos(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3285
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3286
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3287
	if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3288
	    __qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3289
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3290
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3291
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3292
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3293
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3294
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3295
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3296
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3297
	selector:#cos
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3298
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3299
	errorString:'bad receiver in cos'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3300
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3301
    "Modified: / 16.11.2001 / 14:14:26 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3302
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3303
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3304
cosh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3305
    "return the hyperbolic cosine of the receiver"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3306
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3307
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3308
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  3309
    return context._RETURN( self.cosh() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3310
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3311
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3312
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3313
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3314
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3315
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3316
    rslt = cosh(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3317
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3318
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3319
	if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3320
	    __qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3321
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3322
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3323
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3324
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3325
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3326
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3327
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3328
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3329
	selector:#cosh
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3330
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3331
	errorString:'bad receiver in cosh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3332
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3333
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3334
sin
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3335
    "return the sine of the receiver (interpreted as radians)"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3336
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3337
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3338
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  3339
    return context._RETURN( self.sin() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3340
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3341
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3342
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3343
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3344
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3345
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3346
    rslt = sin(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3347
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3348
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3349
	if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3350
	    __qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3351
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3352
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3353
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3354
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3355
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3356
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3357
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3358
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3359
	selector:#sin
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3360
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3361
	errorString:'bad receiver in sin'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3362
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3363
    "Modified: / 16.11.2001 / 14:14:37 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3364
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3365
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3366
sinh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3367
    "return the hyperbolic sine of the receiver"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3368
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3369
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3370
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  3371
    return context._RETURN( self.sinh() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3372
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3373
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3374
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3375
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3376
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3377
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3378
    rslt = sinh(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3379
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3380
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3381
	if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3382
	    __qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3383
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3384
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3385
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3386
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3387
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3388
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3389
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3390
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3391
	selector:#sinh
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3392
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3393
	errorString:'bad receiver in sinh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3394
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3395
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3396
tan
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3397
    "return the tangens of the receiver (interpreted as radians)"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3398
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3399
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3400
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  3401
    return context._RETURN( self.tan() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3402
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3403
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3404
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3405
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3406
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3407
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3408
    rslt = tan(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3409
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3410
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3411
	if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3412
	    __qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3413
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3414
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3415
    }
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3416
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3417
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3418
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3419
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3420
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3421
	selector:#tan
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3422
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3423
	errorString:'bad receiver in tan'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3424
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3425
    "Modified: / 16.11.2001 / 14:14:49 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3426
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3427
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3428
tanh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  3429
    "return the hyperbolic tangens of the receiver"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3430
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3431
%{  /* NOCONTEXT */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3432
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3433
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3434
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3435
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3436
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3437
    rslt = tanh(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3438
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  3439
    {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3440
	if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3441
	    __qMKFLOAT(newFloat, rslt);
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3442
	    RETURN ( newFloat );
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3443
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3444
    }
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3445
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3446
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3447
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3448
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3449
	selector:#tanh
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3450
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3451
	errorString:'bad receiver in tanh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3452
! !
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  3453
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5436
diff changeset
  3454
!Float methodsFor:'truncation & rounding'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3455
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3456
ceiling
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3457
    "return the smallest integer which is greater or equal to the receiver."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3458
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3459
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3460
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3461
%{
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3462
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3463
    ERROR("unimplemented");
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3464
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3465
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3466
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3467
    dVal = ceil(__floatVal(self));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3468
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3469
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3470
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3471
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3472
	RETURN ( __mkSmallInteger( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3473
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3474
    __qMKFLOAT(val, dVal);
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3475
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3476
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3477
    ^ val asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3478
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3479
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3480
ceilingAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3481
    "return the smallest integer-valued float greater or equal to the receiver.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3482
     This is much like #ceiling, but avoids a (possibly expensive) conversion
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3483
     of the result to an integer.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3484
     It may be useful, if the result is to be further used in another float-operation."
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3485
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3486
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3487
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  3488
    return context._RETURN( self.ceiling() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3489
#else
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3490
    double dVal;
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3491
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3492
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3493
    dVal = ceil(__floatVal(self));
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3494
    __qMKFLOAT(v, dVal);
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3495
    RETURN (v);
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3496
#endif
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3497
%}
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3498
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3499
     0.5 ceilingAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3500
     -0.5 ceilingAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3501
     -1.5 ceilingAsFloat
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3502
    "
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3503
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3504
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3505
floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3506
    "return the integer nearest the receiver towards negative infinity."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3507
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3508
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3509
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3510
%{
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3511
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3512
    ERROR("unimplemented");
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3513
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3514
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3515
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3516
    dVal = floor(__floatVal(self));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3517
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3518
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3519
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3520
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3521
	RETURN ( __mkSmallInteger( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3522
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3523
    __qMKFLOAT(val, dVal);
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3524
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3525
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3526
    ^ val asInteger
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3527
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3528
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3529
     0.5 floor
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3530
     0.5 floorAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3531
     -0.5 floor
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3532
     -0.5 floorAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3533
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3534
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3535
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3536
floorAsFloat
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3537
    "return the integer nearest the receiver towards negative infinity as a float.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3538
     This is much like #floor, but avoids a (possibly expensive) conversion
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3539
     of the result to an integer.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3540
     It may be useful, if the result is to be further used in another float-operation."
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3541
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3542
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3543
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  3544
    return context._RETURN( self.floor() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3545
#else
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3546
    double dVal;
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3547
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3548
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3549
    dVal = floor(__floatVal(self));
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3550
    __qMKFLOAT(v, dVal);
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3551
    RETURN (v);
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3552
#endif
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3553
%}
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3554
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3555
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3556
     0.5 floor
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3557
     0.5 floorAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3558
     -0.5 floor
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3559
     -0.5 floorAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3560
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3561
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3562
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3563
fractionPart
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3564
    "extract the after-decimal fraction part.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3565
     such that (self truncated + self fractionPart) = self"
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3566
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3567
%{  /* NOCONTEXT */
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3568
14728
b947522816a7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 14720
diff changeset
  3569
    double modf(double, double*);
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3570
    double frac, trunc;
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3571
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  3572
    __threadErrno = 0;
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3573
    frac = modf(__floatVal(self), &trunc);
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3574
    if (! isnan(frac)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3575
	if (__threadErrno == 0) {
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3576
	    RETURN (__MKFLOAT(frac));
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3577
	}
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3578
    }
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3579
%}.
7403
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  3580
    ^ self class
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3581
	raise:#domainErrorSignal
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3582
	receiver:self
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3583
	selector:#fractionPart
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3584
	arguments:#()
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3585
	errorString:'bad receiver in fractionPart'
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3586
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3587
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3588
     1.6 fractionPart + 1.6 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3589
     -1.6 fractionPart + -1.6 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3590
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3591
     1.0 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3592
     2.0 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3593
     3.0 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3594
     4.0 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3595
     0.5 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3596
     0.25 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3597
     3.14159 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3598
     12345673.14159 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3599
     123456731231231231.14159 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3600
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3601
     3.14159 fractionPart + 3.14159 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3602
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3603
     12345673.14159 fractionPart + 12345673.14159 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3604
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3605
     123456731231231231.14159 fractionPart + 123456731231231231.14159 truncated
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3606
    "
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3607
!
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  3608
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3609
rounded
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3610
    "return the receiver rounded to the nearest integer"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3611
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3612
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3613
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3614
%{
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3615
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3616
    ERROR("unimplemented");
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3617
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3618
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3619
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3620
    dVal = __floatVal(self);
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3621
    if (dVal < 0.0) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3622
	dVal = ceil(dVal - 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3623
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3624
	dVal = floor(dVal + 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3625
    }
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3626
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3627
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3628
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3629
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3630
	RETURN ( __mkSmallInteger( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3631
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3632
    __qMKFLOAT(val, dVal);
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3633
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3634
%}.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  3635
    ^ val asInteger
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3636
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3637
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3638
     0.4 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3639
     0.5 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3640
     0.6 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3641
     -0.4 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3642
     -0.5 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3643
     -0.6 rounded
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3644
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3645
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3646
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3647
roundedAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3648
    "return the receiver rounded to the nearest integer as a float.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3649
     This is much like #rounded, but avoids a (possibly expensive) conversion
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3650
     of the result to an integer.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3651
     It may be useful, if the result is to be further used in another
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3652
     float-operation."
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3653
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3654
    |val|
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3655
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3656
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3657
#ifdef __SCHTEAM__
18299
74723837b0ac *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18296
diff changeset
  3658
    return context._RETURN( self.round() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3659
#else
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3660
    double dVal;
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3661
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3662
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3663
    dVal = __floatVal(self);
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3664
    if (dVal < 0.0) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3665
	dVal = ceil(dVal - 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3666
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3667
	dVal = floor(dVal + 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3668
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3669
    __qMKFLOAT(v, dVal);
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3670
    RETURN (v);
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3671
#endif
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3672
%}
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3673
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3674
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3675
     0.5 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3676
     -0.5 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3677
     0.5 roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3678
     -0.5 roundedAsFloat
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3679
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3680
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3681
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3682
truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3683
    "return the receiver truncated towards zero as an integer"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3684
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3685
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3686
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3687
%{
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3688
#ifdef __SCHTEAM__
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3689
    ERROR("unimplemented");
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3690
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3691
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3692
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  3693
    dVal = __floatVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3694
    if (dVal < 0.0) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3695
	dVal = ceil(dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3696
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3697
	dVal = floor(dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3698
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3699
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3700
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3701
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3702
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3703
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3704
	RETURN ( __mkSmallInteger( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3705
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3706
    __qMKFLOAT(val, dVal);
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3707
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3708
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3709
    ^ val asInteger
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3710
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3711
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3712
     0.5 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3713
     -0.5 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3714
     0.5 truncatedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3715
     -0.5 truncatedAsFloat
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3716
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3717
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3718
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3719
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3720
truncatedAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3721
    "return the receiver truncated towards zero as a float.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3722
     This is much like #truncated, but avoids a (possibly expensive) conversion
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3723
     of the result to an integer.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3724
     It may be useful, if the result is to be further used in another
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3725
     float-operation."
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3726
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3727
%{  /* NOCONTEXT */
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3728
#ifdef __SCHTEAM__
18300
5b641d73fc8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18299
diff changeset
  3729
    return context._RETURN( self.truncated() );
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3730
#else
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3731
    double dVal;
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3732
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3733
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3734
    dVal = __floatVal(self);
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3735
    if (dVal < 0.0) {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3736
	dVal = ceil(dVal);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3737
    } else {
24969
7d932019bfce #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24958
diff changeset
  3738
	dVal = floor(dVal);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3739
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3740
    __qMKFLOAT(v, dVal);
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  3741
    RETURN (v);
18296
c8c42aeac4f5 schteam defs
Claus Gittinger <cg@exept.de>
parents: 18138
diff changeset
  3742
#endif
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3743
%}
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3744
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3745
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3746
     0.5 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3747
     -0.5 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3748
     0.5 truncatedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  3749
     -0.5 truncatedAsFloat
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3750
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3751
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3752
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3753
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3754
!Float class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3755
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3756
version
18492
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
  3757
    ^ '$Header$'
12423
a3c777accbb0 changed: #exponent
Claus Gittinger <cg@exept.de>
parents: 11945
diff changeset
  3758
!
a3c777accbb0 changed: #exponent
Claus Gittinger <cg@exept.de>
parents: 11945
diff changeset
  3759
a3c777accbb0 changed: #exponent
Claus Gittinger <cg@exept.de>
parents: 11945
diff changeset
  3760
version_CVS
18492
eca396c81443 class: Float
Claus Gittinger <cg@exept.de>
parents: 18300
diff changeset
  3761
    ^ '$Header$'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  3762
! !
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  3763
14599
3c1e4683d2f6 class: Float
Stefan Vogel <sv@exept.de>
parents: 14298
diff changeset
  3764
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  3765
Float initialize!