LimitedPrecisionReal.st
author Stefan Vogel <sv@exept.de>
Tue, 29 Jun 2004 15:20:35 +0200
changeset 8422 c206b4711b6e
parent 8395 6bd97113cb4c
child 8892 5d05a7f150a5
permissions -rw-r--r--
Define #storeString to not use DecimalPointCharacter and to store all relevant digits.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     1
"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
     3
	      All Rights Reserved
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     4
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    11
"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    12
5470
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
    13
"{ Package: 'stx:libbasic' }"
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
    14
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    15
Number subclass:#LimitedPrecisionReal
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    16
	instanceVariableNames:''
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    17
	classVariableNames:''
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    18
	poolDictionaries:''
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    19
	category:'Magnitude-Numbers'
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    20
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
!LimitedPrecisionReal class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
 COPYRIGHT (c) 1994 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
    27
	      All Rights Reserved
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
"
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    40
    Abstract superclass for any-precision floating point numbers (i.e. Float and Double).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    41
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    42
    Due to historic reasons, ST/X's Floats are what Doubles are in ST-80.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    43
    This may change soon (implementing LPReal is a first step towards this).
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    44
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    45
    Range and Precision of Storage Formats:
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    46
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    47
      Format |   Class    | Significant Digits (Binary) | Smallest Pos Number | Largest Pos Number | Significant Digits (Decimal)
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    48
      -------+------------+-----------------------------+---------------------+--------------------+------------------------------    
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    49
      single | ShortFloat |         24                  |  1.175... 10-38     |  3.402... 10+38    |      6-9
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    50
      -------+------------+-----------------------------+---------------------+--------------------+------------------------------    
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    51
      double | Float      |         53                  |  2.225... 10-308    |  1.797... 10+308   |     15-17
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    52
      -------+------------+-----------------------------+---------------------+--------------------+------------------------------    
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    53
      double | LongFloat  |        113                  |  3.362... 10-4932   |  1.189... 10+4932  |     33-36
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    54
      ext    |            |                             |                     |                    |
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    55
      (SPARC)|            |                             |                     |                    |
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    56
      -------+            |-----------------------------+---------------------+--------------------+------------------------------    
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    57
      double |            |         64                  |  3.362... 10-4932   |  1.189... 10+4932  |     18-21
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    58
      ext    |            |                             |                     |                    |
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    59
      (x86)  |            |                             |                     |                    |
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    60
      -------+------------+-----------------------------+---------------------+--------------------+------------------------------    
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    61
        --   | LargeFloat |         arbitrary           |  arbitrarily small  |  arbitrarily large |     arbitrary
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    62
      -------+------------+-----------------------------+---------------------+--------------------+------------------------------    
7405
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    63
9b0334a4591b comments
Claus Gittinger <cg@exept.de>
parents: 7403
diff changeset
    64
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    65
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    66
        Claus Gittinger
