LimitedPrecisionReal.st
author Claus Gittinger <cg@exept.de>
Tue, 31 Jul 2001 17:10:05 +0200
changeset 5897 793b0adad934
parent 5883 658ff91cef9e
child 5954 d706efecb134
permissions -rw-r--r--
checkin from browser
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
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    40
    Abstract superclass for single and double (and maybe more) 
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
    precision real numbers (i.e. Float and Double).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    42
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    43
    Due to historic reasons, ST/X's Floats are what Doubles are in ST-80.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    44
    This may change soon (implementing LPReal is a first step towards this).
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    45
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    46
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    47
        Claus Gittinger
1893
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    48
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    49
    [see also:]
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    50
        Fraction FixedPoint
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    51
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    52
! !
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    53
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    54
!LimitedPrecisionReal class methodsFor:'instance creation'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    56
new:aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    57
    "catch this message - not allowed for floats/doubles"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    58
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    59
    self error:'Floats/Doubles cannot be created with new:'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    60
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    61
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    62
!LimitedPrecisionReal methodsFor:'accessing'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    63
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    64
at:index
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    65
    "redefined to prevent access to individual bytes in a real."
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    66
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    67
    self error:'not allowed for floats/doubles'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    68
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    69
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    70
at:index put:aValue
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    71
    "redefined to prevent access to individual bytes in a real"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    72
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    73
    self error:'not allowed for floats/doubles'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    74
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    75
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    76
!LimitedPrecisionReal methodsFor:'arithmetic'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    77
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    78
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    79
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    80
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    81
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    82
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    83
"/    ^ aNumber productFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    84
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    85
    ^ aNumber productFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    86
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    87
    "Modified: 17.4.1996 / 12:35:36 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    88
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    89
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    90
+ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    91
    "return the sum of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    92
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    93
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    94
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    95
"/    ^ aNumber sumFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    96
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    97
    ^ aNumber sumFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    98
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    99
    "Modified: 17.4.1996 / 12:35:55 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   100
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   101
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   102
- aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   103
    "return the difference of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   104
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   105
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   106
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   107
"/    ^ aNumber differenceFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   108
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   109
    ^ aNumber differenceFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   110
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   111
    "Modified: 17.4.1996 / 12:36:07 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   112
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   113
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   114
/ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   115
    "return the quotient of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   116
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   117
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
4455
2d31d0d986be Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 3898
diff changeset
   118
        ^ DivisionByZeroSignal raiseRequest.
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   119
    ].
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   120
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   121
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   122
"/    ^ aNumber quotientFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   123
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   124
    ^ aNumber quotientFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   125
4455
2d31d0d986be Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 3898
diff changeset
   126
    "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
   127
    "Modified: / 26.7.1999 / 10:46:11 / stefan"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   128
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   129
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   130
// aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   131
    "return the integer quotient of dividing the receiver by aNumber with
1882
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   132
     truncation towards negative infinity."
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   133
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   134
    ^ (self / aNumber) floor asInteger
1882
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   135
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   136
    "Modified: 5.11.1996 / 11:45:37 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   137
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   138
5238
f7a816a660a3 categories
Claus Gittinger <cg@exept.de>
parents: 4615
diff changeset
   139
!LimitedPrecisionReal methodsFor:'coercing & converting'!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   140
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   141
asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   142
    "return the receiver as fixedPoint number.
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   143
     Q: what should the scale be here ?"
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   144
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   145
    ^ self asFraction asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   146
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   147
    "
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   148
     0.3 asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   149
     0.5 asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   150
     (1/5) asFloat asFixedPoint 
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   151
     (1/3) asFloat asFixedPoint 
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   152
     (2/3) asFloat asFixedPoint 
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   153
     (1/8) asFloat asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   154
     3.14159 asFixedPoint
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   155
     0.0000001 asFraction
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   156
     0.0000001 asFixedPoint
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   157
    "
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   158
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   159
    "Modified: / 25.10.1997 / 15:36:54 / cg"
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   160
!
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   161
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   162
asFixedPoint:scale
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   163
    "return the receiver as fixedPoint number with the given
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   164
     number of post-decimal-digits."
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   165
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   166
    ^ self asFraction asFixedPoint:scale
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   167
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   168
    "
3732
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   169
     0.3 asFixedPoint:4     
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   170
     0.3 asFixedPoint:3     
