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