1893
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    67
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    68
    [see also:]
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    69
        Fraction FixedPoint
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    70
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    71
! !
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    72
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    73
!LimitedPrecisionReal class methodsFor:'instance creation'!
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    74
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    75
fromInteger:anInteger
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    76
    "return a float with anInteger's value.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    77
     Since floats have a limited precision, you usually loose bits when doing this
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    78
     (see Float decimalPrecision, LongFloat decimalPrecision."
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    79
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    80
    |newFloat sign absVal|
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    81
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    82
    newFloat := self zero.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    83
    sign := anInteger sign.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    84
    absVal := anInteger abs.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    85
    (sign ~~ 0) ifTrue:[
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    86
        absVal digitLength to:1 by:-1 do:[:i |
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    87
            newFloat := (newFloat * 256.0) + (absVal digitByteAt:i) asFloat
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    88
        ].
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    89
        (sign < 0) ifTrue:[
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    90
            newFloat := newFloat negated
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    91
        ]
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    92
    ].
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    93
    ^ newFloat
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    94
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    95
    "
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    96
     1234567890 asFloat                     
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    97
     1234567890 asFloat asInteger                    
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    98
     -1234567890 asFloat asInteger                    
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
    99
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   100
     12345678901234567890 asFloat             
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   101
     12345678901234567890 asFloat asInteger   
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   102
     -12345678901234567890 asFloat asInteger   
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   103
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   104
     12345678901234567890 asLongFloat           
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   105
     12345678901234567890 asLongFloat asInteger 
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   106
     -12345678901234567890 asLongFloat asInteger 
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   107
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   108
     123456789012345678901234567890 asLongFloat           
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   109
     123456789012345678901234567890 asLongFloat asInteger  
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   110
     -123456789012345678901234567890 asLongFloat asInteger  
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   111
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   112
     1234567890123456789012345678901234567890 asLongFloat           
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   113
     1234567890123456789012345678901234567890 asLongFloat asInteger  
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   114
     -1234567890123456789012345678901234567890 asLongFloat asInteger  
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   115
    "
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   116
!
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   117
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   118
fromLimitedPrecisionReal:anLPReal
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   119
    "return a float with anLPReals value.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   120
     You might loose bits when doing this.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   121
     Slow fallback."
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   122
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   123
    |fract|
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   124
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   125
    anLPReal isFinite ifFalse:[
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   126
        anLPReal isNaN ifTrue:[^ self NaN].
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   127
        anLPReal negative ifTrue:[^ self negativeInfinity].
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   128
        ^ self infinity
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   129
    ].
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   130
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   131
    fract := anLPReal asTrueFraction.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   132
    ^ (self fromInteger:fract numerator) / (self fromInteger:fract denominator)
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   133
!
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   134
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   135
new:aNumber
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   136
    "catch this message - not allowed for floats/doubles"
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   137
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   138
    self error:'Floats/Doubles cannot be created with new:'
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   139
! !
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   140
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   141
!LimitedPrecisionReal class methodsFor:'class initialization'!
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   142
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   143
initialize
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   144
    "initialize ANSI compliant float globals"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   145
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   146
    Smalltalk at:#FloatE put:ShortFloat.
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   147
    Smalltalk at:#FloatD put:Float.
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   148
    Smalltalk at:#FloatQ put:LongFloat.
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   149
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   150
    "
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   151
     self initialize
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   152
    "
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   153
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   154
    "Created: / 7.9.2001 / 14:02:45 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   155
    "Modified: / 7.9.2001 / 14:02:54 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   156
! !
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   157
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   158
!LimitedPrecisionReal class methodsFor:'constants & defaults'!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   159
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   160
NaN
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   161
    "return the constant NaN (not a Number)."
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   162
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   163
    ^ self zero uncheckedDivide:self zero
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   164
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   165
    "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   166
      ShortFloat NaN  
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   167
      Float NaN       
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   168
      LongFloat NaN   
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   169
      LargeFloat NaN   
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   170
    "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   171
!
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   172
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   173
e
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   174
    "return the closest approximation of the irrational number e"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   175
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   176
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   177
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   178
    "Modified: / 7.9.2001 / 14:05:02 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   179
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   180
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   181
emax
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   182
    "return the largest exponent"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   183
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   184
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   185
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   186
    "Created: / 7.9.2001 / 14:05:28 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   187
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   188
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   189
emin
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   190
    "return the smallest exponent"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   191
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   192
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   193
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   194
    "Created: / 7.9.2001 / 14:05:35 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   195
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   196
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   197
epsilon
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   198
    "return the maximum relative spacing"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   199
6575
b07cd54c4375 Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents: 6195
diff changeset
   200
    ^ self radix asFloat raisedTo:(1 - self precision)
b07cd54c4375 Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents: 6195
diff changeset
   201
b07cd54c4375 Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents: 6195
diff changeset
   202
    "
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   203
      ShortFloat epsilon  
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   204
      Float epsilon       
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   205
      LongFloat epsilon   
6575
b07cd54c4375 Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents: 6195
diff changeset
   206
    "
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   207
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   208
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   209
fmax
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   210
    "return the largest value allowed"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   211
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   212
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   213
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   214
    "Created: / 7.9.2001 / 14:06:56 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   215
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   216
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   217
fmin
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   218
    "return the minimum value allowed"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   219
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   220
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   221
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   222
    "Created: / 7.9.2001 / 14:07:06 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   223
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   224
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   225
infinity
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   226
    "return a float representing infinity"
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   227
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   228
    ^ self unity uncheckedDivide:self zero
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   229
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   230
    "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   231
      ShortFloat infinity  
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   232
      Float infinity       
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   233
      LongFloat infinity   
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   234
      LargeFloat infinity   
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   235
    "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   236
!
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   237
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   238
negativeInfinity
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   239
    "return a float representing negative infinity"
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   240
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   241
    ^ self unity negated uncheckedDivide:self zero
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   242
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   243
    "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   244
      ShortFloat negativeInfinity   
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   245
      Float negativeInfinity       
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   246
      LongFloat negativeInfinity   
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   247
      LargeFloat negativeInfinity   
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   248
    "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   249
!
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   250
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   251
pi
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   252
    "return the closest approximation of the irrational number pi"
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   253
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   254
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   255
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   256
    "Created: / 7.9.2001 / 14:07:35 / cg"
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   257
! !
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   258
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   259
!LimitedPrecisionReal class methodsFor:'queries'!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   260
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   261
decimalPrecision
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   262
    "return the number of valid decimal digits"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   263
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   264
    ^ (self precision / (10.0 log:self radix)) floor
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   265
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   266
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   267
     ShortFloat decimalPrecision 
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   268
     Float decimalPrecision      
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   269
     LongFloat decimalPrecision  
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   270
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   271
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   272
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   273
numBitsInExponent
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   274
    "return the number of bits in the exponent"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   275
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   276
    ^ self subclassResponsibility
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   277
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   278
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   279
numBitsInIntegerPart
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   280
    ^ 0
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   281
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   282
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   283
numBitsInMantissa
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   284
    "return the number of bits in the mantissa
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   285
     (typically 1 less than the precision due to the hidden bit)"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   286
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   287
    ^ self subclassResponsibility
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   288
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   289
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   290
precision
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   291
    "return the number of valid mantissa bits"
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   292
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   293
    ^ self numBitsInMantissa + 1 - self numBitsInIntegerPart 
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   294
!
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   295
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   296
radix
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   297
    "return the radix (base)"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   298
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   299
    self subclassResponsibility
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   300
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   301
    "Created: / 7.9.2001 / 14:08:20 / cg"
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   302
! !
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   303
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   304
!LimitedPrecisionReal methodsFor:'accessing'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   305
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   306
at:index
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   307
    "redefined to prevent access to individual bytes in a real."
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   308
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   309
    self error:'not allowed for floats/doubles'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   310
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   311
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   312
at:index put:aValue
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   313
    "redefined to prevent access to individual bytes in a real"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   314
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   315
    self error:'not allowed for floats/doubles'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   316
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   317
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   318
!LimitedPrecisionReal methodsFor:'arithmetic'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   319
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   320
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   321
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   323
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   324
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   325
"/    ^ aNumber productFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   326
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   327
    ^ aNumber productFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   328
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   329
    "Modified: 17.4.1996 / 12:35:36 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   330
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   331
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   332
+ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   333
    "return the sum of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   334
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   335
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   336
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   337
"/    ^ aNumber sumFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   338
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   339
    ^ aNumber sumFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   340
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   341
    "Modified: 17.4.1996 / 12:35:55 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   342
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   343
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   344
- aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   345
    "return the difference of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   346
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   347
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   348
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   349
"/    ^ aNumber differenceFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   350
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   351
    ^ aNumber differenceFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   352
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   353
    "Modified: 17.4.1996 / 12:36:07 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   354
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   355
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   356
/ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   357
    "return the quotient of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   358
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   359
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6890
diff changeset
   360
        ^ ZeroDivide raiseRequestWith:thisContext.
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   361
    ].
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   362
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   363
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   364
"/    ^ aNumber quotientFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   365
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   366
    ^ aNumber quotientFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   367