3732
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   171
     0.3 asFixedPoint:2     
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   172
     0.3 asFixedPoint:1     
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   173
     0.3 asFixedPoint:0
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   174
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   175
     0.5 asFixedPoint:3     
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   176
     (1/5) asFloat asFixedPoint:1  
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   177
     (1/8) asFloat asFixedPoint:1  
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   178
     3.14159 asFixedPoint:2       
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   179
     3.14159 asFixedPoint:3       
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   180
     (3.14159 asFixedPoint:2) asFixedPoint:5  
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   181
    "
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   182
3732
bf041aa09cc4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3426
diff changeset
   183
    "Modified: / 5.8.1998 / 13:29:51 / cg"
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   184
!
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   185
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   186
asFraction
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   187
    "Answer a rational number (Integer or Fraction) representing the receiver.
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   188
     This conversion uses the continued fraction method to approximate 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   189
     a floating point number."
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   190
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   191
    |num1 denom1 num2 denom2 int frac newD temp limit|
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   192
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   193
    limit := (self class unity * 10) raisedTo:self defaultNumberOfDigits.
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   194
    num1 := self truncated. 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   195
    denom1 := 1.            "The first of two alternating denominators"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   196
    num2 := 1.              "The second numerator"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   197
    denom2 := 0.            "The second denominator--will update"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   198
    int := num1.            "The integer part of self"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   199
    frac := self fractionPart.             
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   200
    [frac = 0] whileFalse:[                
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   201
        newD := 1.0 / frac.                   
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   202
        int := newD truncated.        
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   203
        frac := newD fractionPart.      "save the fractional part for next time"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   204
        temp := num2.                   "old numerator and save it"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   205
        num2 := num1.                         
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   206
        num1 := num1 * int + temp.      "Update first numerator"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   207
        temp := denom2.                 "old denominator and save it"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   208
        denom2 := denom1.                    
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   209
        denom1 := int * denom1 + temp.  "Update first denominator"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   210
        limit < denom1 ifTrue:[
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   211
            "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
   212
            num2 = 0.0 ifTrue:[
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   213
                "Is second denominator 0?"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   214
                ^ Fraction numerator:num1 denominator:denom1
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   215
            ].
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   216
            ^ Fraction numerator:num2 denominator:denom2
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   217
        ]
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   218
    ].
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   219
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   220
    "If fractional part is zero, return the first ratio"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   221
    denom1 = 1 ifTrue:[
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   222
        "Am i really an Integer?"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   223
        ^ num1 "Yes, return Integer result"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   224
    ].
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   225
    "Otherwise return Fraction result"
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   226
    ^ Fraction numerator:num1 denominator:denom1
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   227
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   228
    "
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   229
     1.1 asFraction      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   230
     1.2 asFraction      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   231
     0.3 asFraction   
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   232
     0.5 asFraction 
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   233
     (1/5) asFloat asFraction
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   234
     (1/8) asFloat asFraction  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   235
     (1/13) asFloat asFraction 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   236
     3.14159 asFraction        
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   237
     3.14159 asFraction asFloat       
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   238
     1.3 asFraction  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   239
     1.0 asFraction  
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   240
    "
2793
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2388
diff changeset
   241
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
   242
    "Modified: / 25.10.1997 / 16:41:19 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   243
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   244
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   245
asInteger
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   246
    "return an integer with same value - might truncate"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   247
3185
1c7bd090a822 removed unused local vars
Claus Gittinger <cg@exept.de>
parents: 3148
diff changeset
   248
    |max maxF|
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   249
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   250
    self isNaN ifTrue:[
3395
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   251
        ^ self class
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   252
            raise:#domainErrorSignal
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   253
            receiver:self
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   254
            selector:#asInteger
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   255
            errorString:'receiver is NaN in #asInteger'
02f47135d80f pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents: 3225
diff changeset
   256
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   257
    ].
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   258
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   259
    self abs < 2e16 ifTrue:[
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   260
        "/ NOTICE: this must be redefined in float
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   261
        "/ subclasses to handle the smallinteger range;
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   262
        "/ i.e. this may only be invoked for reals
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   263
        "/ which are NOT within the smallInt range.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   264
        "/ otherwise, endless recursion is the consequence.
3426
a648de89ac72 comment
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
   265
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   266
        max := SmallInteger maxVal // 2 + 1.
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   267
        maxF := max asFloat.
3426
a648de89ac72 comment
Claus Gittinger <cg@exept.de>
parents: 3395
diff changeset
   268
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   269
        ^ (self quo:maxF) * max + (self rem:maxF) truncated
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   270
    ].
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   271
    ^ self asTrueFraction
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   272
3137
f334b17f0347 bif speedup in asInteger with large floats
ca
parents: 3060
diff changeset
   273
    "
