Float.st
author Claus Gittinger <cg@exept.de>
Mon, 12 Jan 1998 14:23:21 +0100
changeset 3165 b6bde90005a8
parent 3163 212a539ee379
child 3194 16073834a825
permissions -rw-r--r--
also try package-subdir of source-dir for classes source
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
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 47
diff changeset
    13
LimitedPrecisionReal variableByteSubclass:#Float
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    14
	instanceVariableNames:''
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
    15
	classVariableNames:'DefaultPrintFormat'
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    16
	poolDictionaries:''
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    20
!Float primitiveDefinitions!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    21
%{
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    22
#include <errno.h>
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    23
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    24
#ifndef __OPTIMIZE__
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    25
# define __OPTIMIZE__
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    26
#endif
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    27
#include <math.h>
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
    28
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    29
/*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    30
 * on some systems errno is a macro ... check for it here
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    31
 */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    32
#ifndef errno
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    33
 extern errno;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    34
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    35
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    36
#if defined (_AIX)
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    37
# include <float.h>
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    38
#endif
2395
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    39
#if defined(IRIX)
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    40
# include <nan.h>
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
    41
#endif
2397
dd6979979e67 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2396
diff changeset
    42
#if defined(LINUX)
2396
646ea118eaf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2395
diff changeset
    43
# include <nan.h>
646ea118eaf8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2395
diff changeset
    44
#endif
2399
5d47ec6834a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
    45
#if defined(solaris) || defined(sunos)
2398
652c9f2a13fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2397
diff changeset
    46
# include <nan.h>
652c9f2a13fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2397
diff changeset
    47
#endif
2394
475f415ad893 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2393
diff changeset
    48
3129
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    49
/*
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    50
 * sigh - some systems define that stuff; others dont.
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    51
 * (AIX even declares them as macros, so an external decl
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    52
 *  will not work below ...
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    53
 */
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    54
#if !defined(_AIX)
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    55
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    56
# ifdef acos
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    57
  double acos();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    58
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    59
# ifdef asin
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    60
  double asin();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    61
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    62
# ifndef atan
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    63
  double atan();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    64
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    65
# ifndef cos
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    66
  double cos();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    67
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    68
# ifndef sin
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    69
  double sin();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    70
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    71
# ifndef pow
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    72
  double pow();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    73
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    74
# ifndef log
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    75
  double log();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    76
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    77
# ifndef exp
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    78
  double exp();
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    79
# endif
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    80
# ifndef sqrt
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    81
  double sqrt();
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
# ifndef tan
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    84
  double tan();
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
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    87
#endif /* not AIX */
d38fc293dbf9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3128
diff changeset
    88
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    89
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    90
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
    91
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
    92
!Float class methodsFor:'documentation'!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
    93
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    94
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    95
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    96
 COPYRIGHT (c) 1988 by Claus Gittinger
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
    97
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    98
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    99
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   100
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   101
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   102
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   103
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   104
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   105
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   106
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   107
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   108
documentation
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   109
"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   110
    Floats represent rational numbers with limited precision. In ST/X, Float uses
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   111
    the underlying C-compilers double implementation, therefore instances of Float
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   112
    are usually represented by the 8-byte IEEE double precision float format.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   113
    (but there is no guaranty).
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   114
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   115
    Notice, that Floats are defined as Byte-array to prevent the garbage collector
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   116
    from going into the value ... otherwise I needed a special case in many places.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   117
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   118
    Also notice, that ST/X Floats are what Doubles are in ST-80 - this may change 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   119
    in one of the next versions (at least on machines, which provide different float
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   120
    and double types in their C-compiler.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   121
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   122
    WARNING:
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   123
    The layout of float instances is known by the runtime system and the compiler;
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   124
    you may not add instance variables here. 
369
claus
parents: 343
diff changeset
   125
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   126
    Also, subclassing is complicated by the fact, that the VM creates floats as results
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   127
    of arithmetic operations (even if the operands are subclass-instances).
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   128
    (It does the float-check by probing a bit in the classes flag instVar).
85
claus
parents: 77
diff changeset
   129
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1879
diff changeset
   130
    Mixed mode arithmetic:
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   131
        float op float       -> float
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   132
        float op fix         -> float
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   133
        float op integer     -> float
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   134
        float op float       -> float
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1879
diff changeset
   135
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   136
    [Class Variables:]
85
claus
parents: 77
diff changeset
   137
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   138
    [see also:]
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   139
        Number
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   140
        ShortFloat Fraction FixedPoint Integer
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   141
        FloatArray DoubleArray
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   142
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
   143
    [author:]
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   144
        Claus Gittinger
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   145
"
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   146
!
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   147
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   148
errorHandling
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   149
"
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   150
    Floating point error handling and signalling depends on the systems
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   151
    (actually: the C-runtime systems) ability to handle floating point errors.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   152
    Most systems report errors by raising an OS floatingPoint exception,
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   153
    which is mapped to a fpExceptionInterrupt in ST/X.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   154
    However, some systems do return NaN as result.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   155
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   156
    Currently, ST/X does not care specially for these systems - it maybe added 
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   157
    easily, if there is sufficient customer interest, though.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   158
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   159
    Try:
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   160
	|f1 f2|
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   161
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   162
	f1 := 1.0.
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   163
	f2 := 0.0.
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   164
	f1 / f2
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   165
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   166
    or:
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   167
	2 arcSin
2215
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   168
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   169
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   170
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   171
!Float class methodsFor:'initialization'!
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   172
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   173
initialize
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   174
    DefaultPrintFormat := '.6'  "/ 6 valid digits
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   175
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   176
    "
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   177
     DefaultPrintFormat := '.9' 
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   178
     DefaultPrintFormat := '.6' 
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   179
    "
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   180
! !
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
   181
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   182
!Float class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   183
a27a279701f8 Initial revision
claus
parents:
diff changeset
   184
basicNew
a27a279701f8 Initial revision
claus
parents:
diff changeset
   185
    "return a new float - here we return 0.0
a27a279701f8 Initial revision
claus
parents:
diff changeset
   186
     - floats are usually NOT created this way ...
a27a279701f8 Initial revision
claus
parents:
diff changeset
   187
     Its implemented here to allow things like binary store & load
a27a279701f8 Initial revision
claus
parents:
diff changeset
   188
     of floats. (but even this support will go away eventually, its not
a27a279701f8 Initial revision
claus
parents:
diff changeset
   189
     a good idea to store the bits of a float - the reader might have a
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   190
     totally different representation - so floats will eventually be 
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   191
     binary stored in a device independent format."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   192
a27a279701f8 Initial revision
claus
parents:
diff changeset
   193
%{  /* NOCONTEXT */
1206
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   194
    OBJ newFloat;
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   195
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   196
    __qMKFLOAT(newFloat, 0.0);
1206
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   197
    RETURN (newFloat);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   198
%}
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   199
!
1206
9d23c1f5e4d3 use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   200
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   201
readFrom:aStringOrStream onError:exceptionBlock
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   202
    "read a float from a string"
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   203
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   204
    |num|
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   205
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   206
    num := super readFrom:aStringOrStream onError:nil.
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   207
    num isNil ifTrue:[  
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   208
	^ exceptionBlock value
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   209
    ].
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   210
    ^ num asFloat
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   211
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   212
    "
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   213
     Float readFrom:'0.1'
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   214
     Float readFrom:'0'
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   215
    "
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   216
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   217
    "Created: / 7.1.1998 / 16:17:19 / cg"
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   218
    "Modified: / 7.1.1998 / 16:18:33 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   219
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   220
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   221
!Float class methodsFor:'binary storage'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   222
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   223
binaryDefinitionFrom:aStream manager: manager
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   224
    |f|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   225
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   226
    f := self basicNew.
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   227
    self readBinaryIEEEDoubleFrom:aStream into:f.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   228
    ^ f
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   229
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   230
    "Modified: 16.4.1996 / 21:23:38 / cg"
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   231
!
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   232
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   233
readBinaryIEEEDoubleFrom:aStream
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   234
    "read a float from the binary stream, aStream,
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   235
     interpreting the next bytes as an IEEE formatted 8-byte float"
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   236
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   237
    |f|
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   238
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   239
    f := self basicNew.
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   240
    self readBinaryIEEEDoubleFrom:aStream into:f.
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   241
    ^ f
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   242
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   243
    "Created: 16.4.1996 / 20:59:59 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   244
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   245
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   246
readBinaryIEEEDoubleFrom:aStream into:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   247
    "read the receivers value from the binary stream, aStream,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   248
     interpreting the next bytes as an IEEE formatted 8-byte float"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   249
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   250
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   251
     this implementation is wrong: does not work on non-IEEE machines
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   252
     (to date all machines where ST/X is running on use
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   253
      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
   254
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   255
    UninterpretedBytes isBigEndian ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   256
	"swap the bytes"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   257
	8 to:1 by:-1 do:[:i |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   258
	    aFloat basicAt:i put:(aStream next)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   259
	].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   260
	^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   261
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   262
    1 to:8 do:[:i |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   263
	aFloat basicAt:i put:aStream next
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   264
    ]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   265
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   266
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   267
readBinaryIEEESingleFrom:aStream
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   268
    "read a float value from the binary stream, aStream,
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   269
     interpreting the next bytes as an IEEE formatted 4-byte float"
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   270
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   271
    |f|
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   272
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   273
    f := self basicNew.
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   274
    self readBinaryIEEESingleFrom:aStream into:f.
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   275
    ^ f
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   276
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   277
    "Created: 16.4.1996 / 21:00:35 / cg"
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   278
!
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   279
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   280
readBinaryIEEESingleFrom:aStream into:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   281
    "read a float value from the binary stream, aStream,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   282
     interpreting the next bytes as an IEEE formatted 4-byte float"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   283
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   284
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   285
     this implementation is wrong: does not work on non-IEEE machines
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   286
     (to date all machines where ST/X is running on use
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   287
      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
   288
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   289
    UninterpretedBytes isBigEndian ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   290
	"swap the bytes"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   291
	8 to:4 by:-1 do:[:i |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   292
	    aFloat basicAt:i put:(aStream next)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   293
	].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   294
	^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   295
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   296
    1 to:4 do:[:i |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   297
	aFloat basicAt:i put:aStream next
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   298
    ]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   299
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   300
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   301
storeBinaryIEEEDouble:aFloat on:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   302
    "store aFloat as an IEEE formatted 8-byte float
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   303
     onto the binary stream, aStream"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   304
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   305
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   306
     this implementation is wrong: does not work on non-IEEE machines
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   307
     (to date all machines where ST/X is running on use
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   308
      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
   309
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   310
    UninterpretedBytes isBigEndian ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   311
	"swap the bytes"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   312
	8 to:1 by:-1 do:[:i |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   313
	    aStream nextPut:(aFloat basicAt:i).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   314
	].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   315
	^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   316
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   317
    1 to:8 do:[:i |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   318
	aStream nextPut:(aFloat basicAt:i).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   319
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   320
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   321
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   322
storeBinaryIEEESingle:aFloat on:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   323
    "store aFloat as an IEEE formatted 4-byte float
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   324
     onto the binary stream, aStream"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   325
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   326
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   327
     this implementation is wrong: does not work on non-IEEE machines
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   328
     (to date all machines where ST/X is running on use
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   329
      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
   330
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   331
    UninterpretedBytes isBigEndian ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   332
	"swap the bytes"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   333
	8 to:4 by:-1 do:[:i |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   334
	    aStream nextPut:(aFloat basicAt:i).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   335
	].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   336
	^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   337
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   338
    1 to:4 do:[:i |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   339
	aStream nextPut:(aFloat basicAt:i).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   340
    ]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   341
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   342
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   343
!Float class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   344
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   345
pi
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   346
    "return the constant pi as Float"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   347
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   348
    ^ 3.1415926535897932384626434
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   349
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   350
    "Modified: 23.4.1996 / 09:27:02 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   351
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   352
a27a279701f8 Initial revision
claus
parents:
diff changeset
   353
unity
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   354
    "return the neutral element for multiplication (1.0) as Float"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   355
a27a279701f8 Initial revision
claus
parents:
diff changeset
   356
    ^ 1.0
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   357
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   358
    "Modified: 23.4.1996 / 09:27:09 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   359
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   360
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   361
zero
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   362
    "return the neutral element for addition (0.0) as Float"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   363
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   364
    ^ 0.0
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   365
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   366
    "Modified: 23.4.1996 / 09:27:15 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   367
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   368
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   369
!Float class methodsFor:'queries'!
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   370
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   371
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   372
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   373
     Here, true is returned for myself, false for subclasses."
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   374
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   375
    ^ self == Float
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   376
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1260
diff changeset
   377
    "Modified: 23.4.1996 / 15:59:04 / cg"
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   378
! !
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   379
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   380
!Float methodsFor:'arithmetic'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   381
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   382
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   383
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   384
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   385
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   386
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   387
    OBJ newFloat;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   388
    double result;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   389
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   390
    if (__isSmallInteger(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   391
	result = __floatVal(self) * (double)(__intVal(aNumber));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   392
retResult:
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   393
	__qMKFLOAT(newFloat, result);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   394
	RETURN ( newFloat );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   395
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   396
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   397
	result = __floatVal(self) * __floatVal(aNumber);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   398
	goto retResult;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   399
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   400
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   401
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   402
    ^ aNumber productFromFloat:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   403
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   404
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   405
+ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   406
    "return the sum of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   407
a27a279701f8 Initial revision
claus
parents:
diff changeset
   408
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   409
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   410
    OBJ newFloat;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   411
    double result;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   412
250
a5deb61ffdac *** empty log message ***
claus
parents: 224
diff changeset
   413
    if (__isSmallInteger(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   414
	result = __floatVal(self) + (double)(__intVal(aNumber));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   415
retResult:
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   416
	__qMKFLOAT(newFloat, result);
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   417
	RETURN ( newFloat );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   418
    }
283
a897d331b4c1 *** empty log message ***
claus
parents: 258
diff changeset
   419
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   420
	result = __floatVal(self) + __floatVal(aNumber);
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   421
	goto retResult;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   422
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   423
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   424
.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   425
    ^ aNumber sumFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   426
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   427
a27a279701f8 Initial revision
claus
parents:
diff changeset
   428
- aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   429
    "return the difference of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   430
a27a279701f8 Initial revision
claus
parents:
diff changeset
   431
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   432
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   433
    OBJ newFloat;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   434
    double result;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   435
250
a5deb61ffdac *** empty log message ***
claus
parents: 224
diff changeset
   436
    if (__isSmallInteger(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   437
	result = __floatVal(self) - (double)(__intVal(aNumber));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   438
retResult:
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   439
	__qMKFLOAT(newFloat, result);
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   440
	RETURN ( newFloat );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   441
    }
283
a897d331b4c1 *** empty log message ***
claus
parents: 258
diff changeset
   442
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   443
	result = __floatVal(self) - __floatVal(aNumber);
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   444
	goto retResult;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   445
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   446
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   447
.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   448
    ^ aNumber differenceFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   449
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   450
a27a279701f8 Initial revision
claus
parents:
diff changeset
   451
/ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   452
    "return the quotient of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   453
a27a279701f8 Initial revision
claus
parents:
diff changeset
   454
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   455
a27a279701f8 Initial revision
claus
parents:
diff changeset
   456
    OBJ newFloat;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   457
    double result, val;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   458
250
a5deb61ffdac *** empty log message ***
claus
parents: 224
diff changeset
   459
    if (__isSmallInteger(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   460
	if (aNumber != __MKSMALLINT(0)) {
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   461
	    result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   462
retResult:
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   463
	    __qMKFLOAT(newFloat, result);
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   464
	    RETURN ( newFloat );
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   465
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   466
    } else {
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
   467
	if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   468
	    val = __floatVal(aNumber);
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   469
	    if (val != 0.0) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   470
		result = __floatVal(self) / val;
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   471
		goto retResult;
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   472
	    }
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   473
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   474
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   475
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   476
.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   477
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
142
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
   478
	"
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
   479
	 No, you shalt not divide by zero
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
   480
	"
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   481
	^ DivisionByZeroSignal raise.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   482
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   483
    ^ aNumber quotientFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   484
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   485
a27a279701f8 Initial revision
claus
parents:
diff changeset
   486
negated
a27a279701f8 Initial revision
claus
parents:
diff changeset
   487
    "return myself negated"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   488
a27a279701f8 Initial revision
claus
parents:
diff changeset
   489
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   490
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   491
    OBJ newFloat;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   492
    double rslt = - __floatVal(self);
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   493
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   494
    __qMKFLOAT(newFloat, rslt);
3
24d81bf47225 *** empty log message ***
claus
parents: 1
diff changeset
   495
    RETURN ( newFloat );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   496
%}
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   497
!
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   498
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   499
uncheckedDivide:aNumber
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   500
    "return the quotient of the receiver and the argument, aNumber.
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   501
     Do not check for divide by zero (return NaN or infinity)"
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   502
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   503
%{  /* NOCONTEXT */
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   504
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   505
    OBJ newFloat;
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   506
    double result, val;
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   507
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   508
    if (__isSmallInteger(aNumber)) {
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   509
        result = __floatVal(self) / ( (double)__intVal(aNumber)) ;
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   510
retResult:
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   511
        __qMKFLOAT(newFloat, result);
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   512
        RETURN ( newFloat );
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   513
    } else if (__isFloatLike(aNumber)) {
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   514
        val = __floatVal(aNumber);
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   515
        result = __floatVal(self) / val;
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   516
        goto retResult;
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   517
    }
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   518
%}
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   519
.
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   520
    ^ aNumber quotientFromFloat:self
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   521
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   522
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   523
    "
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   524
      0.0 uncheckedDivide:0.0
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   525
      1.0 uncheckedDivide:0.0
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   526
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   527
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   528
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   529
!Float methodsFor:'binary storage'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   530
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   531
storeBinaryDefinitionOn:stream manager:manager
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   532
    "store the receiver in a binary format on stream.
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   533
     This is an internal interface for binary storage mechanism."
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   534
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   535
    manager putIdOfClass:(self class) on:stream.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   536
    Float storeBinaryIEEEDouble:self on:stream.
1260
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   537
2a8ba44e8957 commentary
Claus Gittinger <cg@exept.de>
parents: 1206
diff changeset
   538
    "Modified: 23.4.1996 / 09:29:48 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   539
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   540
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   541
!Float methodsFor:'coercion and converting'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   542
3014
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
   543
asDouble
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
   544
    "ST80 compatibility: return a float with same value - thats me"
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
   545
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
   546
    ^ self
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
   547
!
9934bb63d455 added #asDouble
ca
parents: 2892
diff changeset
   548
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   549
asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   550
    "return a float with same value - thats me"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   551
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   552
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   553
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   554
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   555
asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   556
    "return an integer with same value - might truncate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   557
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   558
%{  /* NOCONTEXT */
1670
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   559
    double dVal;
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   560
1670
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   561
    dVal = __floatVal(self);
55cde0b3ee8e slightly faster asInteger
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   562
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
   563
	RETURN ( __MKSMALLINT( (INT)dVal) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   564
    }
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   565
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   566
    ^ super asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   567
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   568
    "12345.0 asInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   569
    "1e15 asInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   570
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   571
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   572
asShortFloat
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   573
    "return a shortFloat with same value as receiver"
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   574
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   575
%{  /* NOCONTEXT */
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   576
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   577
    OBJ dummy = @global(ShortFloat);
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   578
    OBJ newFloat;
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   579
    float fVal = (float)__floatVal(self);
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   580
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   581
    __qMKSFLOAT(newFloat, fVal);
1198
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   582
    RETURN ( newFloat );
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   583
%}
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   584
!
284eeba6b719 docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   585
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   586
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   587
    "return aNumber converted into receivers type"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   588
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   589
    ^ aNumber asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   590
!
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   591
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   592
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   593
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   594
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   595
    ^ 80
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   596
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   597
a27a279701f8 Initial revision
claus
parents:
diff changeset
   598
!Float methodsFor:'comparing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   599
a27a279701f8 Initial revision
claus
parents:
diff changeset
   600
< aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   601
    "return true, if the argument is greater"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   602
a27a279701f8 Initial revision
claus
parents:
diff changeset
   603
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   604
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   605
    if (aNumber != nil) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   606
	if (__isSmallInteger(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   607
	    RETURN ( (__floatVal(self) < (double)(__intVal(aNumber))) ? true : false );
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   608
	}
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   609
	if (__qIsFloatLike(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   610
	    RETURN ( (__floatVal(self) < __floatVal(aNumber)) ? true : false );
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   611
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   612
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   613
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   614
    ^ aNumber lessFromFloat:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   615
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   616
a27a279701f8 Initial revision
claus
parents:
diff changeset
   617
<= aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   618
    "return true, if the argument is greater or equal"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   619
a27a279701f8 Initial revision
claus
parents:
diff changeset
   620
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   621
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   622
    if (aNumber != nil) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   623
	if (__isSmallInteger(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   624
	    RETURN ( (__floatVal(self) <= (double)(__intVal(aNumber))) ? true : false );
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   625
	}
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   626
	if (__qIsFloatLike(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   627
	    RETURN ( (__floatVal(self) <= __floatVal(aNumber)) ? true : false );
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   628
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   629
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   630
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   631
    ^ self retry:#<= coercing:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   632
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   633
a27a279701f8 Initial revision
claus
parents:
diff changeset
   634
= aNumber
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   635
    "return true, if the arguments value are equal by value"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   636
a27a279701f8 Initial revision
claus
parents:
diff changeset
   637
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   638
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   639
    if (aNumber != nil) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   640
	if (__isSmallInteger(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   641
	    RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false );
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   642
	}
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   643
	if (__qIsFloatLike(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   644
	    RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false );
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   645
	}
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   646
    } else {
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   647
	RETURN (false);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   648
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   649
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   650
    ^ self retry:#= coercing:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   651
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   652
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   653
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   654
    "return true, if the argument is less"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   655
a27a279701f8 Initial revision
claus
parents:
diff changeset
   656
%{  /* NOCONTEXT */
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   657
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   658
    if (aNumber != nil) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   659
	if (__isSmallInteger(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   660
	    RETURN ( (__floatVal(self) > (double)(__intVal(aNumber))) ? true : false );
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   661
	}
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   662
	if (__qIsFloatLike(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   663
	    RETURN ( (__floatVal(self) > __floatVal(aNumber)) ? true : false );
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   664
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   665
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   666
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   667
    ^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   668
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   669
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   670
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   671
    "return true, if the argument is less or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   672
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   673
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   674
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   675
    if (aNumber != nil) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   676
	if (__isSmallInteger(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   677
	    RETURN ( (__floatVal(self) >= (double)(__intVal(aNumber))) ? true : false );
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   678
	}
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   679
	if (__qIsFloatLike(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   680
	    RETURN ( (__floatVal(self) >= __floatVal(aNumber)) ? true : false );
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   681
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   682
    }
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   683
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   684
    ^ self retry:#>= coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   685
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   686
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   687
hash
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   688
    "return a number for hashing; redefined, since floats compare
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   689
     by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   690
     as 3 hash."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   691
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
   692
    |i|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   693
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   694
    (self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   695
	i := self asInteger.
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   696
	self = i ifTrue:[
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   697
	    ^ i hash
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   698
	].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   699
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   700
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   701
    "
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
   702
     mhmh take some of my value-bits to hash on
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   703
    "
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
   704
    ^ (((self basicAt:8) bitAnd:16r3F) bitShift:24) +
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
   705
      ((self basicAt:7) bitShift:16) +
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
   706
      ((self basicAt:6) bitShift:8) +
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
   707
      (self basicAt:5)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   708
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   709
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   710
     3 hash       
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   711
     3.0 hash
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   712
     3.1 hash  
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   713
     3.14159 hash  
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   714
     31.4159 hash 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   715
     3.141591 hash 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   716
     1.234567890123456 hash  
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   717
     1.234567890123457 hash   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   718
     Set withAll:#(3 3.0 99 99.0 3.1415)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   719
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   720
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   721
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   722
~= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   723
    "return true, if the arguments value are not equal"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   724
a27a279701f8 Initial revision
claus
parents:
diff changeset
   725
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   726
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   727
    if (aNumber != nil) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   728
	if (__isSmallInteger(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   729
	    RETURN ( (__floatVal(self) != (double)(__intVal(aNumber))) ? true : false );
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   730
	}
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   731
	if (__qIsFloatLike(aNumber)) {
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   732
	    RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false );
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   733
	}
3115
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   734
    } else {
1ecfb9118163 dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents: 3014
diff changeset
   735
	RETURN (true);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   736
    }
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   737
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   738
    ^ self retry:#~= coercing:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   739
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   740
a27a279701f8 Initial revision
claus
parents:
diff changeset
   741
!Float methodsFor:'mathematical functions'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   742
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   743
arcCos
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   744
    "return the arccosine of myself as radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   745
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   746
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   747
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   748
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   749
    OBJ newFloat;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   750
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   751
    errno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   752
    rslt = acos(__floatVal(self));
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   753
    if (errno == 0) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   754
	__qMKFLOAT(newFloat, rslt);
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   755
	RETURN ( newFloat );
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   756
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   757
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   758
    ^ DomainErrorSignal raise
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   759
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   760
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   761
arcSin
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   762
    "return the arcsine of myself as radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   763
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   764
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   765
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   766
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   767
    OBJ newFloat;
701
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
    errno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   770
    rslt = asin(__floatVal(self));
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   771
    if (errno == 0) {
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   772
	__qMKFLOAT(newFloat, rslt);
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   773
	RETURN ( newFloat );
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   774
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   775
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   776
    ^ DomainErrorSignal raise
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   777
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   778
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   779
arcTan
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   780
    "return the arctangent of myself as radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   781
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   782
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   783
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   784
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   785
    OBJ newFloat;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   786
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   787
    errno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   788
    rslt = atan(__floatVal(self));
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   789
    if (errno == 0) {
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   790
	__qMKFLOAT(newFloat, rslt);
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   791
	RETURN ( newFloat );
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   792
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   793
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   794
    ^ DomainErrorSignal raise
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   795
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   796
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   797
cos
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   798
    "return the cosine of myself interpreted as radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   799
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   800
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   801
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   802
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   803
    OBJ newFloat;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   804
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   805
    errno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   806
    rslt = cos(__floatVal(self));
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   807
    if (errno == 0) {
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   808
	__qMKFLOAT(newFloat, rslt);
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   809
	RETURN ( newFloat );
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   810
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   811
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   812
    ^ DomainErrorSignal raise
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   813
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   814
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   815
exp
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   816
    "return e raised to the power of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   817
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   818
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   819
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   820
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   821
    OBJ newFloat;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   822
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   823
    errno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   824
    rslt = exp(__floatVal(self));
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   825
    if (errno == 0) {
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   826
	__qMKFLOAT(newFloat, rslt);
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   827
	RETURN ( newFloat );
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   828
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   829
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   830
    ^ DomainErrorSignal raise
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   831
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   832
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   833
ln
a27a279701f8 Initial revision
claus
parents:
diff changeset
   834
    "return the natural logarithm of myself"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   835
a27a279701f8 Initial revision
claus
parents:
diff changeset
   836
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   837
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   838
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   839
    OBJ newFloat;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   840
a27a279701f8 Initial revision
claus
parents:
diff changeset
   841
    errno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   842
    rslt = log(__floatVal(self));
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   843
    if (errno == 0) {
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   844
	__qMKFLOAT(newFloat, rslt);
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   845
	RETURN ( newFloat );
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   846
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   847
%}.
142
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
   848
    "
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
   849
     an invalid value for logarithm
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
   850
    "
131
39599c151f30 return value of signal raise
claus
parents: 92
diff changeset
   851
    ^ DomainErrorSignal raise
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   852
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   853
a27a279701f8 Initial revision
claus
parents:
diff changeset
   854
raisedTo:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   855
    "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
   856
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   857
    |n|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   858
a27a279701f8 Initial revision
claus
parents:
diff changeset
   859
    n := aNumber asFloat.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   860
%{
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   861
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   862
    OBJ newFloat;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   863
283
a897d331b4c1 *** empty log message ***
claus
parents: 258
diff changeset
   864
    if (__isFloatLike(n)) {
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   865
	errno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   866
	rslt = pow(__floatVal(self), __floatVal(n));
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   867
#if 0
175
82ba8d2e3569 *** empty log message ***
claus
parents: 142
diff changeset
   868
	errno = 0;  /* XXXX */
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   869
#endif
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   870
	if (errno == 0) {
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   871
	    __qMKFLOAT(newFloat, rslt);
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   872
	    RETURN ( newFloat );
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
   873
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   874
    }
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   875
%}.
142
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
   876
    "
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
   877
     an invalid argument (not convertable to float ?)
c7844287bddf *** empty log message ***
claus
parents: 131
diff changeset
   878
    "
131
39599c151f30 return value of signal raise
claus
parents: 92
diff changeset
   879
    ^ DomainErrorSignal raise
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   880
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   881
a27a279701f8 Initial revision
claus
parents:
diff changeset
   882
sin
a27a279701f8 Initial revision
claus
parents:
diff changeset
   883
    "return the sine of myself interpreted as radians"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   884
a27a279701f8 Initial revision
claus
parents:
diff changeset
   885
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   886
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   887
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   888
    OBJ newFloat;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   889
a27a279701f8 Initial revision
claus
parents:
diff changeset
   890
    errno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   891
    rslt = sin(__floatVal(self));
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   892
    if (errno == 0) {
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   893
	__qMKFLOAT(newFloat, rslt);
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   894
	RETURN ( newFloat );
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   895
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   896
%}.
131
39599c151f30 return value of signal raise
claus
parents: 92
diff changeset
   897
    ^ DomainErrorSignal raise
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   898
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   899
a27a279701f8 Initial revision
claus
parents:
diff changeset
   900
sqrt
a27a279701f8 Initial revision
claus
parents:
diff changeset
   901
    "return the square root of myself"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   902
a27a279701f8 Initial revision
claus
parents:
diff changeset
   903
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   904
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   905
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   906
    OBJ newFloat;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   907
a27a279701f8 Initial revision
claus
parents:
diff changeset
   908
    errno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   909
    rslt = sqrt(__floatVal(self));
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   910
    if (errno == 0) {
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   911
	__qMKFLOAT(newFloat, rslt);
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   912
	RETURN ( newFloat );
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   913
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   914
%}.
131
39599c151f30 return value of signal raise
claus
parents: 92
diff changeset
   915
    ^ DomainErrorSignal raise
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   916
!
258
cf85a4ec2795 basicAt:/basicAt:put:
claus
parents: 250
diff changeset
   917
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   918
tan
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   919
    "return the tangent of myself interpreted as radians"
258
cf85a4ec2795 basicAt:/basicAt:put:
claus
parents: 250
diff changeset
   920
cf85a4ec2795 basicAt:/basicAt:put:
claus
parents: 250
diff changeset
   921
%{  /* NOCONTEXT */
cf85a4ec2795 basicAt:/basicAt:put:
claus
parents: 250
diff changeset
   922
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   923
    double rslt;
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   924
    OBJ newFloat;
44
b262907c93ea *** empty log message ***
claus
parents: 41
diff changeset
   925
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   926
    errno = 0;
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   927
    rslt = tan(__floatVal(self));
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   928
    if (errno == 0) {
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   929
	__qMKFLOAT(newFloat, rslt);
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   930
	RETURN ( newFloat );
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   931
    }
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   932
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   933
    ^ DomainErrorSignal raise
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   934
! !
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   935
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   936
!Float methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   937
a27a279701f8 Initial revision
claus
parents:
diff changeset
   938
printString
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   939
    "return a printed representation of the receiver;
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   940
     if not specified otherwise (by setting DefaultPrintFormat),
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   941
     6 valid digits are printed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   942
a27a279701f8 Initial revision
claus
parents:
diff changeset
   943
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   944
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   945
    char buffer[64];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   946
    REGISTER char *cp;
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   947
    OBJ s;
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   948
    char *fmt;
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   949
    char fmtBuffer[20];
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   950
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   951
    if (__isString(@global(DefaultPrintFormat))) {
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   952
        fmt = (char *) __stringVal(@global(DefaultPrintFormat));
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   953
    } else {
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   954
        /*
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   955
         * in case we get called before #initialize ...
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   956
         */
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   957
        fmt = ".6";
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   958
    }
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   959
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   960
    /*
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   961
     * build a printf format string
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   962
     */
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   963
    fmtBuffer[0] = '%';
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   964
    strncpy(fmtBuffer+1, fmt, 10);
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   965
#ifdef SYSV
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   966
    strcat(fmtBuffer, "lg");
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   967
#else
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   968
    strcat(fmtBuffer, "G");
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   969
#endif
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   970
2358
6bdf2adfe9f5 defaultPrintFormat
Claus Gittinger <cg@exept.de>
parents: 2215
diff changeset
   971
    sprintf(buffer, fmtBuffer, __floatVal(self));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   972
a27a279701f8 Initial revision
claus
parents:
diff changeset
   973
    /* 
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
   974
     * kludge to make integral float f prints as "f.0" (not as "f" as printf does)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   975
     * (i.e. look if string contains '.' or 'e' and append '.0' if not)
a27a279701f8 Initial revision
claus
parents:
diff changeset
   976
     */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   977
    for (cp = buffer; *cp; cp++) {
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   978
        if ((*cp == '.') || (*cp == 'e')) break;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   979
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   980
    if (! *cp) {
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   981
        *cp++ = '.';
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   982
        *cp++ = '0';
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   983
        *cp = '\0';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   984
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   985
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
   986
    s = __MKSTRING(buffer COMMA_SND);
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   987
    if (s != nil) {
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
   988
        RETURN (s);
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   989
    }
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   990
%}.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   991
    "
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   992
     memory allocation (for the new string) failed.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   993
     When we arrive here, there was no memory, even after a garbage collect.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   994
     This means, that the VM wanted to get some more memory from the
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   995
     OS, which was not kind enough to give it.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   996
     Bad luck - you should increase the swap space on your machine.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   997
    "
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   998
    ^ ObjectMemory allocationFailureSignal raise.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
   999
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1000
    "
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1001
        1.0 printString
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1002
        1.234 printString
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1003
        1e10 printString
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1004
        1.2e3 printString
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1005
        1.2e30 printString
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1006
        (1.0 uncheckedDivide:0) printString
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1007
        (0.0 uncheckedDivide:0) printString
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1008
    "
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1009
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1010
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1011
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1012
printfPrintString:formatString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1013
    "non-portable: return a printed representation of the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1014
     as specified by formatString, which is defined by printf.
31
75f2b9f78be2 *** empty log message ***
claus
parents: 16
diff changeset
  1015
     If you use this, be aware, that specifying doubles differs on
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1016
     systems; on SYSV machines you have to give something like %lf, 
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1017
     while on BSD systems the format string has to be %F.
31
75f2b9f78be2 *** empty log message ***
claus
parents: 16
diff changeset
  1018
     Also, the resulting string may not be longer than 255 bytes -
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 47
diff changeset
  1019
     since thats the (static) size of the buffer.
06dbdeeed4f9 *** empty log message ***
claus
parents: 47
diff changeset
  1020
     This method is NONSTANDARD and may be removed without notice."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1021
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
  1022
%{  /* STACK: 400 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1023
    char buffer[256];
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1024
    OBJ s;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1025
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 47
diff changeset
  1026
    if (__isString(formatString)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1027
	sprintf(buffer, __stringVal(formatString), __floatVal(self));
369
claus
parents: 343
diff changeset
  1028
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1029
	s = __MKSTRING(buffer COMMA_SND);
343
claus
parents: 314
diff changeset
  1030
	if (s != nil) {
claus
parents: 314
diff changeset
  1031
	    RETURN (s);
claus
parents: 314
diff changeset
  1032
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1033
    }
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1034
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1035
    self primitiveFailed
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1036
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1037
    "Float pi printfPrintString:'%%lg -> %lg'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1038
    "Float pi printfPrintString:'%%lf -> %lf'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1039
    "Float pi printfPrintString:'%%7.5lg -> %7.5lg'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1040
    "Float pi printfPrintString:'%%7.5lf -> %7.5lf'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1041
    "Float pi printfPrintString:'%%G -> %G'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1042
    "Float pi printfPrintString:'%%F -> %F'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1043
    "Float pi printfPrintString:'%%7.5G -> %7.5G'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1044
    "Float pi printfPrintString:'%%7.5F -> %7.5F'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1045
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1046
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1047
!Float methodsFor:'private accessing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1048
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1049
basicAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1050
    "return an internal byte of the float.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1051
     The value returned here depends on byte order, float representation etc.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1052
     Therefore, this method should be used strictly private.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1053
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1054
     Notice: 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1055
	the need to redefine this method here is due to the
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1056
	inability of many machines to store floats in non-double aligned memory.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1057
	Therefore, on some machines, the first 4 bytes of a float are left unused,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1058
	and the actual float is stored at index 5 .. 12.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1059
	To hide this at one place, this method knows about that, and returns
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1060
	values as if this filler wasnt present."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1061
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1062
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1063
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1064
    register int indx;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1065
    unsigned char *cp;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1066
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1067
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1068
     * notice the missing test for self being a nonNilObject -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1069
     * this can be done since basicAt: is defined both in UndefinedObject
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1070
     * and SmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1071
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1072
    if (__isSmallInteger(index)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1073
	indx = __intVal(index) - 1;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1074
	if ((indx >= 0) && (indx < sizeof(double))) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1075
	    cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1076
	    RETURN ( __MKSMALLINT(cp[indx] & 0xFF) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1077
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1078
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1079
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1080
    index isInteger ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1081
	^ self indexNotInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1082
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1083
    ^ self subscriptBoundsError:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1084
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1085
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1086
basicAt:index put:value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1087
    "set an internal byte of the float.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1088
     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
  1089
     Therefore, this method should be used strictly private.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1090
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1091
     Notice: 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1092
	the need to redefine this method here is due to the
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1093
	inability of many machines to store floats in non-double aligned memory.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1094
	Therefore, on some machines, the first 4 bytes of a float are left unused,
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1095
	and the actual float is stored at index 5 .. 12.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1096
	To hide this at one place, this method knows about that, and returns
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1097
	values as if this filler wasnt present."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1098
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1099
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1100
    register int indx, val;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1101
    unsigned char *cp;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1102
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1103
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1104
     * notice the missing test for self being a nonNilObject -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1105
     * this can be done since basicAt: is defined both in UndefinedObject
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1106
     * and SmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1107
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1108
    if (__bothSmallInteger(index, value)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1109
	val = __intVal(value);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1110
	if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1111
	    indx = __intVal(index) - 1;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1112
	    if ((indx >= 0) && (indx < sizeof(double))) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1113
		cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1114
		cp[indx] = val;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1115
		RETURN ( value );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1116
	    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1117
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1118
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1119
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1120
    index isInteger ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1121
	^ self indexNotInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1122
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1123
    value isInteger ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1124
	"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1125
	 the object to store should be an integer number
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1126
	"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1127
	^ self elementNotInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1128
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1129
    (value between:0 and:255) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1130
	"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1131
	 the object to store must be a bytes value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1132
	"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1133
	^ self elementBoundsError
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1134
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1135
    ^ self subscriptBoundsError:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1136
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1137
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1138
!Float methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1139
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1140
isFinite
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1141
    "return true, if the receiver is a finite float 
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1142
     i.e. not NaN and not infinite."
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1143
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1144
%{  /* NOCONTEXT */
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1145
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1146
    double dV = __floatVal(self);
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1147
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1148
    if (finite(dV)) { RETURN (true); }
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1149
%}.
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1150
    ^false
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1151
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1152
    "
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1153
        1.0 isFinite
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1154
        (0.0 uncheckedDivide: 0.0) isFinite
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1155
        (1.0 uncheckedDivide: 0.0) isFinite
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1156
    "
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1157
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1158
!
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1159
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1160
isInfinite
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1161
    "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
  1162
     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
  1163
     however, inline C-code could produce them ...
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1164
     Redefined here for speed"
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1165
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1166
%{  /* NOCONTEXT */
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1167
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1168
    double dV = __floatVal(self);
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1169
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1170
#if defined(isinf) || defined(LINUX)
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1171
    if (isinf(dV)) { RETURN (true); }
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1172
#else
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1173
    if (!finite(dV) && !isnan(dV)) { RETURN (true); }
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1174
#endif
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1175
%}.
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1176
    ^ false
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1177
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1178
    "
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1179
        1.0 isInfinite
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1180
        (0.0 uncheckedDivide: 0.0) isInfinite
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1181
        (1.0 uncheckedDivide: 0.0) isInfinite
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1182
    "
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1183
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1184
!
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1185
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  1186
isNaN
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  1187
    "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
  1188
     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
  1189
     however, inline C-code could produce them ..."
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  1190
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  1191
%{  /* NOCONTEXT */
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  1192
3139
ca
parents: 3129
diff changeset
  1193
    double dV = (__floatVal(self));
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1194
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1195
    if (isnan(dV)) { RETURN (true); }
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1196
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1197
#if 0 /* Currently all our systems support isnan()
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1198
       * If not, you have to fix librun/jinterpret.c also.
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1199
       */
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1200
2395
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
  1201
    /*
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
  1202
     * sigh - every vendor is playing its own game here ...
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
  1203
     * Q: what are standards worth, anyway ?
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
  1204
     */
2392
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  1205
#ifdef IS_NAN
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1206
    if (IS_NAN(dV)) { RETURN (true); }
3139
ca
parents: 3129
diff changeset
  1207
    RETURN (false);
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1208
#endif
3139
ca
parents: 3129
diff changeset
  1209
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1210
#ifdef IS_QNAN
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1211
    if (IS_QNAN(dV)) { RETURN (true); }
3139
ca
parents: 3129
diff changeset
  1212
    RETURN (false);
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1213
#endif
2392
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  1214
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1215
#ifdef FLT_SNAN
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1216
    if (dV == FLT_SNAN) { RETURN (true); }
3139
ca
parents: 3129
diff changeset
  1217
    RETURN (false);
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1218
#endif
3139
ca
parents: 3129
diff changeset
  1219
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1220
#ifdef FLT_QNAN
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1221
    if (dV == FLT_QNAN) { RETURN (true); }
3139
ca
parents: 3129
diff changeset
  1222
    RETURN (false);
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1223
#endif
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1224
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1225
#ifdef _SNANF
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1226
    if (dV == _SNAN) { RETURN (true); }
3139
ca
parents: 3129
diff changeset
  1227
    RETURN (false);
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1228
#endif
3139
ca
parents: 3129
diff changeset
  1229
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1230
#ifdef _QNANF
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1231
    if (dV == _QNAN) { RETURN (true); }
3139
ca
parents: 3129
diff changeset
  1232
    RETURN (false);
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1233
#endif
2392
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  1234
2395
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
  1235
#ifdef IsPosNAN
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1236
    if IsPosNAN(dV) { RETURN (true); }
3139
ca
parents: 3129
diff changeset
  1237
    RETURN (false);
2395
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
  1238
#endif
3139
ca
parents: 3129
diff changeset
  1239
2395
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
  1240
#ifdef IsNegNAN
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1241
    if IsNegNAN(dV) { RETURN (true); }
3139
ca
parents: 3129
diff changeset
  1242
    RETURN (false);
2395
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
  1243
#endif
e83076fa0a3f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2394
diff changeset
  1244
2393
a20badfc3d85 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2392
diff changeset
  1245
#ifdef NAN
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1246
    if (dV == NAN) { RETURN (true); }
3139
ca
parents: 3129
diff changeset
  1247
    RETURN (false);
2390
43f615d2af49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2387
diff changeset
  1248
#endif
3139
ca
parents: 3129
diff changeset
  1249
2399
5d47ec6834a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
  1250
#ifdef NaN
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1251
    if (NaN(dV)) { RETURN (true); }
3139
ca
parents: 3129
diff changeset
  1252
    RETURN (false);
2399
5d47ec6834a8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
  1253
#endif
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1254
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1255
#endif /* 0 */
2392
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  1256
%}.
cd44ad5cf015 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2391
diff changeset
  1257
    ^ false
3139
ca
parents: 3129
diff changeset
  1258
3146
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1259
    "
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1260
        1.0 isNaN
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1261
        (0.0 uncheckedDivide: 0.0) isNaN
4e46505d1d59 New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents: 3139
diff changeset
  1262
    "
3139
ca
parents: 3129
diff changeset
  1263
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  1264
!
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  1265
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1266
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1267
    "return true if the receiver is less than zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1268
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1269
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1270
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1271
    RETURN ( (__floatVal(self) < 0.0) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1272
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1273
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1274
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1275
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1276
    "return true if the receiver is greater or equal to zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1277
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1278
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1279
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1280
    RETURN ( (__floatVal(self) >= 0.0) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1281
%}
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1282
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1283
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1284
strictlyPositive
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1285
    "return true if the receiver is greater than zero"
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1286
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1287
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1288
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1289
    RETURN ( (__floatVal(self) > 0.0) ? true : false );
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1290
%}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1291
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1292
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1293
!Float methodsFor:'truncation and rounding'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1294
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1295
ceiling
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1296
    "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
  1297
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1298
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1299
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1300
%{
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1301
    double ceil();
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1302
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1303
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1304
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1305
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1306
     */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1307
    dVal = ceil(__floatVal(self));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1308
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1309
	RETURN ( __MKSMALLINT( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1310
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1311
    __qMKFLOAT(val, dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1312
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1313
    ^ val asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1314
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1315
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1316
ceilingAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1317
    "return the smallest integer-valued float greater or equal to the receiver.
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1318
     This is much like #ceiling, but avoids a (possibly expensive) conversion 
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1319
     of the result to an integer.
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1320
     It may be useful, if the result is to be further used in another 
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1321
     float-operation."
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1322
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1323
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1324
    double ceil();
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1325
    double dVal;
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1326
    OBJ val;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1327
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1328
    /*
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1329
     * ST-80 (and X3J20) returns integer.
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1330
     */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1331
    dVal = ceil(__floatVal(self));
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1332
    __qMKFLOAT(val, dVal);
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1333
    RETURN (val);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1334
%}
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1335
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1336
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1337
floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1338
    "return the integer nearest the receiver towards negative infinity."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1339
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1340
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1341
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1342
%{
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1343
    double floor();
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1344
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1345
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1346
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1347
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1348
     */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1349
    dVal = floor(__floatVal(self));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1350
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1351
	RETURN ( __MKSMALLINT( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1352
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1353
    __qMKFLOAT(val, dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1354
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1355
    ^ val asInteger
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1356
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1357
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1358
     0.5 floor          
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1359
     0.5 floorAsFloat 
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1360
     -0.5 floor     
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1361
     -0.5 floorAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1362
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1363
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1364
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1365
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1366
floorAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1367
    "return the integer nearest the receiver towards negative infinity
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1368
     as a float.
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1369
     This is much like #floor, but avoids a (possibly expensive) conversion 
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1370
     of the result to an integer.
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1371
     It may be useful, if the result is to be further used in another 
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1372
     float-operation."
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1373
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1374
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1375
    double floor();
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1376
    double dVal;
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1377
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1378
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1379
    dVal = floor(__floatVal(self));
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1380
    __qMKFLOAT(v, dVal);
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1381
    RETURN (v);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1382
%}
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1383
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1384
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1385
     0.5 floor          
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1386
     0.5 floorAsFloat 
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1387
     -0.5 floor       
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1388
     -0.5 floorAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1389
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1390
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1391
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1392
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1393
rounded
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1394
    "return the receiver rounded to the nearest integer"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1395
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1396
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1397
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1398
%{  
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1399
    double floor(), ceil();
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1400
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1401
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1402
    dVal = __floatVal(self);
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1403
    if (dVal < 0.0) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1404
	dVal = ceil(dVal - 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1405
    } else {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1406
	dVal = floor(dVal + 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1407
    }
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1408
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1409
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1410
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1411
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1412
	RETURN ( __MKSMALLINT( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1413
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1414
    __qMKFLOAT(val, dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1415
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1416
    ^ val asInteger
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1417
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1418
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1419
     0.4 rounded     
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1420
     0.5 rounded     
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1421
     0.6 rounded     
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1422
     -0.4 rounded    
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1423
     -0.5 rounded  
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1424
     -0.6 rounded  
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1425
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1426
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1427
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1428
roundedAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1429
    "return the receiver rounded to the nearest integer as a float.
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1430
     This is much like #rounded, but avoids a (possibly expensive) conversion 
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1431
     of the result to an integer.
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1432
     It may be useful, if the result is to be further used in another 
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1433
     float-operation."
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1434
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1435
    |val|
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1436
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1437
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1438
    double floor(), ceil();
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1439
    double dVal;
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1440
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1441
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1442
    dVal = __floatVal(self);
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1443
    if (dVal < 0.0) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1444
	dVal = ceil(dVal - 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1445
    } else {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1446
	dVal = floor(dVal + 0.5);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1447
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1448
    __qMKFLOAT(v, dVal);
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1449
    RETURN (v);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1450
%}
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1451
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1452
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1453
     0.5 rounded     
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1454
     -0.5 rounded  
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1455
     0.5 roundedAsFloat     
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1456
     -0.5 roundedAsFloat  
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1457
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1458
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1459
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1460
truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1461
    "return the receiver truncated towards zero as an integer"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1462
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1463
    |val|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1464
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1465
%{
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1466
    double floor(), ceil();
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1467
    double dVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1468
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1469
    dVal = __floatVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1470
    if (dVal < 0.0) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1471
	dVal = ceil(dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1472
    } else {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1473
	dVal = floor(dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1474
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1475
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1476
    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1477
     * ST-80 (and X3J20) returns integer.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1478
     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1479
    if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1480
	RETURN ( __MKSMALLINT( (INT) dVal ) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1481
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1482
    __qMKFLOAT(val, dVal);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1483
%}.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1484
    ^ val asInteger
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1485
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1486
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1487
     0.5 truncated     
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1488
     -0.5 truncated   
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1489
     0.5 truncatedAsFloat     
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1490
     -0.5 truncatedAsFloat  
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1491
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1492
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1493
!
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1494
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1495
truncatedAsFloat
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1496
    "return the receiver truncated towards zero as a float.
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1497
     This is much like #truncated, but avoids a (possibly expensive) conversion 
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1498
     of the result to an integer.
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1499
     It may be useful, if the result is to be further used in another 
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1500
     float-operation."
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1501
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1502
%{  /* NOCONTEXT */
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1503
    double floor(), ceil();
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1504
    double dVal;
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1505
    OBJ v;
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1506
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1507
    dVal = __floatVal(self);
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1508
    if (dVal < 0.0) {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1509
	dVal = ceil(dVal);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1510
    } else {
3127
590c7d2bb4b9 fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents: 3118
diff changeset
  1511
	dVal = floor(dVal);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1512
    }
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1513
    __qMKFLOAT(v, dVal);
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1514
    RETURN (v);
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1515
%}
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1516
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1517
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1518
     0.5 truncated     
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1519
     -0.5 truncated   
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1520
     0.5 truncatedAsFloat     
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1521
     -0.5 truncatedAsFloat  
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1522
    "
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1523
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1524
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1525
1879
26df273349c4 added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1526
!Float class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1527
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1528
version
3163
212a539ee379 added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents: 3146
diff changeset
  1529
    ^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.70 1998-01-12 13:20:30 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
  1530
! !
2387
3aafb49a86ac added #isNaN
Claus Gittinger <cg@exept.de>
parents: 2358
diff changeset
  1531
Float initialize!