4455
2d31d0d986be Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 3898
diff changeset
   368
    "Modified: / 17.4.1996 / 12:36:21 / cg"
2d31d0d986be Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 3898
diff changeset
   369
    "Modified: / 26.7.1999 / 10:46:11 / stefan"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   370
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   371
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   372
// aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   373
    "return the integer quotient of dividing the receiver by aNumber with
1882
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   374
     truncation towards negative infinity."
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   375
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   376
    ^ (self / aNumber) floor asInteger
1882
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   377
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   378
    "Modified: 5.11.1996 / 11:45:37 / cg"
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   379
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   380
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   381
ceiling
7398
0f96525b931e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7394
diff changeset
   382
    ^ self asTrueFraction ceiling
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   383
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   384
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   385
floor
7398
0f96525b931e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7394
diff changeset
   386
    ^ self asTrueFraction floor
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   387
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   388
5238
f7a816a660a3 categories
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   389
!LimitedPrecisionReal methodsFor:'coercing & converting'!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   390
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   391
asFloat
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   392
    ^ Float fromLimitedPrecisionReal:self
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   393
!
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   394
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   395
asFraction
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   396
    "Answer a rational number (Integer or Fraction) representing the receiver.
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   397
     This conversion uses the continued fraction method to approximate 
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   398
     a floating point number.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   399
     In contrast to #asTrueFraction, which returns exactly the value of the float,
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   400
     this rounds in the last significant bit of the floating point number.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   401
    "
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   402
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   403
    |num1 denom1 num2 denom2 int frac newD temp limit|
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   404
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   405
    self isFinite ifFalse:[
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   406
"/        ^ self asMetaNumber.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   407
        ^ self class
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   408
            raise:#domainErrorSignal
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   409
            receiver:self
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   410
            selector:#asFraction
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   411
            arguments:#()
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   412
            errorString:'Cannot represent non-finite number as fraction'
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   413
    ].
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   414
7394
c18ce6a5a437 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7390
diff changeset
   415
    limit := 10 raisedToInteger:self defaultNumberOfDigits.
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   416
    num1 := self truncated. 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   417
    denom1 := 1.            "The first of two alternating denominators"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   418
    num2 := 1.              "The second numerator"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   419
    denom2 := 0.            "The second denominator--will update"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   420
    int := num1.            "The integer part of self"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   421
    frac := self fractionPart.             
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   422
    [frac = 0] whileFalse:[                
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   423
        newD := 1.0 / frac.                   
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   424
        int := newD truncated.        
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   425
        frac := newD fractionPart.      "save the fractional part for next time"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   426
        temp := num2.                   "old numerator and save it"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   427
        num2 := num1.                         
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   428
        num1 := num1 * int + temp.      "Update first numerator"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   429
        temp := denom2.                 "old denominator and save it"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   430
        denom2 := denom1.                    
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   431
        denom1 := int * denom1 + temp.  "Update first denominator"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   432
        limit < denom1 ifTrue:[
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   433
            "Is ratio past float precision?  If so, pick which of the two ratios to use"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   434
            num2 = 0.0 ifTrue:[
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   435
                "Is second denominator 0?"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   436
                ^ Fraction numerator:num1 denominator:denom1
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   437
            ].
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   438
            ^ Fraction numerator:num2 denominator:denom2
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   439
        ]
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   440
    ].
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   441
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   442
    "If fractional part is zero, return the first ratio"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   443
    denom1 = 1 ifTrue:[
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   444
        "Am i really an Integer?"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   445
        ^ num1 "Yes, return Integer result"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   446
    ].
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   447
    "Otherwise return Fraction result"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   448
    ^ Fraction numerator:num1 denominator:denom1
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   449
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   450
    "
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   451
     1.1 asFraction      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   452
     1.2 asFraction      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   453
     0.3 asFraction   
