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