4615
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   274
     12345.0 asInteger     
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   275
     1e15 asInteger        
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   276
     1e33 asInteger asFloat
e480d1e6090f largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents: 4455
diff changeset
   277
     1e303 asInteger asFloat
3137
f334b17f0347 bif speedup in asInteger with large floats
ca
parents: 3060
diff changeset
   278
    "
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   279
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   280
    "Modified: 12.2.1997 / 16:45:07 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   281
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   282
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   283
asRational
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   284
    "Answer a Rational number--Integer or Fraction--representing the receiver.
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   285
     Same as asFraction fro st-80 compatibility."
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   286
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   287
    ^ self asFraction
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   288
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   289
    "
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   290
     1.1 asRational      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   291
     1.2 asRational      
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   292
     0.3 asRational   
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   293
     0.5 asRational 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   294
     (1/5) asFloat asRational
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   295
     (1/8) asFloat asRational  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   296
     (1/13) asFloat asRational 
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   297
     3.14159 asRational        
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   298
     3.14159 asRational asFloat       
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   299
     1.3 asRational  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   300
     1.0 asRational  
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   301
    "
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   302
!
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   303
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
    "return aNumber converted into receivers type"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   306
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   307
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   308
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   309
"/    ^ aNumber asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   310
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   311
    ^ aNumber asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   312
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   313
    "Modified: 17.4.1996 / 12:36:46 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   314
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   315
3898
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   316
fractionalPart
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   317
    "This has been renamed to #fractionPart for ST80 compatibility.
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   318
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   319
     extract the after-decimal fraction part.
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   320
     the floats value is 
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   321
        float truncated + float fractionalPart"
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   322
5868
d497030b1df7 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
   323
    <resource:#obsolete>
d497030b1df7 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
   324
3898
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   325
    self obsoleteMethodWarning:'please use #fractionPart'.
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   326
    ^ self fractionPart
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   327
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   328
    "Modified: / 28.10.1998 / 17:10:12 / cg"
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   329
    "Created: / 28.10.1998 / 17:10:32 / cg"
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   330
!
818a12afad05 moved methods around
Claus Gittinger <cg@exept.de>
parents: 3732
diff changeset
   331
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   332
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   333
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   334
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   335
    ^ 80
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   337
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   338
!LimitedPrecisionReal methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   339
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   340
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   341
    "return true, if the argument is greater"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   342
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   343
"/ 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
   344
"/ use:
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   345
"/    ^ aNumber lessFromDouble:self asDouble
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   346
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   347
    ^ aNumber lessFromFloat:self asFloat
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   348
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   349
    "Modified: 17.4.1996 / 13:34:50 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   350
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   351
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   352
<= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   353
    "return true, if the argument is greater or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   354
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   355
    ^ self retry:#<= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   356
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   357
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   358
= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   359
    "return true, if the arguments value are equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   360
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   361
    ^ self retry:#= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   362
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   363
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   364
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   365
    "return true, if the argument is less"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   366
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   367
    ^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   368
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   369
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   370
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   371
    "return true, if the argument is less or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   372
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   373
    ^ self retry:#>= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   374
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   375
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   376
~= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   377
    "return true, if the arguments value are not equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   378
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   379
    ^ self retry:#~= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   380
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   381
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   382
!LimitedPrecisionReal methodsFor:'copying'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   383
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   384
deepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   385
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   386
     - 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
   387
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   388
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   389
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   390
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   391
deepCopyUsing:aDictionary
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   392
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   393
     - 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
   394
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   395
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   396
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   397
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   398
shallowCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   399
    "return a shallow copy of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   400
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   401
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   402
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   403
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   404
simpleDeepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   405
    "return a deep copy of the receiver
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   406
     - 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
   407
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   408
    ^ self
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   409
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   410
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   411
!LimitedPrecisionReal methodsFor:'double dispatching'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   412
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   413
differenceFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   414
    "sent when a fraction does not know how to subtract the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   415
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   416
    |d|
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   417
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   418
    d := aFraction denominator.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   419
    ^ (aFraction numerator - (self * d)) / d
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   420
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   421
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   422
productFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   423
    "sent when a fraction does not know how to multiply the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   424
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   425
    ^ self * aFraction numerator / aFraction denominator
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   426
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   427
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   428
quotientFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   429
    "sent when a fraction does not know how to divide by the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   430
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   431
    ^ aFraction numerator / (self * aFraction denominator)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   432
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   433
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   434
sumFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   435
    "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
   436
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   437
    |d|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   438
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   439
    d := aFraction denominator.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   440
    ^ (self * d + aFraction numerator) / d
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   441
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   442
5470
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   443
!LimitedPrecisionReal methodsFor:'encoding'!
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   444
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   445
encodeOn:anEncoder with:aParameter
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   446
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   447
    anEncoder encodeFloat:self with:aParameter
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   448
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   449
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   450
! !
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   451
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   452
!LimitedPrecisionReal methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   453
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   454
printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   455
    "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
   456
     the argument, aStream.
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   457
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   458
     LimitedPrecisonReal and its subclasses use #printString instead of
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   459
     #printOn: as basic print mechanism."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   460
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   461
    aStream nextPutAll:self printString
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   462
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   463
    "Modified: / 20.1.1998 / 14:10:46 / stefan"
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   464
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   465
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   466
printString
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   467
    "return a printed representation of the receiver
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   468
     LimitedPrecisonReal and its subclasses use #printString instead of
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   469
     #printOn: as basic print mechanism."
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   470
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   471
    ^ self subclassResponsibility
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   472
3194
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   473
    "Created: / 17.4.1996 / 12:12:20 / cg"