7394
c18ce6a5a437 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7390
diff changeset
   454
     0.5 asFraction  
c18ce6a5a437 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7390
diff changeset
   455
     (1/5) asFloat asFraction  
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   456
     (1/8) asFloat asFraction  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   457
     (1/13) asFloat asFraction 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   458
     3.14159 asFraction        
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   459
     3.14159 asFraction asFloat       
7394
c18ce6a5a437 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7390
diff changeset
   460
     1.3 asFraction            
c18ce6a5a437 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7390
diff changeset
   461
     1.0 asFraction            
c18ce6a5a437 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7390
diff changeset
   462
     1E6 asFraction            
c18ce6a5a437 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7390
diff changeset
   463
     1E-6 asFraction            
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   464
    "
2793
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2388
diff changeset
   465
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   466
    "Modified: / 25.10.1997 / 16:41:19 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   467
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   468
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   469
asInteger
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   470
    "return an integer with same value - might truncate"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   471
3185
1c7bd090a822 removed unused local vars
Claus Gittinger <cg@exept.de>
parents: 3148
diff changeset
   472
    |max maxF|
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   473
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   474
    self isFinite ifFalse:[
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   475
"/        ^ self asMetaNumber.
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   476
        ^ self class
7418
521174de046d Nan asInteger raises DomainError
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
   477
            raise:#domainErrorSignal
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   478
            receiver:self
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   479
            selector:#asInteger
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6185
diff changeset
   480
            arguments:#()
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   481
            errorString:'Cannot represent non-finite number as integer'
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   482
    ].
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   483
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   484
    self abs < 2e16 ifTrue:[
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   485
        "/ NOTICE: this must be redefined in float
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   486
        "/ subclasses to handle the smallinteger range;
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   487
        "/ i.e. this may only be invoked for reals
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   488
        "/ which are NOT within the smallInt range.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   489
        "/ otherwise, endless recursion is the consequence.
3426
a648de89ac72 comment
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
   490
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   491
        max := SmallInteger maxVal // 2 + 1.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   492
        maxF := max asFloat.
3426
a648de89ac72 comment
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
   493
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   494
        ^ (self quo:maxF) * max + (self rem:maxF) truncated
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   495
    ].
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   496
    ^ self asTrueFraction
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   497
3137
f334b17f0347 bif speedup in asInteger with large floats
ca
parents: 3060
diff changeset
   498
    "
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   499
     12345.0 asInteger     
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   500
     1e15 asInteger        
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   501
     1e33 asInteger asFloat
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   502
     1e303 asInteger asFloat
