Float.st
author Claus Gittinger <cg@exept.de>
Tue, 29 Jan 2013 13:27:45 +0100
changeset 14728 b947522816a7
parent 14720 ca17582f4fba
child 14751 991d38458125
child 18022 f23232c2eaef
permissions -rw-r--r--
*** empty log message ***
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
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
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
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 47
diff changeset
    14
LimitedPrecisionReal variableByteSubclass:#Float
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    15
	instanceVariableNames:''
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
    16
	classVariableNames:'DefaultPrintFormat Pi E Halfpi HalfpiNegative Twopi
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
    17
		RadiansPerDegree Ln2 Ln10 Sqrt2'
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    18
	poolDictionaries:''
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    19
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    22
!Float primitiveDefinitions!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    23
%{
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    24
#include <errno.h>
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    25
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    26
#ifndef __OPTIMIZE__
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    27
# define __OPTIMIZE__
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    28
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    29
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    30
#define __USE_ISOC9X 1
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
    31
#define __USE_ISOC99 1
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    32
#include <math.h>
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    33
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    34
/*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    35
 * on some systems errno is a macro ... check for it here
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    36
 */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    37
#ifndef errno
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    38
 extern errno;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    39
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    40
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
    41
#if !defined (WIN32)
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
    42
# include <locale.h>
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
    43
#endif
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
    44
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    45
#if defined (_AIX)
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    46
# include <float.h>
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    47
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    48
2395
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    49
#if defined(IRIX)
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    50
# include <nan.h>
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    51
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    52
2397
dd6979979e67 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2396
diff changeset
    53
#if defined(LINUX)
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    54
# ifndef NAN
5822
4e56f8aadda5 Get nan.h from bits/nan.h for Linux
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
    55
#  include <bits/nan.h>
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    56
# endif
2396
646ea118eaf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2395
diff changeset
    57
#endif
4825
4c77d43433d1 nan trouble with new suse
Claus Gittinger <cg@exept.de>
parents: 4682
diff changeset
    58
2399
5d47ec6834a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
    59
#if defined(solaris) || defined(sunos)
2398
652c9f2a13fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2397
diff changeset
    60
# include <nan.h>
652c9f2a13fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2397
diff changeset
    61
#endif
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    62
3129
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    63
/*
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    64
 * sigh - some systems define that stuff; others dont.
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    65
 * (AIX even declares them as macros, so an external decl
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    66
 *  will not work below ...
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    67
 */
3240
29ebc1071762 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3198
diff changeset
    68
#if !defined(_AIX) && !defined(NEXT3)
3129
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    69
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    70
# ifdef acos
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    71
  double acos();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    72
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    73
# ifdef asin
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    74
  double asin();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    75
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    76
# ifndef atan
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    77
  double atan();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    78
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    79
# ifndef cos
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    80
  double cos();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    81
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    82
# ifndef sin
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    83
  double sin();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    84
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    85
# ifndef pow
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    86
  double pow();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    87
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    88
# ifndef log
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    89
  double log();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    90
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    91
# ifndef exp
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    92
  double exp();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    93
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    94
# ifndef sqrt
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    95
  double sqrt();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    96
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    97
# ifndef tan
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    98
  double tan();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    99
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   100
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   101
#endif /* not AIX */
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
   102
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   103
#ifdef WIN32
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   104
/*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   105
 * no finite(x) ?
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   106
 * no isnan(x) ?
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   107
 */
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   108
# ifndef isnan
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   109
#  define isnan(x)      \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   110
	((((unsigned int *)(&x))[0] == 0x00000000) && \
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   111
	 (((unsigned int *)(&x))[1] == 0xFFF80000))
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   112
# endif
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   113
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   114
# ifndef isPositiveInfinity
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   115
#  define isPositiveInfinity(x) \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   116
	((((unsigned int *)(&x))[0] == 0x00000000) && \
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   117
	 (((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
   118
# endif
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   119
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   120
# ifndef isNegativeInfinity
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   121
#  define isPositiveInfinity(x) \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   122
	((((unsigned int *)(&x))[0] == 0x00000000) && \
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   123
	 (((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
   124
# endif
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   125
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   126
# ifndef isinf
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   127
#  define isinf(x) \
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   128
	((((unsigned int *)(&x))[0] == 0x00000000) && \
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   129
	 ((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000))
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   130
# endif
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   131
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
   132
# ifndef isfinite
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
   133
#  define isfinite(x) (!isinf(x) && !isnan(x))
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   134
# endif
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
   135
7411
45c19db66503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7410
diff changeset
   136
# define NO_ASINH
45c19db66503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7410
diff changeset
   137
# define NO_ACOSH
45c19db66503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7410
diff changeset
   138
# define NO_ATANH
8984
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   139
#endif /* WIN32 */
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   140
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   141
#ifdef solaris
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   142
# ifndef isfinite
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   143
#  define isfinite(f) finite((double)(f))
ddf3bff73452 isfinite() et.al. for Solaris
Stefan Vogel <sv@exept.de>
parents: 8980
diff changeset
   144
# endif
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   145
#endif
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
   146
3414
d9aefd18c10d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3399
diff changeset
   147
#ifdef realIX
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   148
# ifndef isfinite
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
   149
#  define isfinite(x)     1
3414
d9aefd18c10d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3399
diff changeset
   150
# endif
d9aefd18c10d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3399
diff changeset
   151
#endif
d9aefd18c10d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3399
diff changeset
   152
3241
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   153
#ifndef NEXT3
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   154
# ifndef ceil
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   155
double ceil();
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   156
double floor();
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   157
# endif
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   158
#endif
259bdd31694b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3240
diff changeset
   159
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   160
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   161
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   162
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   163
!Float class methodsFor:'documentation'!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   164
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   165
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   166
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   167
 COPYRIGHT (c) 1988 by Claus Gittinger
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   168
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   169
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   170
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   171
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   172
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   173
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   174
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   175
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   176
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   177
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   178
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   179
documentation
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   180
"
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   181
    ShortFloats represent rational numbers with limited precision.
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   182
    They use the C-compilers 'double' format, which is usually the 8byte IEE double float format.
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   183
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   184
    Floats give you 64 bit floats.
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   185
    In contrast to ShortFloats and LongFloats.
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   186
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   187
    WARNING:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   188
	The layout of Float instances is known by the runtime system and the compiler;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   189
	you may not add instance variables here.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   190
	Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   191
	and does some float-checks by an identity compare with the Float-class.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   192
	(i.e. your subclasses instances may not be recognized as float-like objects,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   193
	 thus mixed mode arithmetic will always coerce them, effectively slowing things down).
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   194
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   195
    Notice, that Floats are defined as Byte-array to prevent the garbage collector
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   196
    from going into the value ... otherwise I needed a special case in many places.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   197
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   198
    Also notice, that ST/X Floats are what Doubles are in ST-80 - this may change
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   199
    in one of the next versions (at least on machines, which provide different float
6674
c383bfa3dc8c documentation comment
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
   200
    and double types in their C-compiler).
c383bfa3dc8c documentation comment
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
   201
    The reason for doung this was to be compatible to both Digitalk and ParcPlace smalltalk
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   202
    implementations
6674
c383bfa3dc8c documentation comment
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
   203
    (ParcPlace uses a 4-byte Float and an 8-byte Double class, in contrast to
c383bfa3dc8c documentation comment
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
   204
     Digitalk, which has an 8-byte Float class).
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   205
    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
   206
    (although some memory is wasted when porting from VW).
6674
c383bfa3dc8c documentation comment
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
   207
    As Digitalk is dead now, things could (should) now be made to be compatible with VW.
c383bfa3dc8c documentation comment
Claus Gittinger <cg@exept.de>
parents: 6574
diff changeset
   208
    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
   209
    instances.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   210
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1879
diff changeset
   211
    Mixed mode arithmetic:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   212
	float op float       -> float
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   213
	float op fix         -> float
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   214
	float op fraction    -> float
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   215
	float op integer     -> float
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   216
	float op shortFloat  -> float
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   217
	float op longFloat   -> longFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   218
	float op complex     -> complex
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1879
diff changeset
   219
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   220
    Representation:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   221
	    64bit double precision IEE floats
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   222
	    53 bit mantissa,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   223
	    11 bit exponent,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   224
	    15 decimal digits (approx)
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   225
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
   226
    Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation
85
claus
parents: 77
diff changeset
   227
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   228
    [author:]
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   229
	Claus Gittinger
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7373
diff changeset
   230
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   231
    [see also:]
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   232
	Number
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   233
	ShortFloat LongFloat Fraction FixedPoint Integer Complex
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   234
	FloatArray DoubleArray
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   235
"
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   236
!
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   237
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   238
errorHandling
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   239
"
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   240
    Floating point error handling and signalling depends on the systems
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   241
    (actually: the C-runtime systems) ability to handle floating point errors.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   242
    Most systems report errors by raising an OS floatingPoint exception,
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   243
    which is mapped to a fpExceptionInterrupt in ST/X.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   244
    However, some systems do return NaN as result.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   245
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   246
    Currently, ST/X does not care specially for these systems - it maybe added
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   247
    easily, if there is sufficient customer interest, though.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   248
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   249
    Try:
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   250
	|f1 f2|
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   251
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   252
	f1 := 1.0.
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   253
	f2 := 0.0.
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   254
	f1 / f2
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   255
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   256
    or:
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   257
	2 arcSin
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   258
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   259
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   260
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   261
!Float class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   262
a27a279701f8 Initial revision
claus
parents:
diff changeset
   263
basicNew
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
    "return a new float - here we return 0.0
a27a279701f8 Initial revision
claus
parents:
diff changeset
   265
     - floats are usually NOT created this way ...
a27a279701f8 Initial revision
claus
parents:
diff changeset
   266
     Its implemented here to allow things like binary store & load
a27a279701f8 Initial revision
claus
parents:
diff changeset
   267
     of floats. (but even this support will go away eventually, its not
a27a279701f8 Initial revision
claus
parents:
diff changeset
   268
     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
   269
     totally different representation - so floats will eventually be
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   270
     binary stored in a device independent format."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   271
a27a279701f8 Initial revision
claus
parents:
diff changeset
   272
%{  /* NOCONTEXT */
1206
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   273
    OBJ newFloat;
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   274
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   275
    __qMKFLOAT(newFloat, 0.0);
1206
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   276
    RETURN (newFloat);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
%}
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   278
!
1206
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   279
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   280
fastFromString:aString at:startIndex
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   281
    "return the next Float from the string starting at startIndex.
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   282
     No spaces are skipped.
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   283
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   284
     This is a specially tuned entry (using a low-level C-call), which
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   285
     returns garbage if the argument string is not a valid float number.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   286
     It has been added to allow high speed string decomposition into numbers,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   287
     especially for mass-data."
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   288
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   289
%{   /* NOCONTEXT */
12478
e8051030cda6 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12423
diff changeset
   290
     if (__isStringLike(aString) && __isSmallInteger(startIndex)) {
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   291
	char *cp = (char *)(__stringVal(aString));
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   292
	int idx = __intVal(startIndex) - 1;
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   293
	double atof();
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   294
	double val;
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   295
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   296
	if ((unsigned)idx < __stringSize(aString)) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   297
	    val = atof(cp + idx);
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   298
	    RETURN (__MKFLOAT(val));
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   299
	}
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   300
     }
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   301
%}.
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   302
     self primitiveFailed.
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   303
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   304
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   305
     Float fastFromString:'123.45' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   306
     Float fastFromString:'123.45' at:2
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   307
     Float fastFromString:'123.45E4' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   308
     Float fastFromString:'hello123.45E4' at:6
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   309
     Float fastFromString:'12345' at:1
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   310
     Float fastFromString:'12345' at:2
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   311
     Float fastFromString:'12345' at:3
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   312
     Float fastFromString:'12345' at:4
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   313
     Float fastFromString:'12345' at:5
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   314
     Float fastFromString:'12345' at:6
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   315
     Float fastFromString:'12345' at:0
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   316
     Float fastFromString:'hello123.45E4' at:1
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   317
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   318
     Time millisecondsToRun:[
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   319
	100000 timesRepeat:[
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   320
	    Float readFrom:'123.45'
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   321
	]
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   322
     ]
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   323
    "
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   324
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   325
    "
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   326
     Time millisecondsToRun:[
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   327
	100000 timesRepeat:[
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   328
	    Float fastFromString:'123.45' at:1
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   329
	]
4295
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   330
     ]
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   331
    "
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   332
!
4adf74ef8e3e added fastFromString:
Claus Gittinger <cg@exept.de>
parents: 3955
diff changeset
   333
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   334
fromVAXFloatBytes:b1 b2:b2 b3:b3 b4:b4
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   335
    "creates a double, given the four vax 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
   336
     For NaNs and Infinity, nil is returned.
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   337
    "
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   338
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   339
%{  /* NOCONTEXT */
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   340
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   341
    REGISTER union {
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
   342
	unsigned char   b[4];
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
   343
	unsigned int    l;
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
   344
	float           f;
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   345
    } r;
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   346
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8635
diff changeset
   347
#ifdef __LSBFIRST__
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   348
    r.b[3] = __intVal( b2 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   349
    r.b[2] = __intVal( b1 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   350
    r.b[1] = __intVal( b4 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   351
    r.b[0] = __intVal( b3 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   352
#else
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   353
    r.b[0] = __intVal( b2 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   354
    r.b[1] = __intVal( b1 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   355
    r.b[2] = __intVal( b4 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   356
    r.b[3] = __intVal( b3 );
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   357
#endif
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   358
    if( (r.l & 0xff800000) != 0x80000000 )
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   359
    {
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
   360
	if( (r.l & 0x7f800000) > 0x01000000 )
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
   361
	    r.l -= 0x01000000;
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
   362
	else
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
   363
	    r.l = 0;
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   364
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
   365
	RETURN( __MKFLOAT(r.f) );
3279
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   366
    }
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   367
%}.
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   368
    ^ nil
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   369
!
09d2ccf1bed2 added #fromVAXFloatBytes
ca
parents: 3244
diff changeset
   370
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   371
readFrom:aStringOrStream onError:exceptionBlock
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   372
    "read a float from a string"
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   373
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   374
    |num|
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   375
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   376
    num := super readFrom:aStringOrStream onError:nil.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   377
    num isNil ifTrue:[
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   378
	^ exceptionBlock value
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   379
    ].
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   380
    ^ num asFloat
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   381
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   382
    "
13146
1456b253fdf9 changed: #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12917
diff changeset
   383
     Float readFrom:'.1'
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   384
     Float readFrom:'0.1'
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   385
     Float readFrom:'0'
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   386
    "
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   387
13146
1456b253fdf9 changed: #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12917
diff changeset
   388
    "Created: / 07-01-1998 / 16:17:19 / cg"
1456b253fdf9 changed: #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 12917
diff changeset
   389
    "Modified: / 23-11-2010 / 14:35:41 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   390
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   391
12916
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   392
!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
   393
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   394
defaultPrintFormat
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   395
    ^ DefaultPrintFormat
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   396
!
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   397
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   398
defaultPrintFormat:something
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   399
    DefaultPrintFormat := something.
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   400
! !
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
   401
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   402
!Float class methodsFor:'binary storage'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   403
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   404
readBinaryIEEEDoubleFrom:aStream
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   405
    "read a float from the binary stream, aStream,
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   406
     interpreting the next bytes as an IEEE formatted 8-byte float"
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   407
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   408
    |f|
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   409
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   410
    f := self basicNew.
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   411
    self readBinaryIEEEDoubleFrom:aStream into:f.
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   412
    ^ f
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   413
9637
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   414
    "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
   415
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   416
    "Created: / 16-04-1996 / 20:59:59 / cg"
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   417
    "Modified: / 23-08-2006 / 16:00:42 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   418
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   419
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   420
readBinaryIEEEDoubleFrom:aStream into:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   421
    "read the receivers value from the binary stream, aStream,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   422
     interpreting the next bytes as an IEEE formatted 8-byte float"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   423
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   424
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   425
     this implementation is wrong: does not work on non-IEEE machines
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   426
     (to date all machines where ST/X is running on use
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   427
      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
   428
    "
3427
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   429
    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
   430
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   431
    UninterpretedBytes isBigEndian ifFalse:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   432
	"swap the bytes"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   433
	8 to:1 by:-1 do:[:i |
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   434
	    aFloat basicAt:i put:(aStream next)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   435
	].
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   436
	^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   437
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   438
    1 to:8 do:[:i |
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   439
	aFloat basicAt:i put:aStream next
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   440
    ]
9637
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   441
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   442
    "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
   443
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   444
    "Modified: / 23-08-2006 / 16:00:37 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   445
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   446
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   447
storeBinaryIEEEDouble:aFloat on:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   448
    "store aFloat as an IEEE formatted 8-byte float
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   449
     onto the binary stream, aStream"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   450
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   451
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   452
     this implementation is wrong: does not work on non-IEEE machines
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   453
     (to date all machines where ST/X is running on use
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   454
      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
   455
    "
3427
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   456
    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
   457
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   458
    UninterpretedBytes isBigEndian ifFalse:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   459
	"swap the bytes"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   460
	8 to:1 by:-1 do:[:i |
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   461
	    aStream nextPut:(aFloat basicAt:i).
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   462
	].
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   463
	^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   464
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   465
    1 to:8 do:[:i |
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   466
	aStream nextPut:(aFloat basicAt:i).
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   467
    ].
9637
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   468
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   469
    "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
   470
3e3866fb16e9 boss stuff separated
Claus Gittinger <cg@exept.de>
parents: 9150
diff changeset
   471
    "Modified: / 23-08-2006 / 16:00:47 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   472
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   473
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   474
!Float class methodsFor:'class initialization'!
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   475
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   476
initialize
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   477
    Pi isNil ifTrue:[
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   478
	DefaultPrintFormat := '.15'.  "/ print 15 valid digits
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   479
	Pi := 3.14159265358979323846264338327950288419716939937510582097494459.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   480
	Halfpi := Pi / 2.0.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   481
	HalfpiNegative := Halfpi negated.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   482
	Twopi := Pi * 2.0.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   483
	E := 2.7182818284590452353602874713526625.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   484
	Sqrt2 := 1.41421356237309504880168872420969808.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   485
	RadiansPerDegree := Pi / 180.0.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   486
	Ln2 := 0.69314718055994530941723212145817657.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   487
	Ln10 := 10.0 ln.
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   488
    ].
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   489
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   490
    "
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   491
     Pi := nil.
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   492
     self initialize
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   493
    "
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   494
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   495
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   496
     DefaultPrintFormat := '.9'.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   497
     Float pi printString.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   498
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   499
     DefaultPrintFormat := '.6'.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   500
     Float pi printString.
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   501
    "
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   502
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   503
    "Modified: / 07-06-2007 / 21:17:53 / cg"
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   504
! !
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   505
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   506
!Float class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   507
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   508
NaN
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   509
    "return the constant NaN (not a Number).
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   510
     Do not use (yet) - for now, this is only defined for a
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   511
     few selected architectures."
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   512
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   513
%{  /* NOCONTEXT */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8635
diff changeset
   514
#if defined(LINUX) && defined(__i386__)
3955
ebf11ebe113e NAN for suseV6 nan.h
Claus Gittinger <cg@exept.de>
parents: 3945
diff changeset
   515
# ifdef NAN
ebf11ebe113e NAN for suseV6 nan.h
Claus Gittinger <cg@exept.de>
parents: 3945
diff changeset
   516
    RETURN (__MKFLOAT(NAN));
ebf11ebe113e NAN for suseV6 nan.h
Claus Gittinger <cg@exept.de>
parents: 3945
diff changeset
   517
# else
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   518
    RETURN (__MKFLOAT(_SNAN));
3955
ebf11ebe113e NAN for suseV6 nan.h
Claus Gittinger <cg@exept.de>
parents: 3945
diff changeset
   519
# endif
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   520
#endif
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   521
%}.
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   522
    ^ super NaN
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   523
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   524
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   525
     Float NaN
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   526
     Float NaN + 0.0
3945
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   527
     Float NaN + Float NaN
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   528
     0.0 + Float NaN
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   529
    "
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   530
!
1745e97364cb added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents: 3903
diff changeset
   531
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   532
e
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   533
    "return the constant e as Float"
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   534
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   535
    "/ dont expect this many valid digits on all machines;
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   536
    "/ The actual precision is very CPU specific.
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   537
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
   538
    ^ 2.7182818284590452353602874713526625
6341
19a407a314da Raise more specific signals.
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   539
!
19a407a314da Raise more specific signals.
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
   540
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   541
ln2
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   542
    "/ dont expect this many valid digits on all machines;
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   543
    "/ The actual precision is very CPU specific.
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   544
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   545
    ^ 0.69314718055994530941723212145817657.
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   546
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   547
    "Created: / 07-06-2007 / 21:11:55 / cg"
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   548
!
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   549
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   550
pi
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   551
    "return the constant pi as Float"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   552
3244
9ba0abc1d217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3241
diff changeset
   553
    "/ dont expect this many valid digits on all machines;
9ba0abc1d217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3241
diff changeset
   554
    "/ The actual precision is very CPU specific.
9ba0abc1d217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3241
diff changeset
   555
6063
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   556
    ^ 3.14159265358979323846264338327950288419716939937510582097494459
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   557
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   558
    "Modified: 23.4.1996 / 09:27:02 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   559
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   560
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   561
sqrt2
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   562
    "/ dont expect this many valid digits on all machines;
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   563
    "/ The actual precision is very CPU specific.
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   564
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   565
    ^ 1.41421356237309504880168872420969808
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   566
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   567
    "Created: / 07-06-2007 / 21:12:33 / cg"
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   568
!
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
   569
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   570
unity
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   571
    "return the neutral element for multiplication (1.0) as Float"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   572
a27a279701f8 Initial revision
claus
parents:
diff changeset
   573
    ^ 1.0
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   574
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   575
    "Modified: 23.4.1996 / 09:27:09 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   576
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   577
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   578
zero
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   579
    "return the neutral element for addition (0.0) as Float"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   580
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   581
    ^ 0.0
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   582
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   583
    "Modified: 23.4.1996 / 09:27:15 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   584
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   585
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   586
!Float class methodsFor:'misc'!
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   587
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   588
getFPUControl
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   589
    "get the fpu control word."
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   590
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   591
%{
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   592
#ifdef __BORLANDC__
14106
900bb7bce82f *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 14105
diff changeset
   593
    unsigned int _control87();
900bb7bce82f *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 14105
diff changeset
   594
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   595
    int result = _control87(0, 0);
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   596
    RETURN(__MKSMALLINT(result));
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   597
#endif
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   598
%}
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   599
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   600
    "
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   601
	self getFPUControl
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   602
    "
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   603
!
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   604
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   605
setFPUControl
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   606
    "set the fpu control word.
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   607
     We want 64 bit precision for long double here"
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   608
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   609
%{
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   610
#ifdef __BORLANDC__
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   611
#include <float.h>
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   612
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   613
    // Set precision to long double / 64bit
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   614
    int result = _control87(PC_64, MCW_PC);
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   615
    RETURN(__MKSMALLINT(result));
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   616
#endif
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   617
%}
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   618
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   619
    "
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
   620
	self setFPUControl
14105
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   621
    "
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   622
! !
Stefan Vogel <sv@exept.de>
parents: 13146
diff changeset
   623
14599
3c1e4683d2f6 class: Float
Stefan Vogel <sv@exept.de>
parents: 14298
diff changeset
   624
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   625
!Float class methodsFor:'queries'!
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   626
6898
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   627
exponentCharacter
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   628
    ^ $d
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   629
!
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   630
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   631
hasSharedInstances
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   632
    "return true if this class has shared instances, that is, instances
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   633
     with the same value are identical.
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   634
     Although not really shared, floats should be treated
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   635
     so, to be independent of the implementation of the arithmetic methods."
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   636
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   637
    ^ true
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   638
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   639
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   640
!
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   641
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   642
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   643
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   644
     Here, true is returned for myself, false for subclasses."
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   645
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   646
    ^ self == Float
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   647
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   648
    "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
   649
!
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   650
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   651
isIEEEFormat
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   652
    "return true, if this machine represents floats in IEEE format.
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   653
     Currently, no support is provided for non-ieee machines
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   654
     to convert their floats into this (which is only relevant,
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   655
     if such a machine wants to send floats as binary to some other
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   656
     machine).
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   657
     Machines with non-IEEE format are VAXed and IBM370-type systems
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   658
     (among others). Today, most systems use IEEE format floats."
ba90490c94b6 added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents: 3414
diff changeset
   659
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   660
    ^ true "/ this may be a lie
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   661
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   662
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   663
numBitsInExponent
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   664
    "answer the number of bits in the exponent
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   665
     This is an IEEE float, where 11 bits are available:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   666
	seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   667
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   668
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   669
    ^ 11
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   670
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   671
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   672
numBitsInMantissa
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   673
    "answer the number of bits in the mantissa.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   674
     This is an IEEE double, where 52 bits (the hidden one is not counted here) are available:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   675
	seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   676
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   677
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   678
     ^ 52
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   679
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   680
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   681
precision
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   682
    "answer the precision of a Float (in bits)
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   683
     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
   684
     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
   685
     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
   686
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   687
    ^  53
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   688
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   689
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   690
radix
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   691
    "answer the radix of a Floats exponent
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   692
     This is an IEEE float, which is represented as binary"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   693
8635
38674ba49a14 comment
Claus Gittinger <cg@exept.de>
parents: 8422
diff changeset
   694
    ^ 2 "must be careful here, whenever ST/X is used on VAX or a 370"
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   695
! !
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   696
14298
693cc8edfaa7 Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents: 14108
diff changeset
   697
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   698
!Float methodsFor:'arithmetic'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   699
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   700
* aNumber
11733
fe4717d35e0c comment
Claus Gittinger <cg@exept.de>
parents: 11721
diff changeset
   701
    "return the product of the receiver and the argument."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   702
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   703
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   704
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   705
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   706
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   707
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   708
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   709
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   710
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   711
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   712
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   713
     */
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   714
    OBJ newFloat;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   715
    double result;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   716
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   717
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   718
	result = __floatVal(self) * (double)(__intVal(aNumber));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   719
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   720
	__qMKFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   721
	RETURN ( newFloat );
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   722
    }
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   723
    /* 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
   724
     * 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
   725
     */
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   726
    if (aNumber != nil) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   727
	if (__qIsFloatLike(aNumber)) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   728
	    result = __floatVal(self) * __floatVal(aNumber);
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   729
	    goto retResult;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   730
	}
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   731
	if (__qIsShortFloat(aNumber)) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   732
	    result = __floatVal(self) * (double)(__shortFloatVal(aNumber));
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   733
	    goto retResult;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   734
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   735
    }
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
   736
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   737
    ^ aNumber productFromFloat:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   738
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   739
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   740
+ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   741
    "return the sum of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   742
a27a279701f8 Initial revision
claus
parents:
diff changeset
   743
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   744
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   745
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   746
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   747
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   748
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   749
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   750
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   751
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   752
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   753
     */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   754
    OBJ newFloat;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   755
    double result;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   756
250
a5deb61ffdac *** empty log message ***
claus
parents: 224
diff changeset
   757
    if (__isSmallInteger(aNumber)) {
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
   758
	result = __floatVal(self) + (double)(__intVal(aNumber));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   759
retResult:
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
   760
	__qMKFLOAT(newFloat, result);
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
   761
	RETURN ( newFloat );
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   762
    }
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   763
    /* 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
   764
     * 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
   765
     */
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   766
    if (aNumber != nil) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   767
	if (__qIsFloatLike(aNumber)) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   768
	    result = __floatVal(self) + __floatVal(aNumber);
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   769
	    goto retResult;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   770
	}
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   771
	if (__qIsShortFloat(aNumber)) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   772
	    result = __floatVal(self) + (double)(__shortFloatVal(aNumber));
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   773
	    goto retResult;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   774
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   775
    }
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
   776
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   777
    ^ aNumber sumFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   778
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   779
a27a279701f8 Initial revision
claus
parents:
diff changeset
   780
- aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   781
    "return the difference of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   782
a27a279701f8 Initial revision
claus
parents:
diff changeset
   783
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   784
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   785
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   786
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   787
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   788
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   789
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   790
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   791
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   792
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   793
     */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   794
    OBJ newFloat;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   795
    double result;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   796
250
a5deb61ffdac *** empty log message ***
claus
parents: 224
diff changeset
   797
    if (__isSmallInteger(aNumber)) {
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
   798
	result = __floatVal(self) - (double)(__intVal(aNumber));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   799
retResult:
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
   800
	__qMKFLOAT(newFloat, result);
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
   801
	RETURN ( newFloat );
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   802
    }
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   803
    /* 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
   804
     * 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
   805
     */
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   806
    if (aNumber != nil) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   807
	if (__qIsFloatLike(aNumber)) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   808
	    result = __floatVal(self) - __floatVal(aNumber);
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   809
	    goto retResult;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   810
	}
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   811
	if (__qIsShortFloat(aNumber)) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   812
	    result = __floatVal(self) - (double)(__shortFloatVal(aNumber));
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   813
	    goto retResult;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   814
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   815
    }
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
   816
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   817
    ^ aNumber differenceFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   818
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   819
a27a279701f8 Initial revision
claus
parents:
diff changeset
   820
/ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   821
    "return the quotient of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   822
a27a279701f8 Initial revision
claus
parents:
diff changeset
   823
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   824
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   825
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   826
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   827
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   828
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   829
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   830
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   831
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   832
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   833
     */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   834
    OBJ newFloat;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   835
    double result, val;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   836
250
a5deb61ffdac *** empty log message ***
claus
parents: 224
diff changeset
   837
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   838
	if (aNumber != __mkSmallInteger(0)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   839
	    result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   840
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   841
	    __qMKFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   842
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   843
	}
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
   844
    } else if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   845
	val = __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   846
	if (val != 0.0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   847
	    result = __floatVal(self) / val;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   848
	    goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   849
	}
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
   850
    } else if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   851
	val = (double)(__shortFloatVal(aNumber));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   852
	if (val != 0.0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   853
	    result = __floatVal(self) / val;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   854
	    goto retResult;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   855
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   856
    }
3530
a1af5dafc3ee float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents: 3472
diff changeset
   857
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   858
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   859
	"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   860
	 No, you shalt not divide by zero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   861
	"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   862
	^ ZeroDivide raiseRequestWith:thisContext.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   863
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   864
    ^ aNumber quotientFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   865
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   866
14689
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   867
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
   868
    "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
   869
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   870
%{  /* NOCONTEXT */
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   871
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   872
    /*
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   873
     * notice:
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   874
     * 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
   875
     * 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
   876
     *
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   877
     * 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
   878
     * 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
   879
     * (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
   880
     */
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   881
    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
   882
    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
   883
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   884
    if (__isSmallInteger(aNumber)) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   885
	if (aNumber != __mkSmallInteger(0)) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   886
	    val = (double)__intVal(aNumber);
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   887
computeResult:
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   888
	    result = fmod(__floatVal(self), val) ;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   889
	    __qMKFLOAT(newFloat, result);
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   890
	    RETURN ( newFloat );
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   891
	}
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   892
    } else if (__isFloatLike(aNumber)) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   893
	val = __floatVal(aNumber);
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   894
	if (val != 0.0) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   895
	    goto computeResult;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   896
	}
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   897
    } else if (__isShortFloat(aNumber)) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   898
	val = (double)(__shortFloatVal(aNumber));
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   899
	if (val != 0.0) {
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   900
	    goto computeResult;
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   901
	}
14720
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   902
#ifdef LONGFLOAT_KNOWN_HERE
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   903
    } else if (__isLongFloat(aNumber)) {
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   904
	long double lval;
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   905
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   906
	lval = (long double)(__longFloatVal(aNumber));
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   907
	if (val != 0.0) {
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   908
	    long double lResult;
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   909
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   910
	    lResult = fmodl((long double)(__floatVal(self)), lval);
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   911
	    __qMKLFLOAT(newFloat, lResult);
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   912
	    RETURN (newFloat);
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   913
	}
ca17582f4fba comment
Claus Gittinger <cg@exept.de>
parents: 14689
diff changeset
   914
#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
   915
    }
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   916
%}.
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   917
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   918
	"
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   919
	 No, you shalt not divide by zero
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   920
	"
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   921
	^ ZeroDivide raiseRequestWith:thisContext.
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   922
    ].
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   923
    ^ 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
   924
!
f709732040c1 added rem: and a tiny performance speedup in other mixed-type arith messages
Claus Gittinger <cg@exept.de>
parents: 14672
diff changeset
   925
5411
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   926
abs
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   927
    "return the absolute value of the receiver
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   928
     reimplemented here for speed"
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   929
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   930
%{  /* NOCONTEXT */
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   931
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   932
    OBJ newFloat;
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   933
    double val =__floatVal(self);
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   934
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   935
    if (val < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   936
	__qMKFLOAT(newFloat, -val);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   937
	RETURN ( newFloat );
5411
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   938
    }
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   939
    RETURN (self);
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   940
%}.
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   941
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   942
    "
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   943
     3.0 abs
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   944
     -3.0 abs
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   945
    "
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   946
!
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   947
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   948
negated
a27a279701f8 Initial revision
claus
parents:
diff changeset
   949
    "return myself negated"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   950
a27a279701f8 Initial revision
claus
parents:
diff changeset
   951
%{  /* NOCONTEXT */
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   952
    OBJ newFloat;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   953
    double rslt = - __floatVal(self);
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   954
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   955
    __qMKFLOAT(newFloat, rslt);
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   956
    RETURN ( newFloat );
5411
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
   957
%}.
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   958
!
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   959
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   960
uncheckedDivide:aNumber
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   961
    "return the quotient of the receiver and the argument, aNumber.
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7441
diff changeset
   962
     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
   963
     This operation is provided for emulators of other languages/semantics,
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   964
     where no exception is raised for these results (i.e. Java).
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   965
     Its only defined if the arguments type is the same as the receivers."
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   966
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   967
%{  /* NOCONTEXT */
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   968
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   969
    OBJ newFloat;
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   970
    double result, val;
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   971
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   972
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   973
	result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   974
retResult:
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   975
	__qMKFLOAT(newFloat, result);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   976
	RETURN ( newFloat );
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   977
    }
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   978
    if (__isFloatLike(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   979
	val = __floatVal(aNumber);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   980
	result = __floatVal(self) / val;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   981
	goto retResult;
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   982
    }
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   983
    if (__isShortFloat(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   984
	val = (double)(__shortFloatVal(aNumber));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   985
	result = __floatVal(self) / val;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   986
	goto retResult;
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   987
    }
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
   988
%}.
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   989
    ^ aNumber quotientFromFloat:self
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   990
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   991
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   992
      0.0 uncheckedDivide:0.0
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   993
      1.0 uncheckedDivide:0.0
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
   994
      -1.0 uncheckedDivide:0.0
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   995
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   996
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   997
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   998
5238
f7a816a660a3 categories
Claus Gittinger <cg@exept.de>
parents: 5120
diff changeset
   999
!Float methodsFor:'coercing & converting'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1000
3014
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
  1001
asDouble
7429
3efb092371a3 comment
Claus Gittinger <cg@exept.de>
parents: 7420
diff changeset
  1002
    "ST80 compatibility: return a double with receivers value.
3efb092371a3 comment
Claus Gittinger <cg@exept.de>
parents: 7420
diff changeset
  1003
     our floats are the identical to ST80 doubles"
3014
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
  1004
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
  1005
    ^ self
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
  1006
!
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
  1007
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1008
asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1009
    "return a float with same value - thats me"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1010
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1011
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1012
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1013
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1014
asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1015
    "return an integer with same value - might truncate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1016
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1017
%{  /* NOCONTEXT */
1670
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1018
    double dVal;
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1019
1670
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1020
    dVal = __floatVal(self);
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
  1021
#ifdef WIN32
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1022
    if (! isnan(dVal))
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
  1023
#endif
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
  1024
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1025
	if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1026
	    RETURN ( __mkSmallInteger( (INT)dVal) );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1027
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1028
    }
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1029
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1030
    ^ super asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1031
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1032
    "12345.0 asInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1033
    "1e15 asInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1034
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1035
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1036
asLongFloat
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1037
    "return a longFloat with same value as receiver"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1038
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1039
    ^ LongFloat fromFloat:self
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1040
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1041
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1042
     123 asFloat asLongFloat
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1043
    "
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1044
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1045
    "Created: / 7.9.2001 / 13:43:04 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1046
    "Modified: / 7.9.2001 / 13:43:16 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1047
!
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1048
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1049
asShortFloat
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1050
    "return a shortFloat with same value as receiver.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1051
     CAVEAT: should raise an error if the receiver exceeds the float range."
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1052
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1053
%{  /* NOCONTEXT */
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1054
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1055
    OBJ dummy = @global(ShortFloat);
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1056
    OBJ newFloat;
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1057
    float fVal = (float)__floatVal(self);
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1058
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1059
    __qMKSFLOAT(newFloat, fVal);
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1060
    RETURN ( newFloat );
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1061
%}
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1062
!
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
  1063
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1064
asTrueFraction
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1065
    "Answer a fraction or integer that EXACTLY represents self,
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1066
     a double precision IEEE floating point number.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1067
     Floats are stored in the same form on all platforms.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1068
     (Does not handle gradual underflow or NANs.)
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1069
     By David N. Smith with significant performance
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1070
     improvements by Luciano Esteban Notarfrancesco.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1071
     (Version of 11April97)"
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1072
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1073
    |shifty sign expPart exp fraction fractionPart result zeroBitsCount|
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1074
6344
f49b43e5b724 Raise more specific errors
Stefan Vogel <sv@exept.de>
parents: 6341
diff changeset
  1075
    self isFinite ifFalse:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1076
	^ self asMetaNumber
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1077
"/        ^ self class
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1078
"/            raise:#domainErrorSignal
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1079
"/            receiver:self
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1080
"/            selector:#asTrueFraction
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1081
"/            arguments:#()
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1082
"/            errorString:'Cannot represent non-finite float as a fraction'.
6341
19a407a314da Raise more specific signals.
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
  1083
    ].
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1084
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1085
    "Extract the bits of an IEEE double float "
6341
19a407a314da Raise more specific signals.
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
  1086
    shifty := LargeInteger basicNew numberOfDigits:8.
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1087
    UninterpretedBytes isBigEndian ifTrue:[
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1088
"/        shifty := ((self longWordAt: 1) bitShift: 32) + (self longWordAt: 2).
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1089
	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
  1090
    ] ifFalse:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1091
	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
  1092
    ].
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1093
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1094
    " Extract the sign and the biased exponent "
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1095
    sign := (shifty bitShift: -63) = 0 ifTrue: [1] ifFalse: [-1].
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1096
    expPart := (shifty bitShift: -52) bitAnd: 16r7FF.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1097
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1098
    " 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
  1099
    fractionPart := shifty bitAnd:  16r000FFFFFFFFFFFFF.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1100
    ( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0  ].
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1101
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1102
    " Replace omitted leading 1 in fraction "
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1103
    fraction := fractionPart bitOr: 16r0010000000000000.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1104
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1105
    "Unbias exponent: 16r3FF is bias; 52 is fraction width"
7480
74f8bf8628e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1106
    exp := 16r3FF - expPart + 52.
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1107
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1108
    " 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
  1109
      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
  1110
      the (huge) time otherwise spent in #gcd:. "
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1111
    exp negative ifTrue: [
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1112
	result := sign * (fraction bitShift: exp negated)
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1113
    ] ifFalse:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1114
	zeroBitsCount := fraction lowBit - 1.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1115
	exp := exp - zeroBitsCount.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1116
	exp <= 0 ifTrue: [
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1117
	    zeroBitsCount := zeroBitsCount + exp.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1118
	    "exp := 0."   " Not needed; exp not refernced again "
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1119
	    result := sign * (fraction bitShift:zeroBitsCount negated)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1120
	] ifFalse: [
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1121
	    result := Fraction
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1122
		    numerator: (sign * (fraction bitShift: zeroBitsCount negated))
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1123
		    denominator: (1 bitShift:exp)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1124
	]
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1125
    ].
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1126
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1127
    "Low cost validation omitted after extensive testing"
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1128
    "(result asFloat = self) ifFalse: [self error: 'asTrueFraction validation failed']."
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1129
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1130
    ^ result
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1131
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1132
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1133
     0.3 asTrueFraction
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1134
     1.25 asTrueFraction
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1135
     0.25 asTrueFraction
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1136
     -0.25 asTrueFraction
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1137
     3e37 asTrueFraction
6341
19a407a314da Raise more specific signals.
Stefan Vogel <sv@exept.de>
parents: 6335
diff changeset
  1138
     Float NaN asTrueFraction
6344
f49b43e5b724 Raise more specific errors
Stefan Vogel <sv@exept.de>
parents: 6341
diff changeset
  1139
     Float infinity asTrueFraction
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1140
    "
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1141
!
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
  1142
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1143
coerce:aNumber
11721
358878a3860c comment
Claus Gittinger <cg@exept.de>
parents: 11487
diff changeset
  1144
    "convert the argument aNumber into an instance of the receivers class and return it."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1145
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1146
    ^ aNumber asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1147
!
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1148
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1149
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1150
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1151
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1152
    ^ 80
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1153
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1154
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1155
!Float methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1156
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1157
< aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1158
    "return true, if the argument is greater"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1159
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1160
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1161
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1162
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1163
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1164
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1165
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1166
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1167
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1168
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1169
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1170
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1171
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1172
	RETURN ( (__floatVal(self) < (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1173
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1174
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1175
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1176
	    RETURN ( (__floatVal(self) < __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1177
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1178
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1179
	    RETURN ( (__floatVal(self) < (double)(__shortFloatVal(aNumber))) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1180
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1181
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1182
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1183
    ^ aNumber lessFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1184
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1185
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1186
<= aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1187
    "return true, if the argument is greater or equal"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1188
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1189
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1190
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1191
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1192
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1193
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1194
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1195
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1196
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1197
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1198
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1199
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1200
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1201
	RETURN ( (__floatVal(self) <= (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1202
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1203
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1204
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1205
	    RETURN ( (__floatVal(self) <= __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1206
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1207
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1208
	    RETURN ( (__floatVal(self) <= (double)(__shortFloatVal(aNumber))) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1209
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1210
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1211
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1212
    ^ self retry:#<= coercing:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1213
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1214
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1215
= aNumber
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1216
    "return true, if the argument represents the same numeric value
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1217
     as the receiver, false otherwise"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1218
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1219
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1220
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1221
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1222
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1223
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1224
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1225
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1226
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1227
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1228
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1229
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1230
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1231
	RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1232
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1233
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1234
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1235
	    RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1236
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1237
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1238
	    RETURN ( (__floatVal(self) == (double)(__shortFloatVal(aNumber))) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1239
	}
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1240
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1241
	RETURN (false);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1242
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1243
%}.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1244
    ^ aNumber equalFromFloat:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1245
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1246
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1247
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1248
    "return true, if the argument is less"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1249
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1250
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1251
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1252
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1253
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1254
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1255
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1256
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1257
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1258
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1259
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1260
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1261
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1262
	RETURN ( (__floatVal(self) > (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1263
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1264
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1265
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1266
	    RETURN ( (__floatVal(self) > __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1267
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1268
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1269
	    RETURN ( (__floatVal(self) > (double)(__shortFloatVal(aNumber))) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1270
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1271
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1272
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1273
    ^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1274
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1275
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1276
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1277
    "return true, if the argument is less or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1278
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1279
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1280
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1281
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1282
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1283
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1284
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1285
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1286
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1287
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1288
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1289
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1290
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1291
	RETURN ( (__floatVal(self) >= (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1292
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1293
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1294
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1295
	    RETURN ( (__floatVal(self) >= __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1296
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1297
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1298
	    RETURN ( (__floatVal(self) >= (double)(__shortFloatVal(aNumber))) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1299
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1300
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1301
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1302
    ^ self retry:#>= coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1303
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1304
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1305
hash
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1306
    "return a number for hashing; redefined, since floats compare
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1307
     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
  1308
     as 3 hash."
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1309
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
  1310
    |i|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1311
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1312
    (self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  1313
	i := self asInteger.
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  1314
	self = i ifTrue:[
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  1315
	    ^ i hash
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  1316
	].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1317
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1318
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1319
    "
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
  1320
     mhmh take some of my value-bits to hash on
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1321
    "
4590
3db3bf4615bd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1322
    ^ (((self basicAt:8) bitAnd:16r1F) bitShift:24) +
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
  1323
      ((self basicAt:7) bitShift:16) +
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
  1324
      ((self basicAt:6) bitShift:8) +
4592
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  1325
      (((self basicAt:5) + (self basicAt:1) + (self basicAt:2)) bitAnd:16rFF)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1326
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1327
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1328
     3 hash
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1329
     3.0 hash
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1330
     3.1 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1331
     3.14159 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1332
     31.4159 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1333
     3.141591 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1334
     1.234567890123456 hash
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1335
     1.234567890123457 hash
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1336
     Set withAll:#(3 3.0 99 99.0 3.1415)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1337
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1338
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1339
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1340
~= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1341
    "return true, if the arguments value are not equal"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1342
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1343
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1344
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1345
    /*
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1346
     * notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1347
     * the following inline code handles some common cases,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1348
     * and exists as an optimization, to speed up those cases.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1349
     *
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1350
     * Conceptionally, (and for most other argument types),
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1351
     * mixed arithmetic is implemented by double dispatching
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1352
     * (see the message send at the bottom)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1353
     */
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1354
    if (__isSmallInteger(aNumber)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1355
	RETURN ( (__floatVal(self) != (double)(__intVal(aNumber))) ? true : false );
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1356
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1357
    if (aNumber != nil) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1358
	if (__qIsFloatLike(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1359
	    RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1360
	}
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1361
	if (__qIsShortFloat(aNumber)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1362
	    RETURN ( (__floatVal(self) != (double)(__shortFloatVal(aNumber))) ? true : false );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1363
	}
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
  1364
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1365
	RETURN ( true );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1366
    }
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1367
%}.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1368
    ^ super ~= aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1369
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1370
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1371
!Float methodsFor:'mathematical functions'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1372
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1373
exp
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1374
    "return e raised to the power of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1375
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1376
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1377
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1378
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1379
    OBJ newFloat;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1380
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1381
    __threadErrno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1382
    rslt = exp(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  1383
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  1384
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1385
	if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1386
	    __qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1387
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1388
	}
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1389
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1390
%}.
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3279
diff changeset
  1391
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1392
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1393
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1394
	selector:#exp
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1395
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1396
	errorString:'bad receiver in exp'
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6193
diff changeset
  1397
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6193
diff changeset
  1398
    "Modified: / 16.11.2001 / 14:14:29 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1399
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1400
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1401
ln
6193
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  1402
    "return the natural logarithm of myself.
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  1403
     Raises an exception, if the receiver is less or equal to zero."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1404
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1405
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1406
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  1407
    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
  1408
    OBJ newFloat;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1409
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  1410
    val = __floatVal(self);
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  1411
6193
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  1412
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  1413
    if (val > 0.0)
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  1414
#endif
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  1415
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1416
	__threadErrno = 0;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1417
	rslt = log(val);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1418
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1419
	{
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1420
	    if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1421
		__qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1422
		RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1423
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1424
	}
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1425
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1426
%}.
142
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
  1427
    "
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
  1428
     an invalid value for logarithm
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
  1429
    "
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3279
diff changeset
  1430
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1431
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1432
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1433
	selector:#ln
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1434
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1435
	errorString:'bad receiver in ln'
6193
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  1436
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6193
diff changeset
  1437
    "Modified: / 16.11.2001 / 14:14:33 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1438
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1439
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1440
log10
12583
4271383b5862 changed: #log10
Claus Gittinger <cg@exept.de>
parents: 12478
diff changeset
  1441
    "return the base-10 logarithm of myself.
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1442
     Raises an exception, if the receiver is less or equal to zero."
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1443
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1444
%{  /* NOCONTEXT */
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1445
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1446
    double val, rslt;
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1447
    OBJ newFloat;
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1448
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1449
    val = __floatVal(self);
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1450
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1451
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1452
    if (val > 0.0)
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1453
#endif
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1454
    {
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1455
	__threadErrno = 0;
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1456
	rslt = log10(val);
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1457
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1458
	{
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1459
	    if (__threadErrno == 0) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1460
		__qMKFLOAT(newFloat, rslt);
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1461
		RETURN ( newFloat );
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1462
	    }
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1463
	}
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1464
    }
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1465
%}.
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1466
    "
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1467
     an invalid value for logarithm
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1468
    "
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1469
    ^ self class
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1470
	raise:#domainErrorSignal
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1471
	receiver:self
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1472
	selector:#log10
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1473
	arguments:#()
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1474
	errorString:'bad receiver in log10'
7373
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1475
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1476
    "Modified: / 16.11.2001 / 14:14:33 / cg"
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1477
!
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1478
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1479
raisedTo:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1480
    "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
  1481
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1482
    |n|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1483
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1484
    n := aNumber asFloat.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1485
%{
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1486
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1487
    OBJ newFloat;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1488
283
a897d331b4c1 *** empty log message ***
claus
parents: 258
diff changeset
  1489
    if (__isFloatLike(n)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1490
	__threadErrno = 0;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1491
	rslt = pow(__floatVal(self), __floatVal(n));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1492
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1493
	{
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1494
	    if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1495
		__qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1496
		RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1497
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1498
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1499
    }
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1500
%}.
142
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
  1501
    "
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
  1502
     an invalid argument (not convertable to float ?)
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
  1503
    "
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3279
diff changeset
  1504
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1505
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1506
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1507
	selector:#raisedTo:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1508
	arguments:(Array with:aNumber)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1509
	errorString:'bad receiver/arg in raisedTo:'
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6193
diff changeset
  1510
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6193
diff changeset
  1511
    "Modified: / 16.11.2001 / 14:16:51 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1512
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1513
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1514
sqrt
6193
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  1515
    "return the square root of myself.
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  1516
     Raises an exception, if the receiver is less than zero."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1517
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1518
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1519
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  1520
    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
  1521
    OBJ newFloat;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1522
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  1523
    val = __floatVal(self);
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  1524
6193
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  1525
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
6189
f4bfc2dacdb7 win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents: 6145
diff changeset
  1526
    if (val >= 0.0)
3889
3466554b639f manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents: 3632
diff changeset
  1527
#endif
3466554b639f manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents: 3632
diff changeset
  1528
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1529
	__threadErrno = 0;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1530
	rslt = sqrt(val);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1531
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1532
	{
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1533
	    if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1534
		__qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1535
		RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1536
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1537
	}
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1538
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1539
%}.
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3279
diff changeset
  1540
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1541
	raise:#imaginaryResultSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1542
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1543
	selector:#sqrt
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1544
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1545
	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
  1546
4f45ebb7bc60 oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
  1547
    "
4f45ebb7bc60 oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
  1548
     10 sqrt
4f45ebb7bc60 oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
  1549
     -10 sqrt
4f45ebb7bc60 oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
  1550
    "
6193
69f010509638 comments
Claus Gittinger <cg@exept.de>
parents: 6189
diff changeset
  1551
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6193
diff changeset
  1552
    "Modified: / 16.11.2001 / 14:14:43 / cg"
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1553
! !
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1554
14298
693cc8edfaa7 Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents: 14108
diff changeset
  1555
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1556
!Float methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1557
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1558
printString
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1559
    "return a printed representation of the receiver;
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1560
     if not specified otherwise (by setting DefaultPrintFormat),
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3163
diff changeset
  1561
     6 valid digits are printed.
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3163
diff changeset
  1562
     LimitedPrecisonReal and its subclasses use #printString instead of
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3163
diff changeset
  1563
     #printOn: as basic print mechanism."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1564
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1565
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1566
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1567
    char buffer[64];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1568
    REGISTER char *cp;
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1569
    OBJ s;
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1570
    char *fmt;
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1571
    char fmtBuffer[20];
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  1572
    int len;
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1573
12478
e8051030cda6 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12423
diff changeset
  1574
    if (__isStringLike(@global(DefaultPrintFormat))) {
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1575
	fmt = (char *) __stringVal(@global(DefaultPrintFormat));
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1576
    } else {
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1577
	/*
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1578
	 * in case we get called before #initialize ...
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1579
	 */
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1580
	fmt = ".15";
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1581
    }
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1582
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1583
    /*
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1584
     * build a printf format string
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1585
     */
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1586
    fmtBuffer[0] = '%';
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1587
    strncpy(fmtBuffer+1, fmt, 10);
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1588
#ifdef SYSV
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1589
    strcat(fmtBuffer, "lg");
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1590
#else
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1591
    strcat(fmtBuffer, "G");
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
  1592
#endif
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1593
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  1594
    __BEGIN_PROTECT_REGISTERS__
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  1595
    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
  1596
    __END_PROTECT_REGISTERS__
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  1597
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  1598
    if (len >= 0 && len < sizeof(buffer)-3) {
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1599
	/*
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1600
	 * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1601
	 * (i.e. look if string contains '.' or 'e' and append '.0' if not)
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1602
	 */
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1603
	for (cp = buffer; *cp; cp++) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1604
	    if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break;
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1605
	}
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1606
	if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1607
	    if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1608
		*cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1609
	    } else {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1610
		*cp++ = '.';
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1611
	    }
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1612
	    *cp++ = '0';
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1613
	    *cp = '\0';
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1614
	} else {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1615
	    if (cp && ((*cp == '.') || (*cp == ','))) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1616
		if (__isCharacter(@global(DecimalPointCharacterForPrinting))) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1617
		    *cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting)));
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1618
		}
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1619
	    }
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1620
	}
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1621
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1622
	s = __MKSTRING(buffer);
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1623
	if (s != nil) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1624
	    RETURN (s);
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1625
	}
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1626
    }
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1627
%}.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1628
    "
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1629
     memory allocation (for the new string) failed.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1630
     When we arrive here, there was no memory, even after a garbage collect.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1631
     This means, that the VM wanted to get some more memory from the
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1632
     OS, which was not kind enough to give it.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1633
     Bad luck - you should increase the swap space on your machine.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1634
    "
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1635
    ^ ObjectMemory allocationFailureSignal raise.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1636
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1637
    "
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1638
	1.0 printString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1639
	1.234 printString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1640
	1e10 printString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1641
	1.2e3 printString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1642
	1.2e30 printString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1643
	(1.0 uncheckedDivide:0) printString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1644
	(0.0 uncheckedDivide:0) printString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1645
	self pi printString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1646
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1647
	DecimalPointCharacter := $,.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1648
	1.234 printString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1649
	1.0 printString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1650
	1e10 printString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1651
	1.2e3 printString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1652
	1.2e30 printString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1653
	(1.0 uncheckedDivide:0) printString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1654
	(0.0 uncheckedDivide:0) printString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1655
	DecimalPointCharacter := $.
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1656
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1657
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1658
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1659
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7724
diff changeset
  1660
    "non-standard: return a printed representation of the receiver
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1661
     as specified by formatString, which is defined by printf.
31
75f2b9f78be2 *** empty log message ***
claus
parents: 16
diff changeset
  1662
     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
  1663
     systems; on SYSV machines you have to give something like %lf,
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1664
     while on BSD systems the format string has to be %F.
31
75f2b9f78be2 *** empty log message ***
claus
parents: 16
diff changeset
  1665
     Also, the resulting string may not be longer than 255 bytes -
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 47
diff changeset
  1666
     since thats the (static) size of the buffer.
11926
295e8bb99fde changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11733
diff changeset
  1667
     This method is NONSTANDARD and may be removed without notice.
295e8bb99fde changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11733
diff changeset
  1668
     WARNNG: this goes directly to the C-printf function and may therefore me inherently unsafe.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1669
11926
295e8bb99fde changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11733
diff changeset
  1670
     Please use the printf: method, which is safe as it is completely implemented in Smalltalk."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1671
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1672
%{  /* STACK: 400 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1673
    char buffer[256];
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1674
    OBJ s;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  1675
    int len;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1676
12478
e8051030cda6 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12423
diff changeset
  1677
    if (__isStringLike(formatString)) {
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1678
	/*
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1679
	 * actually only needed on sparc: since thisContext is
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1680
	 * in a global register, which gets destroyed by printf,
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1681
	 * manually save it here - very stupid ...
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1682
	 */
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1683
	__BEGIN_PROTECT_REGISTERS__
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1684
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1685
	len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __floatVal(self));
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1686
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1687
	__END_PROTECT_REGISTERS__
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1688
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1689
	if (len < 0) goto fail;
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1690
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1691
	s = __MKSTRING_L(buffer, len);
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1692
	if (s != nil) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1693
	    RETURN (s);
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1694
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1695
    }
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8302
diff changeset
  1696
fail: ;
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1697
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1698
    self primitiveFailed
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1699
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1700
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1701
     Float pi printfPrintString:'%%lg -> %lg'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1702
     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
  1703
     Float pi printfPrintString:'%%7.15lg -> %7.15lg'
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1704
     Float pi printfPrintString:'%%7.5lf -> %7.5lf'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1705
     Float pi printfPrintString:'%%G -> %G'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1706
     Float pi printfPrintString:'%%F -> %F'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1707
     Float pi printfPrintString:'%%7.5G -> %7.5G'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1708
     Float pi printfPrintString:'%%7.5F -> %7.5F'
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1709
    "
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1710
!
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1711
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1712
storeString
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1713
    "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
  1714
     all valid digits are printed.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1715
     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
  1716
     #storeOn: as basic print mechanism."
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1717
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1718
%{  /* NOCONTEXT */
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1719
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1720
    char buffer[64];
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1721
    REGISTER char *cp;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1722
    OBJ s;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1723
    int len;
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1724
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1725
    __BEGIN_PROTECT_REGISTERS__
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1726
#ifdef SYSV
12916
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
  1727
    len = snprintf(buffer, sizeof(buffer), "%.15lg", __floatVal(self));
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1728
#else
12916
a32796fca6ed #printString prints with maximum precision (15 for Float and 19 for LongFloat)
Stefan Vogel <sv@exept.de>
parents: 12723
diff changeset
  1729
    len = snprintf(buffer, sizeof(buffer), "%.15G", __floatVal(self));
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1730
#endif
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1731
    __END_PROTECT_REGISTERS__
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1732
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1733
    if (len >= 0 && len < sizeof(buffer)-3) {
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1734
	/*
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1735
	 * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1736
	 * (i.e. look if string contains '.' or 'e' and append '.0' if not)
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1737
	 */
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1738
	for (cp = buffer; *cp; cp++) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1739
	    if ((*cp == '.') || (*cp == ',') || (*cp == 'E') || (*cp == 'e')) break;
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1740
	}
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1741
	if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1742
	    *cp++ = '.';
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1743
	    *cp++ = '0';
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1744
	    *cp = '\0';
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1745
	}
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1746
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1747
	s = __MKSTRING(buffer);
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1748
	if (s != nil) {
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1749
	    RETURN (s);
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1750
	}
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1751
    }
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1752
%}.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1753
    "
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1754
     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
  1755
     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
  1756
     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
  1757
     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
  1758
     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
  1759
    "
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1760
    ^ ObjectMemory allocationFailureSignal raise.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1761
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1762
    "
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1763
	1.0 storeString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1764
	1.234 storeString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1765
	1e10 storeString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1766
	1.2e3 storeString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1767
	1.2e30 storeString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1768
	Float pi storeString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1769
	(1.0 uncheckedDivide:0) storeString
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1770
	(0.0 uncheckedDivide:0) storeString
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1771
9124
1bc6bb791bdc decimalPoint control
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  1772
     notice that the storeString is NOT affected by DecimalPointCharacterForPrinting:
1bc6bb791bdc decimalPoint control
Claus Gittinger <cg@exept.de>
parents: 8984
diff changeset
  1773
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1774
	DecimalPointCharacterForPrinting := $,.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1775
	1.234 storeString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1776
	1.0 storeString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1777
	1e10 storeString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1778
	1.2e3 storeString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1779
	1.2e30 storeString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1780
	(1.0 uncheckedDivide:0) storeString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1781
	(0.0 uncheckedDivide:0) storeString.
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1782
	DecimalPointCharacterForPrinting := $.
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  1783
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1784
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1785
11926
295e8bb99fde changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11733
diff changeset
  1786
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7217
diff changeset
  1787
!Float methodsFor:'private-accessing'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1788
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1789
basicAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1790
    "return an internal byte of the float.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1791
     The value returned here depends on byte order, float representation etc.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1792
     Therefore, this method should be used strictly private.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1793
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1794
     Notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1795
	the need to redefine this method here is due to the
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1796
	inability of many machines to store floats in non-double aligned memory.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1797
	Therefore, on some machines, the first 4 bytes of a float are left unused,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1798
	and the actual float is stored at index 5 .. 12.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1799
	To hide this at one place, this method knows about that, and returns
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1800
	values as if this filler wasnt present."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1801
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1802
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1803
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1804
    register int indx;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1805
    unsigned char *cp;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1806
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1807
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1808
     * notice the missing test for self being a nonNilObject -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1809
     * this can be done since basicAt: is defined both in UndefinedObject
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1810
     * and SmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1811
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1812
    if (__isSmallInteger(index)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1813
	indx = __intVal(index) - 1;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1814
	if (((unsigned)(indx)) < sizeof(double)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1815
	    cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1816
	    RETURN ( __mkSmallInteger(cp[indx] & 0xFF) );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1817
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1818
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1819
%}.
7217
554bb9c2ba24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1820
    ^ self indexNotIntegerOrOutOfBounds:index
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1821
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1822
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1823
basicAt:index put:value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1824
    "set an internal byte of the float.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1825
     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
  1826
     Therefore, this method should be used strictly private.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1827
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1828
     Notice:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1829
	the need to redefine this method here is due to the
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1830
	inability of many machines to store floats in non-double aligned memory.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1831
	Therefore, on some machines, the first 4 bytes of a float are left unused,
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1832
	and the actual float is stored at index 5 .. 12.
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1833
	To hide this at one place, this method knows about that, and returns
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1834
	values as if this filler wasnt present."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1835
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1836
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1837
    register int indx, val;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1838
    unsigned char *cp;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1839
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1840
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1841
     * notice the missing test for self being a nonNilObject -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1842
     * this can be done since basicAt: is defined both in UndefinedObject
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1843
     * and SmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1844
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1845
    if (__bothSmallInteger(index, value)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1846
	val = __intVal(value);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1847
	if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1848
	    indx = __intVal(index) - 1;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1849
	    if (((unsigned)(indx)) < sizeof(double)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1850
		cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1851
		cp[indx] = val;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1852
		RETURN ( value );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1853
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1854
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1855
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1856
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1857
    value isInteger ifFalse:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1858
	"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1859
	 the object to store should be an integer number
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1860
	"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1861
	^ self elementNotInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1862
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1863
    (value between:0 and:255) ifFalse:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1864
	"
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1865
	 the object to store must be a bytes value
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
	^ self elementBoundsError:value
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1868
    ].
7217
554bb9c2ba24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
  1869
    ^ self indexNotIntegerOrOutOfBounds:index
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1870
! !
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1871
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
  1872
!Float methodsFor:'queries'!
4592
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  1873
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  1874
basicSize
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  1875
    "return the size in bytes of the float.
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  1876
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1877
     Notice:
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  1878
	the need to redefine this method here is due to the
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  1879
	inability of many machines to store floats in non-double aligned memory.
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  1880
	Therefore, on some machines, the first 4 bytes of a float are left unused,
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  1881
	and the actual float is stored at index 5 .. 12.
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  1882
	To hide this at one place, this method knows about that, and returns
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  1883
	values as if this filler wasnt present."
4592
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  1884
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  1885
%{  /* NOCONTEXT */
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  1886
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1887
    RETURN (__mkSmallInteger(sizeof(double)));
4592
f68de0746dab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4590
diff changeset
  1888
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1889
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1890
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1891
!Float methodsFor:'special access'!
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1892
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1893
exponent
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1894
    "extract a normalized floats exponent.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1895
     The returned value depends on the float-representation of
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1896
     the underlying machine and is therefore highly unportable.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1897
     This is not for general use.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1898
     This assumes that the mantissa is normalized to
12423
a3c777accbb0 changed: #exponent
Claus Gittinger <cg@exept.de>
parents: 11945
diff changeset
  1899
     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
  1900
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1901
%{  /* NOCONTEXT */
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1902
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1903
    double frexp();
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1904
    double frac;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1905
    int exp;
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1906
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1907
    __threadErrno = 0;
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1908
    frac = frexp(__floatVal(self), &exp);
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1909
    if (__threadErrno == 0) {
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1910
	RETURN (__mkSmallInteger(exp));
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1911
    }
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1912
%}.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1913
    ^ self primitiveFailed
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1914
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1915
    "
14672
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1916
     1.0 exponent
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1917
     2.0 exponent
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1918
     3.0 exponent
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1919
     4.0 exponent
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1920
     0.5 exponent
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1921
     0.4 exponent
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1922
     0.25 exponent
8abd84f0951a setlocale once only in stxmain
Claus Gittinger <cg@exept.de>
parents: 14630
diff changeset
  1923
     0.2 exponent
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1924
     0.00000011111 exponent
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1925
    "
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1926
!
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1927
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1928
mantissa
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1929
    "extract a normalized floats mantissa.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1930
     The returned value depends on the float-representation of
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1931
     the underlying machine and is therefore highly unportable.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1932
     This is not for general use.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1933
     This assumes that the mantissa is normalized to
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1934
     0.5 .. 1.0 and the floats value is mantissa * 2^exp"
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1935
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1936
%{  /* NOCONTEXT */
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1937
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1938
    double frexp();
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1939
    double frac;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1940
    int exp;
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1941
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1942
    __threadErrno = 0;
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1943
    frac = frexp(__floatVal(self), &exp);
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  1944
    if (__threadErrno == 0) {
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
  1945
	RETURN (__MKFLOAT(frac));
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1946
    }
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1947
%}.
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1948
    ^ self primitiveFailed
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1949
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1950
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1951
     1.0 exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1952
     1.0 mantissa
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1953
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1954
     0.25 exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1955
     0.25 mantissa
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1956
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1957
     0.00000011111 exponent
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1958
     0.00000011111 mantissa
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1959
    "
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1960
! !
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  1961
14298
693cc8edfaa7 Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents: 14108
diff changeset
  1962
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1963
!Float methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1964
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1965
isFinite
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1966
    "return true, if the receiver is a finite float
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1967
     i.e. not NaN and not infinite."
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1968
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1969
%{  /* NOCONTEXT */
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1970
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1971
    double dV = __floatVal(self);
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1972
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  1973
    /*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  1974
     * notice: on machines which do not provide
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1975
     * a finite() macro or function (WIN32),
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
  1976
     * 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
  1977
     */
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1978
    if (isfinite(dV)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1979
	RETURN (true);
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  1980
    }
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1981
%}.
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
  1982
    ^ false
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1983
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1984
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1985
	1.0 isFinite
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1986
	Float NaN isFinite
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1987
	Float infinity isFinite
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1988
	(0.0 uncheckedDivide: 0.0) isFinite
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  1989
	(1.0 uncheckedDivide: 0.0) isFinite
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1990
    "
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1991
!
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1992
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1993
isInfinite
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1994
    "return true, if the receiver is an infinite float (Inf).
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1995
     These are not created by ST/X float operations (they raise an exception);
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1996
     however, inline C-code could produce them ...
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1997
     Redefined here for speed"
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1998
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1999
%{  /* NOCONTEXT */
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2000
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2001
    double dV = __floatVal(self);
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2002
3198
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2003
    /*
4f930c1c96e7 care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents: 3194
diff changeset
  2004
     * notice: on machines which do not provide
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2005
     * finite() & isnan() macros or functions (WIN32),
4305
e71100d13b67 void possible return warning
Claus Gittinger <cg@exept.de>
parents: 4296
diff changeset
  2006
     * 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
  2007
     */
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
  2008
#if defined(isinf)
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2009
    if (isinf(dV)) { RETURN (true); }
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2010
#else
8980
abee9fcb0385 cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
  2011
    if (!isfinite(dV) && !isnan(dV)) { RETURN (true); }
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2012
#endif
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2013
%}.
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2014
    ^ false
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2015
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2016
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2017
	1.0 isInfinite
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2018
	(0.0 uncheckedDivide: 0.0) isInfinite
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2019
	(1.0 uncheckedDivide: 0.0) isInfinite
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2020
	(-1.0 uncheckedDivide: 0.0) isInfinite
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2021
    "
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2022
!
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2023
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2024
isLiteral
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2025
    "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
  2026
     (i.e. can be used in constant arrays)"
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2027
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2028
    ^ true
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2029
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2030
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2031
!
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2032
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2033
isNaN
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2034
    "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
  2035
     These are not created by ST/X float operations (they raise an exception);
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2036
     however, inline C-code could produce them ..."
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2037
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2038
%{  /* NOCONTEXT */
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2039
3139
ca
parents: 3129
diff changeset
  2040
    double dV = (__floatVal(self));
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2041
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2042
    if (isnan(dV)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2043
	RETURN (true);
7420
633c9331da21 isnan for Win32
Claus Gittinger <cg@exept.de>
parents: 7411
diff changeset
  2044
    }
2392
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  2045
%}.
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  2046
    ^ false
3139
ca
parents: 3129
diff changeset
  2047
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2048
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2049
	1.0 isNaN
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2050
	(0.0 uncheckedDivide: 0.0) isNaN
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2051
	(1.0 uncheckedDivide: 0.0) isNaN
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2052
	(-1.0 uncheckedDivide: 0.0) isNaN
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  2053
    "
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2054
!
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2055
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2056
isNegativeZero
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2057
    "many systems have two float.Pnt zeros"
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2058
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2059
%{
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8635
diff changeset
  2060
#if defined(__i386__) && defined(LINUX)
7441
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  2061
    unsigned int biasedExponent;
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  2062
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  2063
    biasedExponent = ((short *)(__ByteArrayInstPtr(self)->ba_element))[3] & 0xFF70;
17e37777f83b double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  2064
    RETURN ((biasedExponent == 0x8000) ? true : false );
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2065
#endif
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2066
%}.
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2067
    ^ super isNegativeZero
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2068
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2069
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2070
     0.0 isNegativeZero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2071
     -0.0 isNegativeZero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2072
     -1.0 isNegativeZero
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2073
     1.0 isNegativeZero
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2074
    "
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2075
!
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2076
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2077
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2078
    "return true if the receiver is less than zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2079
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2080
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2081
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2082
    RETURN ( (__floatVal(self) < 0.0) ? true : false );
5411
c396c6640868 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5357
diff changeset
  2083
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2084
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2085
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2086
numberOfBits
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2087
    "return the size (in bits) of the real;
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2088
     typically, 64 is returned here,
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2089
     but who knows ..."
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2090
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2091
%{  /* NOCONTEXT */
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2092
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2093
    RETURN (__mkSmallInteger (sizeof(double) * 8));
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2094
%}
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2095
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2096
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2097
     1.2 numberOfBits
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2098
     1.2 asShortFloat numberOfBits
5357
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2099
    "
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2100
!
39860dd8b0f5 query for number of bits
ps
parents: 5317
diff changeset
  2101
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2102
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2103
    "return true if the receiver is greater or equal to zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2104
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2105
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2106
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2107
    RETURN ( (__floatVal(self) >= 0.0) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2108
%}
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2109
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2110
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2111
strictlyPositive
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2112
    "return true if the receiver is greater than zero"
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2113
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2114
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2115
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2116
    RETURN ( (__floatVal(self) > 0.0) ? true : false );
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2117
%}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2118
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2119
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2120
!Float methodsFor:'tracing'!
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2121
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4655
diff changeset
  2122
traceInto:aRequestor level:level from:referrer
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2123
    "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
  2124
4682
4158042a9c8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4655
diff changeset
  2125
    ^ aRequestor traceFloat:self level:level from:referrer
4655
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2126
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2127
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2128
! !
b9405ca0bb4e added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
  2129
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2130
!Float methodsFor:'trigonometric'!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2131
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2132
arcCos
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2133
    "return the arccosine of the receiver (as radians).
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2134
     Raises an exception, if the receiver is not in -1..1"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2135
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2136
%{  /* NOCONTEXT */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2137
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2138
    double val, rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2139
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2140
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2141
    val = __floatVal(self);
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2142
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2143
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2144
    if ((val >= -1.0) && (val <= 1.0))
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2145
#endif
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2146
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2147
	__threadErrno = 0;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2148
	rslt = acos(val);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2149
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2150
	{
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2151
	    if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2152
		__qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2153
		RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2154
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2155
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2156
    }
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2157
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2158
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2159
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2160
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2161
	selector:#arcCos
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2162
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2163
	errorString:'bad receiver in arcCos'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2164
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2165
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2166
     -10 arcCos
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2167
     1 arcCos
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2168
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2169
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2170
    "Modified: / 16.11.2001 / 14:14:13 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2171
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2172
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2173
arcCosh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2174
    "return the hyperbolic arccosine of the receiver."
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2175
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2176
    |useFallBack|
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2177
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2178
%{
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2179
#ifdef NO_ACOSH
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2180
    useFallBack = true;
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2181
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2182
    double val, rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2183
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2184
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2185
    val = __floatVal(self);
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2186
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2187
# ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2188
    if (val >= 1.0)
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2189
# endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2190
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2191
	__threadErrno = 0;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2192
	rslt = acosh(val);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2193
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2194
	{
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2195
	    if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2196
		__qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2197
		RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2198
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2199
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2200
    }
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2201
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2202
%}.
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2203
    useFallBack notNil ifTrue:[
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2204
	^ super arcCosh
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2205
    ].
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2206
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2207
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2208
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2209
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2210
	selector:#arcCosh
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2211
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2212
	errorString:'bad receiver in arcCosh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2213
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2214
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2215
     -10.0 arcCosh
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2216
     1.0 arcCosh
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2217
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2218
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2219
    "Modified: / 16.11.2001 / 14:14:13 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2220
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2221
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2222
arcSin
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2223
    "return the arcsine of myself (I am interpreted as radians).
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2224
     Raises an exception, if the receiver is not in -1..1"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2225
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2226
%{  /* NOCONTEXT */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2227
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2228
    double val, rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2229
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2230
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2231
    val = __floatVal(self);
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2232
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2233
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2234
    if ((val >= -1.0) && (val <= 1.0))
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2235
#endif
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2236
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2237
	__threadErrno = 0;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2238
	rslt = asin(val);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2239
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2240
	{
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2241
	    if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2242
		__qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2243
		RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2244
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2245
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2246
    }
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2247
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2248
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2249
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2250
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2251
	selector:#arcSin
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2252
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2253
	errorString:'bad receiver in arcSin'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2254
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2255
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2256
     -10 arcSin
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2257
     1 arcSin
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2258
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2259
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2260
    "Modified: / 16.11.2001 / 14:14:18 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2261
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2262
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2263
arcSinh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2264
    "return the hyperbolic arcsine of the receiver."
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2265
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2266
    |useFallBack|
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2267
%{
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2268
#ifdef NO_ASINH
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2269
    useFallBack = true;
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2270
#else
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2271
    double val, rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2272
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2273
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2274
    val = __floatVal(self);
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2275
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2276
# ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2277
    if (val >= 1.0)
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2278
# endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2279
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2280
	__threadErrno = 0;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2281
	rslt = asinh(val);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2282
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2283
	{
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2284
	    if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2285
		__qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2286
		RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2287
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2288
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2289
    }
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2290
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2291
%}.
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2292
    useFallBack notNil ifTrue:[
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2293
	^ super arcSinh
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2294
    ].
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2295
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2296
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2297
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2298
	selector:#arcSinh
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2299
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2300
	errorString:'bad receiver in arcSinh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2301
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2302
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2303
     -10.0 arcSinh
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2304
     1.0 arcSinh
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2305
    "
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2306
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2307
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2308
arcTan
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2309
    "return the arctangent of the receiver (as radians)"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2310
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2311
%{  /* NOCONTEXT */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2312
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2313
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2314
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2315
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2316
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2317
    rslt = atan(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2318
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2319
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2320
	if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2321
	    __qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2322
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2323
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2324
    }
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2325
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2326
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2327
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2328
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2329
	selector:#arcTan
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2330
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2331
	errorString:'bad receiver in arcTan'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2332
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2333
    "Modified: / 16.11.2001 / 14:14:22 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2334
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2335
11487
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2336
arcTan2:x
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2337
    "return the atan2(self,x)"
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2338
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2339
%{  /* NOCONTEXT */
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2340
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2341
    double rslt;
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2342
    OBJ newFloat;
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2343
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2344
    if (__isFloat(x)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2345
	__threadErrno = 0;
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2346
	rslt = atan2(__floatVal(self),__floatVal(x));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2347
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2348
	{
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2349
	    if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2350
		__qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2351
		RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2352
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2353
	}
11487
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2354
    }
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2355
%}.
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2356
    x isFloat ifFalse:[
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2357
	^ self arcTan2:(x asFloat).
11487
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2358
    ].
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2359
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2360
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2361
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2362
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2363
	selector:#arcTan2:
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2364
	arguments:(Array with:x)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2365
	errorString:'bad receiver in arcTan2:'
11487
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2366
!
9195c17baa9e +arcTan2:
Claus Gittinger <cg@exept.de>
parents: 10604
diff changeset
  2367
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  2368
arcTan: denominator
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2369
    (self = 0.0) ifTrue: [
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2370
	(denominator > 0.0)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2371
	    ifTrue: [ ^ 0 ]
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2372
	    ifFalse: [ ^ Pi ]
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  2373
    ].
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2374
    (denominator = 0.0) ifTrue: [
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2375
	(self > 0.0)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2376
	    ifTrue: [ ^ Halfpi ]
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2377
	    ifFalse: [ ^ HalfpiNegative ]
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  2378
    ].
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2379
    (denominator > 0)
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2380
	ifTrue: [ ^ (self / denominator) arcTan ]
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2381
	ifFalse: [ ^ ((self / denominator) arcTan) + Pi ]
10604
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  2382
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  2383
    "Created: / 07-06-2007 / 21:10:32 / cg"
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  2384
    "Modified: / 11-06-2007 / 12:58:34 / cg"
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  2385
!
2a9b9a20067a more constants
Claus Gittinger <cg@exept.de>
parents: 9651
diff changeset
  2386
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2387
arcTanh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2388
    "return the hyperbolic arctangent of the receiver."
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2389
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2390
    |useFallBack|
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2391
%{
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2392
#ifdef NO_ATANH
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2393
    useFallBack = true;
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2394
#else
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2395
    double val, rslt;
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2396
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2397
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2398
    __threadErrno = 0;
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2399
    val = __floatVal(self);
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2400
# ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2401
    if ((val >= -1.0) && (val <= 1.0))
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2402
# endif
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2403
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2404
	rslt = atanh(__floatVal(self));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2405
	if (! isnan(rslt))  /* Currently all our systems support isnan() */
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2406
	{
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2407
	    if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2408
		__qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2409
		RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2410
	    }
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2411
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2412
    }
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2413
#endif
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2414
%}.
7410
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2415
    useFallBack notNil ifTrue:[
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2416
	^ super arcTanh
ba285982489a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7409
diff changeset
  2417
    ].
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2418
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2419
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2420
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2421
	selector:#arcTanh
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2422
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2423
	errorString:'bad receiver in arcTanh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2424
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2425
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2426
cos
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2427
    "return the cosine of the receiver (interpreted as radians)"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2428
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2429
%{  /* NOCONTEXT */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2430
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2431
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2432
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2433
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2434
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2435
    rslt = cos(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2436
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2437
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2438
	if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2439
	    __qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2440
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2441
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2442
    }
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2443
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2444
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2445
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2446
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2447
	selector:#cos
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2448
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2449
	errorString:'bad receiver in cos'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2450
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2451
    "Modified: / 16.11.2001 / 14:14:26 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2452
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2453
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2454
cosh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2455
    "return the hyperbolic cosine of the receiver"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2456
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2457
%{  /* NOCONTEXT */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2458
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2459
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2460
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2461
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2462
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2463
    rslt = cosh(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2464
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2465
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2466
	if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2467
	    __qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2468
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2469
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2470
    }
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2471
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2472
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2473
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2474
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2475
	selector:#cosh
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2476
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2477
	errorString:'bad receiver in cosh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2478
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2479
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2480
sin
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2481
    "return the sine of the receiver (interpreted as radians)"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2482
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2483
%{  /* NOCONTEXT */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2484
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2485
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2486
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2487
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2488
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2489
    rslt = sin(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2490
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2491
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2492
	if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2493
	    __qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2494
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2495
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2496
    }
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2497
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2498
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2499
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2500
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2501
	selector:#sin
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2502
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2503
	errorString:'bad receiver in sin'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2504
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2505
    "Modified: / 16.11.2001 / 14:14:37 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2506
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2507
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2508
sinh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2509
    "return the hyperbolic sine of the receiver"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2510
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2511
%{  /* NOCONTEXT */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2512
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2513
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2514
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2515
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2516
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2517
    rslt = sinh(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2518
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2519
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2520
	if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2521
	    __qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2522
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2523
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2524
    }
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2525
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2526
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2527
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2528
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2529
	selector:#sinh
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2530
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2531
	errorString:'bad receiver in sinh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2532
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2533
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2534
tan
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2535
    "return the tangens of the receiver (interpreted as radians)"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2536
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2537
%{  /* NOCONTEXT */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2538
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2539
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2540
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2541
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2542
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2543
    rslt = tan(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2544
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2545
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2546
	if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2547
	    __qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2548
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2549
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2550
    }
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2551
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2552
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2553
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2554
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2555
	selector:#tan
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2556
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2557
	errorString:'bad receiver in tan'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2558
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2559
    "Modified: / 16.11.2001 / 14:14:49 / cg"
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2560
!
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2561
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2562
tanh
7391
55ca5a24162a added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents: 7385
diff changeset
  2563
    "return the hyperbolic tangens of the receiver"
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2564
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2565
%{  /* NOCONTEXT */
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2566
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2567
    double rslt;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2568
    OBJ newFloat;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2569
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2570
    __threadErrno = 0;
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2571
    rslt = tanh(__floatVal(self));
7393
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2572
    if (! isnan(rslt))  /* Currently all our systems support isnan() */
23344038fa0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7391
diff changeset
  2573
    {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2574
	if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2575
	    __qMKFLOAT(newFloat, rslt);
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2576
	    RETURN ( newFloat );
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2577
	}
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2578
    }
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2579
%}.
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2580
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2581
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2582
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2583
	selector:#tanh
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2584
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2585
	errorString:'bad receiver in tanh'
7385
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2586
! !
852e84340d2b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7381
diff changeset
  2587
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5436
diff changeset
  2588
!Float methodsFor:'truncation & rounding'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2589
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2590
ceiling
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2591
    "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
  2592
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2593
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2594
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2595
%{
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2596
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2597
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2598
    dVal = ceil(__floatVal(self));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2599
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2600
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2601
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2602
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2603
	RETURN ( __mkSmallInteger( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2604
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2605
    __qMKFLOAT(val, dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2606
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2607
    ^ val asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2608
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2609
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2610
ceilingAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2611
    "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
  2612
     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
  2613
     of the result to an integer.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2614
     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
  2615
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2616
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2617
    double dVal;
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2618
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2619
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2620
    dVal = ceil(__floatVal(self));
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2621
    __qMKFLOAT(v, dVal);
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2622
    RETURN (v);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2623
%}
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2624
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2625
     0.5 ceilingAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2626
     -0.5 ceilingAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2627
     -1.5 ceilingAsFloat
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2628
    "
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2629
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2630
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2631
floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2632
    "return the integer nearest the receiver towards negative infinity."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2633
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2634
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2635
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2636
%{
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2637
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2638
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2639
    dVal = floor(__floatVal(self));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2640
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2641
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2642
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2643
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2644
	RETURN ( __mkSmallInteger( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2645
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2646
    __qMKFLOAT(val, dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2647
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2648
    ^ val asInteger
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2649
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2650
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2651
     0.5 floor
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2652
     0.5 floorAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2653
     -0.5 floor
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2654
     -0.5 floorAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2655
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2656
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2657
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2658
floorAsFloat
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2659
    "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
  2660
     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
  2661
     of the result to an integer.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2662
     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
  2663
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2664
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2665
    double dVal;
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2666
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2667
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2668
    dVal = floor(__floatVal(self));
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2669
    __qMKFLOAT(v, dVal);
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2670
    RETURN (v);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2671
%}
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2672
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2673
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2674
     0.5 floor
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2675
     0.5 floorAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2676
     -0.5 floor
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2677
     -0.5 floorAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2678
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2679
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2680
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2681
fractionPart
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2682
    "extract the after-decimal fraction part.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2683
     such that (self truncated + self fractionPart) = self"
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2684
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2685
%{  /* NOCONTEXT */
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2686
14728
b947522816a7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 14720
diff changeset
  2687
    double modf(double, double*);
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2688
    double frac, trunc;
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2689
5120
13143fbcbdf8 introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents: 4825
diff changeset
  2690
    __threadErrno = 0;
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2691
    frac = modf(__floatVal(self), &trunc);
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2692
    if (! isnan(frac)) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2693
	if (__threadErrno == 0) {
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2694
	    RETURN (__MKFLOAT(frac));
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2695
	}
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2696
    }
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2697
%}.
7403
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  2698
    ^ self class
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2699
	raise:#domainErrorSignal
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2700
	receiver:self
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2701
	selector:#fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2702
	arguments:#()
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2703
	errorString:'bad receiver in fractionPart'
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2704
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2705
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2706
     1.6 fractionPart + 1.6 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2707
     -1.6 fractionPart + -1.6 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2708
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2709
     1.0 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2710
     2.0 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2711
     3.0 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2712
     4.0 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2713
     0.5 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2714
     0.25 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2715
     3.14159 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2716
     12345673.14159 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2717
     123456731231231231.14159 fractionPart
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2718
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2719
     3.14159 fractionPart + 3.14159 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2720
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2721
     12345673.14159 fractionPart + 12345673.14159 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2722
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2723
     123456731231231231.14159 fractionPart + 123456731231231231.14159 truncated
3896
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2724
    "
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2725
!
ff8ef5f6f3e9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3894
diff changeset
  2726
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2727
rounded
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2728
    "return the receiver rounded to the nearest integer"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2729
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2730
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2731
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2732
%{
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2733
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2734
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2735
    dVal = __floatVal(self);
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2736
    if (dVal < 0.0) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2737
	dVal = ceil(dVal - 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2738
    } else {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2739
	dVal = floor(dVal + 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2740
    }
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2741
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2742
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2743
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2744
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2745
	RETURN ( __mkSmallInteger( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2746
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2747
    __qMKFLOAT(val, dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2748
%}.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  2749
    ^ val asInteger
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2750
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2751
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2752
     0.4 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2753
     0.5 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2754
     0.6 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2755
     -0.4 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2756
     -0.5 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2757
     -0.6 rounded
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2758
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2759
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2760
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2761
roundedAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2762
    "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
  2763
     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
  2764
     of the result to an integer.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2765
     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
  2766
     float-operation."
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2767
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2768
    |val|
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2769
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2770
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2771
    double dVal;
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2772
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2773
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2774
    dVal = __floatVal(self);
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2775
    if (dVal < 0.0) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2776
	dVal = ceil(dVal - 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2777
    } else {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2778
	dVal = floor(dVal + 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2779
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2780
    __qMKFLOAT(v, dVal);
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2781
    RETURN (v);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2782
%}
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2783
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2784
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2785
     0.5 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2786
     -0.5 rounded
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2787
     0.5 roundedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2788
     -0.5 roundedAsFloat
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2789
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2790
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2791
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2792
truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2793
    "return the receiver truncated towards zero as an integer"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2794
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2795
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2796
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2797
%{
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2798
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2799
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  2800
    dVal = __floatVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2801
    if (dVal < 0.0) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2802
	dVal = ceil(dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2803
    } else {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2804
	dVal = floor(dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2805
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2806
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2807
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2808
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2809
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2810
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2811
	RETURN ( __mkSmallInteger( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2812
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2813
    __qMKFLOAT(val, dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2814
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2815
    ^ val asInteger
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2816
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2817
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2818
     0.5 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2819
     -0.5 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2820
     0.5 truncatedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2821
     -0.5 truncatedAsFloat
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2822
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2823
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2824
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2825
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2826
truncatedAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2827
    "return the receiver truncated towards zero as a float.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2828
     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
  2829
     of the result to an integer.
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2830
     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
  2831
     float-operation."
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2832
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2833
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2834
    double dVal;
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2835
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2836
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2837
    dVal = __floatVal(self);
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2838
    if (dVal < 0.0) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2839
	dVal = ceil(dVal);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2840
    } else {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  2841
	dVal = floor(dVal);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2842
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2843
    __qMKFLOAT(v, dVal);
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  2844
    RETURN (v);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2845
%}
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2846
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2847
    "
11945
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2848
     0.5 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2849
     -0.5 truncated
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2850
     0.5 truncatedAsFloat
8697e2333da3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11926
diff changeset
  2851
     -0.5 truncatedAsFloat
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2852
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2853
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2854
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2855
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  2856
!Float class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2857
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2858
version
14728
b947522816a7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 14720
diff changeset
  2859
    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.186 2013-01-29 12:27:45 cg Exp $'
12423
a3c777accbb0 changed: #exponent
Claus Gittinger <cg@exept.de>
parents: 11945
diff changeset
  2860
!
a3c777accbb0 changed: #exponent
Claus Gittinger <cg@exept.de>
parents: 11945
diff changeset
  2861
a3c777accbb0 changed: #exponent
Claus Gittinger <cg@exept.de>
parents: 11945
diff changeset
  2862
version_CVS
14728
b947522816a7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 14720
diff changeset
  2863
    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.186 2013-01-29 12:27:45 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  2864
! !
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6674
diff changeset
  2865
14599
3c1e4683d2f6 class: Float
Stefan Vogel <sv@exept.de>
parents: 14298
diff changeset
  2866
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  2867
Float initialize!