16073834a825 Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents: 3185
diff changeset
   474
    "Modified: / 20.1.1998 / 14:10:47 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   475
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   476
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   477
!LimitedPrecisionReal methodsFor:'queries'!
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   478
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   479
defaultNumberOfDigits
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   480
    self subclassResponsibility
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   481
!
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   482
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   483
size
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   484
   "redefined since reals are kludgy (ByteArry)"
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   485
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   486
   ^ 0
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 5470
diff changeset
   487
! !
5470
5e56d8cff0c9 General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents: 5357
diff changeset
   488
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   489
!LimitedPrecisionReal methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   490
3148
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   491
isFinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   492
   ^ self subclassResponsibility
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   493
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   494
    "Created: / 7.1.1998 / 12:02:06 / stefan"
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   495
!
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   496
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   497
isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   498
    "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
   499
     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
   500
     however, inline C-code could produce them ..."
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   501
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   502
    ^ (self isFinite or:[self isNaN]) not.
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   503
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   504
    "
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   505
        1.0 isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   506
        (0.0 uncheckedDivide: 0.0) isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   507
        (1.0 uncheckedDivide: 0.0) isInfinite
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   508
    "
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   509
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   510
    "Modified: / 7.1.1998 / 12:01:30 / stefan"
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   511
!
1434542209e7 New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents: 3137
diff changeset
   512
2388
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   513
isNaN
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   514
   ^ self subclassResponsibility
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   515
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   516
    "Modified: 12.2.1997 / 16:45:27 / cg"
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   517
!
df5e0eb88999 added isNaN-check
Claus Gittinger <cg@exept.de>
parents: 2141
diff changeset
   518
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   519
isReal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   520
    "return true, if the receiver is some kind of real number;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   521
     false is returned here - the method is redefined from Object."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   522
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   523
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   524
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   525
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   526
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   527
    "return true if the receiver is less than zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   528
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   529
"/ 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
   530
"/ use:
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   531
"/    ^ self asDouble negative
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   532
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   533
    ^ self asFloat negative
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   534
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   535
    "Modified: 17.4.1996 / 13:35:00 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   536
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   537
5357
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   538
numberOfBits
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   539
    "return the size (in bits) of the real;
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   540
     typically, this is 64 for Floats and 32 for ShortFloats,
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   541
     but who knows ..."
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   542
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   543
    self subclassResponsibility
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   544
!
39860dd8b0f5 query for number of bits
ps
parents: 5238
diff changeset
   545
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   546
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   547
    "return true if the receiver is greater or equal to zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   548
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   549
"/ 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
   550
"/ use:
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   551
"/    ^ self asDouble positive
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   552
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   553
    ^ self asFloat positive
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   554
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   555
    "Modified: 17.4.1996 / 13:35:10 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   556
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   557
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   558
!LimitedPrecisionReal class methodsFor:'documentation'!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   559
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   560
version
5883
658ff91cef9e fixed asFraction
Claus Gittinger <cg@exept.de>
parents: 5868
diff changeset
   561
    ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.38 2001-06-26 14:03:35 cg Exp $'
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   562
! !