3137
f334b17f0347 bif speedup in asInteger with large floats
ca
parents: 3060
diff changeset
   503
    "
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   504
6195
9e60c38d1d61 #raise:receiver:selector...
Claus Gittinger <cg@exept.de>
parents: 6185
diff changeset
   505
    "Modified: / 16.11.2001 / 14:15:33 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   506
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   507
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   508
asLargeFloat
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   509
    ^ LargeFloat fromLimitedPrecisionReal:self
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   510
!
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   511
7378
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   512
asLimitedPrecisionReal
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   513
    "return a float of any precision with same value"
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   514
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   515
   ^ self
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   516
!
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
   517
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   518
asLongFloat
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   519
    ^ LongFloat fromLimitedPrecisionReal:self
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   520
!
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   521
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   522
asRational
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   523
    "Answer a Rational number--Integer or Fraction--representing the receiver.
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   524
     Same as asFraction fro st-80 compatibility."
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   525
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   526
    ^ self asFraction
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   527
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   528
    "
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   529
     1.1 asRational      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   530
     1.2 asRational      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   531
     0.3 asRational   
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   532
     0.5 asRational 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   533
     (1/5) asFloat asRational
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   534
     (1/8) asFloat asRational  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   535
     (1/13) asFloat asRational 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   536
     3.14159 asRational        
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   537
     3.14159 asRational asFloat       
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   538
     1.3 asRational  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   539
     1.0 asRational  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   540
    "
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   541
!
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   542
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   543
asShortFloat
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   544
    ^ ShortFloat fromLimitedPrecisionReal:self
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   545
!
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   546
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   547
asTrueFraction
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   548
    "Answer a fraction or integer that EXACTLY represents self,
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   549
     an any-precision IEEE floating point number, consisting of:
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   550
        numMantissaBits bits of normalized mantissa (i.e. with hidden leading 1-bit)
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   551
        optional numExtraBits between mantissa and exponent (normalized flag for ext-real)
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   552
        numExponentBits bits of 2s complement exponent
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   553
        1 sign bit.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   554
     Taken from Floats asTrueFraction"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   555
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   556
    |shifty sign expPart exp fraction fractionPart result zeroBitsCount
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   557
     numBytes numBits numBitsInMantissa maskMantissa numBitsInExponent maskExponent
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   558
     biasExponent numIntegerBits|
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   559
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   560
    self isFinite ifFalse:[
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   561
"/        ^ self asMetaNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   562
        ^ self class
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   563
            raise:#domainErrorSignal
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   564
            receiver:self
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   565
            selector:#asTrueFraction
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   566
            arguments:#()
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   567
            errorString:'Cannot represent non-finite float as a fraction'.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   568
    ].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   569
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   570
    "Extract the bits of an IEEE anySize float "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   571
    numBytes := self basicSize.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   572
    numBitsInMantissa := self class numBitsInMantissa. maskMantissa := (1 bitShift:numBitsInMantissa) - 1.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   573
    numBitsInExponent := self class numBitsInExponent. maskExponent := (1 bitShift:numBitsInExponent) - 1.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   574
    numIntegerBits := self class numBitsInIntegerPart.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   575
    numBits := numBitsInMantissa + numBitsInExponent. "not (numBytes * 8 - 1) -- there could be 80 float bits in 96 overall bits"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   576
    biasExponent := maskExponent bitShift:-1.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   577
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   578
    shifty := LargeInteger basicNew numberOfDigits:numBytes.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   579
    UninterpretedBytes isBigEndian ifTrue:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   580
        1 to:numBytes do:[:i | shifty digitAt:(numBytes+1-i) put:(self basicAt:i)].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   581
    ] ifFalse:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   582
        1 to:numBytes do:[:i | shifty digitAt:i put:(self basicAt:i)].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   583
    ].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   584
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   585
    " Extract the sign and the biased exponent "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   586
    sign := (shifty bitAt:numBits+1) == 0 ifTrue: [1] ifFalse: [-1].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   587
    expPart := (shifty bitShift:numBitsInMantissa negated) bitAnd: maskExponent.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   588
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   589
    " Extract fractional part; answer 0 if this is a true 0.0 value "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   590
    fractionPart := shifty bitAnd:maskMantissa.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   591
    ( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0  ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   592
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   593
    numIntegerBits == 0 ifTrue:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   594
        " Replace omitted leading 1 in fraction (Notice: quadIEEE format does not do this)"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   595
        fraction := fractionPart bitOr: (maskMantissa + 1).
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   596
    ] ifFalse:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   597
        fraction := fractionPart.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   598
    ].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   599
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   600
    "Unbias exponent"
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   601
    exp := biasExponent - expPart + (numBitsInMantissa - numIntegerBits).
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   602
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   603
    " Form the result. When exp>fractionalPrecision, the exponent is adjusted by
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   604
      the number of trailing zero bits in the fraction to minimize
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   605
      the (huge) time otherwise spent in #gcd: of fraction handling code."
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   606
    exp negative ifTrue: [
7480
74f8bf8628e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7447
diff changeset
   607
        result := sign * (fraction bitShift: exp negated) 
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   608
    ] ifFalse:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   609
        zeroBitsCount := fraction lowBit - 1.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   610
        exp := exp - zeroBitsCount.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   611
        exp <= 0 ifTrue: [
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   612
            zeroBitsCount := zeroBitsCount + exp.
7480
74f8bf8628e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7447
diff changeset
   613
            result := sign * (fraction bitShift:zeroBitsCount negated) 
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   614
        ] ifFalse: [
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   615
            result := Fraction
7480
74f8bf8628e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7447
diff changeset
   616
                    numerator: (sign * (fraction bitShift: zeroBitsCount negated))
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   617
                    denominator: (1 bitShift:exp) 
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   618
        ] 
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   619
    ].
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   620
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   621
    "Low cost validation omitted after extensive testing"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   622
    "(result asFloat = self) ifFalse: [self error: 'asTrueFraction validation failed']."
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   623
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   624
    ^ result 
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   625
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   626
    "
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   627
     0.3 asFloat asTrueFraction   
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   628
     0.3 asShortFloat asTrueFraction  
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   629
     0.3 asLongFloat asTrueFraction   
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   630
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   631
     1.25 asTrueFraction     
7480
74f8bf8628e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7447
diff changeset
   632
     1.25 asShortFloat asTrueFraction     
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   633
     0.25 asTrueFraction     
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   634
     -0.25 asTrueFraction    
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   635
     3e37 asTrueFraction     
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   636
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   637
     Float NaN asTrueFraction               -> error
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   638
     Float infinity asTrueFraction          -> error
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   639
     Float negativeInfinity asTrueFraction  -> error
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   640
    "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   641
!
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   642
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   643
exponent
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   644
    "extract a normalized floats exponent.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   645
     The returned value depends on the float-representation of
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   646
     the underlying machine and is therefore highly unportable.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   647
     This is not for general use.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   648
     This assumes that the mantissa is normalized to
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   649
     0.5 .. 1.0 and the floats value is mantissa * 2^exp"
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   650
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   651
    |shifty expPart exp numBytes numBitsInMantissa maskMantissa numBitsInExponent maskExponent
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   652
     biasExponent numIntegerBits fractionPart|
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   653
7390
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   654
    "Extract the bits of an IEEE anySize float "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   655
    numBytes := self basicSize.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   656
    numBitsInMantissa := self class numBitsInMantissa. maskMantissa := (1 bitShift:numBitsInMantissa) - 1.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   657
    numBitsInExponent := self class numBitsInExponent. maskExponent := (1 bitShift:numBitsInExponent) - 1.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   658
    numIntegerBits := self class numBitsInIntegerPart.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   659
    biasExponent := maskExponent bitShift:-1.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   660
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   661
    shifty := LargeInteger basicNew numberOfDigits:numBytes.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   662
    UninterpretedBytes isBigEndian ifTrue:[
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   663
        1 to:numBytes do:[:i | shifty digitAt:(numBytes+1-i) put:(self basicAt:i)].
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   664
    ] ifFalse:[
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   665
        1 to:numBytes do:[:i | shifty digitAt:i put:(self basicAt:i)].
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   666
    ].
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   667
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   668
    " Extract the sign and the biased exponent "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   669
    expPart := (shifty bitShift:numBitsInMantissa negated) bitAnd: maskExponent.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   670
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   671
    " Extract fractional part; answer 0 if this is a true 0.0 value "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   672
    fractionPart := shifty bitAnd:maskMantissa.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   673
    ( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0  ].
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   674
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   675
    exp := expPart - biasExponent + 1.
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   676
    ^ exp
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   677
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   678
    "
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   679
     0.3 asFloat exponent  
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   680
     0.3 asShortFloat exponent  
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   681
     0.3 asLongFloat exponent  
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   682
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   683
     0.0 exponent2      0
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   684
     1.0 exponent2      1
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   685
     2.0 exponent2      2
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   686
     3.0 exponent2      2
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   687
     4.0 exponent2      3
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   688
     0.5 exponent2      0
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   689
     0.4 exponent2      -1
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   690
     0.25 exponent2     -1
1e770c64a291 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
   691
     0.00000011111 exponent2  -23 
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   692
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   693
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   694
3898
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   695
fractionalPart
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   696
    "This has been renamed to #fractionPart for ST80 compatibility.
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   697
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   698
     extract the after-decimal fraction part.
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   699
     the floats value is 
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   700
        float truncated + float fractionalPart"
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   701
5868
d497030b1df7 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
   702
    <resource:#obsolete>
d497030b1df7 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
   703
3898
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   704
    self obsoleteMethodWarning:'please use #fractionPart'.
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   705
    ^ self fractionPart
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   706
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   707
    "Modified: / 28.10.1998 / 17:10:12 / cg"
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   708
    "Created: / 28.10.1998 / 17:10:32 / cg"
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   709
!
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   710
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   711
i
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   712
    "return a complex number, with the receiver as imaginary part, 0 as real part"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   713
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   714
    ^ Complex
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   715
        real:0
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   716
        imaginary:self
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   717
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   718
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   719
     3.0i
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   720
     (1+1i)
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   721
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   722
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   723
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   724
!LimitedPrecisionReal methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   725
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   726
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   727
    "return true, if the argument is greater"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   728
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   729
"/ as soon as Float are float & Double are doubles,
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   730
"/ use:
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   731
"/    ^ aNumber lessFromDouble:self asDouble
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   732
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   733
    ^ aNumber lessFromFloat:self asFloat
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   734
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   735
    "Modified: 17.4.1996 / 13:34:50 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   736
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   737
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   738
!LimitedPrecisionReal methodsFor:'copying'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   739
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   740
deepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   741
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   742
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   743
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   744
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   745
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   746
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   747
deepCopyUsing:aDictionary
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   748
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   749
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   750
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   751
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   752
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   753
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   754
shallowCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   755
    "return a shallow copy of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   756
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   757
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   758
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   759
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   760
simpleDeepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   761
    "return a deep copy of the receiver
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   762
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   763
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   764
    ^ self
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   765
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   766
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   767
!LimitedPrecisionReal methodsFor:'double dispatching'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   768
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   769
differenceFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   770
    "sent when a fraction does not know how to subtract the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   771
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   772
    |d|
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   773
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   774
    d := aFraction denominator.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   775
    ^ (aFraction numerator - (self * d)) / d
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   776
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   777
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   778
productFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   779
    "sent when a fraction does not know how to multiply the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   780
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   781
    ^ self * aFraction numerator / aFraction denominator
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   782
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   783
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   784
quotientFromFraction:aFraction
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   785
    "Return the quotient of the argument, aFraction and the receiver.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   786
     Sent when aFraction does not know how to divide by the receiver."
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   787
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   788
    ^ aFraction numerator / (self * aFraction denominator)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   789
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   790
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   791
sumFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   792
    "sent when a fraction does not know how to add the receiver, a float"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   793
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   794
    |d|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   795
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   796
    d := aFraction denominator.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   797
    ^ (self * d + aFraction numerator) / d
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   798
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   799
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   800
!LimitedPrecisionReal methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   801
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   802
printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   803
    "append a printed representation of the receiver to
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   804
     the argument, aStream.
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   805
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   806
     LimitedPrecisonReal and its subclasses use #printString instead of
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   807
     #printOn: as basic print mechanism."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   808
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   809
    aStream nextPutAll:self printString
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   810
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   811
    "Modified: / 20.1.1998 / 14:10:46 / stefan"
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   812
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   813
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   814
printString
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   815
    "return a printed representation of the receiver
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   816
     LimitedPrecisonReal and its subclasses use #printString instead of
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   817
     #printOn: as basic print mechanism."
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   818
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   819
    ^ self subclassResponsibility
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   820
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   821
    "Created: / 17.4.1996 / 12:12:20 / cg"
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   822
    "Modified: / 20.1.1998 / 14:10:47 / stefan"
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   823
!
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   824
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   825
storeOn:aStream
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   826
    "append a printed representation of the receiver to
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   827
     the argument, aStream.
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   828
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   829
     LimitedPrecisonReal and its subclasses use #storeString instead of
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   830
     #storeOn: as basic store mechanism."
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   831
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   832
    aStream nextPutAll:self storeString
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   833
!
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   834
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   835
storeString
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   836
    "return a printed representation of the receiver
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   837
     LimitedPrecisonReal and its subclasses use #storeString instead of
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   838
     #storeOn: as basic print mechanism."
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   839
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   840
    ^ self subclassResponsibility
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   841
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   842
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   843
!LimitedPrecisionReal methodsFor:'queries'!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   844
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   845
defaultNumberOfDigits
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   846
    "Answer how many digits of accuracy this class supports"
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   847
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   848
    ^ self class decimalPrecision - 1 
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   849
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   850
    "
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   851
        Float new defaultNumberOfDigits
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   852
        LongFloat new defaultNumberOfDigits
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   853
        ShortFloat new defaultNumberOfDigits
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   854
    "
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   855
!
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   856
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   857
precision
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   858
    "return the number of valid mantissa bits.
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   859
     Should be redefined in classes which allow per-instance precision specification"
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   860
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   861
    ^ self class precision
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   862
!
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   863
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   864
size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   865
   "redefined since reals are kludgy (ByteArry)"
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   866
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   867
   ^ 0
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   868
! !
5470
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   869
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   870
!LimitedPrecisionReal methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   871
3148
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   872
isFinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   873
   ^ self subclassResponsibility
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   874
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   875
    "Created: / 7.1.1998 / 12:02:06 / stefan"
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   876
!
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   877
6185
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   878
isFloat
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   879
    "return true, if the receiver is some kind of floating point number;
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   880
     false is returned here.
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   881
     Same as #isLimitedPrecisionReal, but a better name ;-)"
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   882
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   883
    ^ true
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   884
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   885
    "Created: / 14.11.2001 / 14:57:55 / cg"
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   886
!
2029fdbadfde +isFloat
Claus Gittinger <cg@exept.de>
parents: 6086
diff changeset
   887
3148
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   888
isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   889
    "return true, if the receiver is an infinite float (Inf).
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   890
     These are not created by ST/X float operations (they raise an exception);
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   891
     however, inline C-code could produce them ..."
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   892
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   893
    ^ (self isFinite or:[self isNaN]) not.
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   894
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   895
    "
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   896
        1.0 isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   897
        (0.0 uncheckedDivide: 0.0) isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   898
        (1.0 uncheckedDivide: 0.0) isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   899
    "
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   900
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   901
    "Modified: / 7.1.1998 / 12:01:30 / stefan"
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   902
!
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   903
6086
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   904
isLimitedPrecisionReal
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   905
    "return true, if the receiver is some kind of limited precision real (i.e. floating point) number;
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   906
     true is returned here - the method is redefined from Object."
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   907
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   908
    ^ true
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   909
!
0bd476397581 added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents: 5989
diff changeset
   910
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   911
isNaN
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   912
   ^ self subclassResponsibility
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   913
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   914
    "Modified: 12.2.1997 / 16:45:27 / cg"
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   915
!
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   916
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6641
diff changeset
   917
isNegativeZero
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6641
diff changeset
   918
    "many systems have two float.Pnt zeros"
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6641
diff changeset
   919
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   920
    ^ (self isZero) and:[self printString first == $-]
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6641
diff changeset
   921
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6641
diff changeset
   922
    "
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   923
     0.0 asLongFloat isNegativeZero     
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   924
     -0.0 asLongFloat isNegativeZero       
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   925
     -1.0 asLongFloat isNegativeZero       
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   926
     1.0 asLongFloat isNegativeZero       
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   927
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   928
     0.0 asLargeFloat isNegativeZero     
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   929
     -0.0 asLargeFloat isNegativeZero       
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   930
    "
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   931
    "
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   932
     0.0 asLongFloat isZero                      
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   933
     -0.0 asLongFloat isZero       
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   934
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   935
     0.0 > 0   
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   936
     -0.0 < 0       
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   937
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   938
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   939
5357
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   940
numberOfBits
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   941
    "return the size (in bits) of the real;
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   942
     typically, this is 64 for Floats and 32 for ShortFloats,
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   943
     but who knows ..."
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   944
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   945
    self subclassResponsibility
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   946
!
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   947
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   948
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   949
    "return true if the receiver is greater or equal to zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   950
7447
64fab8614c76 double dispatching, converting
Claus Gittinger <cg@exept.de>
parents: 7418
diff changeset
   951
    ^ self sign >= 0
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   952
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   953
    "Modified: 17.4.1996 / 13:35:10 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   954
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   955
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   956
!LimitedPrecisionReal methodsFor:'truncation & rounding'!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   957
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   958
ceilingAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   959
    ^ self coerce:(self ceiling).
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   960
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   961
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   962
     0.4 asLongFloat ceilingAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   963
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   964
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   965
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   966
floorAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   967
    ^ self coerce:(self floor).
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   968
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   969
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   970
     0.4 asLongFloat floorAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   971
    "
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   972
!
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   973
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   974
roundedAsFloat
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   975
    self negative ifTrue:[ ^ (self - 0.5) ceilingAsFloat ].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   976
    ^ (self + 0.5) floorAsFloat
7398
0f96525b931e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7394
diff changeset
   977
!
0f96525b931e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7394
diff changeset
   978
0f96525b931e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7394
diff changeset
   979
truncatedAsFloat
0f96525b931e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7394
diff changeset
   980
    ^ self coerce:(self truncated).
0f96525b931e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7394
diff changeset
   981
0f96525b931e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7394
diff changeset
   982
    "
0f96525b931e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7394
diff changeset
   983
     0.4 asLongFloat truncatedAsFloat
0f96525b931e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7394
diff changeset
   984
    "
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   985
! !
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7141
diff changeset
   986
8395
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8202
diff changeset
   987
!LimitedPrecisionReal methodsFor:'visiting'!
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8202
diff changeset
   988
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8202
diff changeset
   989
acceptVisitor:aVisitor with:aParameter
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8202
diff changeset
   990
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8202
diff changeset
   991
    ^ aVisitor visitFloat:self with:aParameter
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8202
diff changeset
   992
! !
6bd97113cb4c Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents: 8202
diff changeset
   993
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   994
!LimitedPrecisionReal class methodsFor:'documentation'!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   995
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   996
version
8422
c206b4711b6e Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents: 8395
diff changeset
   997
    ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.61 2004-06-29 13:20:30 stefan Exp $'
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   998
! !
6890
8e74eff54c3d added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents: 6641
diff changeset
   999
5989
8e3ff880f561 ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1000
LimitedPrecisionReal initialize!