LPReal.st
author Claus Gittinger <cg@exept.de>
Sat, 16 Dec 1995 14:04:33 +0100
changeset 778 afbb3ebde874
parent 701 a309e3ef7faf
child 1200 cc16f7a00b52
permissions -rw-r--r--
commentary
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
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    13
Number subclass:#LimitedPrecisionReal
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    14
	 instanceVariableNames:''
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    15
	 classVariableNames:''
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    16
	 poolDictionaries:''
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    17
	 category:'Magnitude-Numbers'
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    18
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    19
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    20
!LimitedPrecisionReal class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    21
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
 COPYRIGHT (c) 1994 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
    25
	      All Rights Reserved
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    26
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    35
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
documentation
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
    Abstract superclass for single and double (and maybe more) 
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
    precision real numbers (i.e. Float and Double).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    40
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    41
    Due to historic reasons, ST/X's Floats are what Doubles are in ST-80.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    42
    This may change soon (implementing LPReal is a first step towards this).
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    43
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    44
! !
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    45
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    46
!LimitedPrecisionReal class methodsFor:'instance creation'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    47
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    48
new:aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    49
    "catch this message - not allowed for floats/doubles"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    50
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    51
    self error:'Floats/Doubles cannot be created with new:'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    52
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    53
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    54
!LimitedPrecisionReal methodsFor:'accessing'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    56
at:index
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    57
    "redefined to prevent access to individual bytes in a real."
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    58
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    59
    self error:'not allowed for floats/doubles'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    60
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    61
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    62
at:index put:aValue
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    63
    "redefined to prevent access to individual bytes in a real"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    64
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    65
    self error:'not allowed for floats/doubles'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    66
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    67
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    68
size
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    69
   "redefined since reals are kludgy (ByteArry)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    70
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    71
   ^ 0
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    72
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    73
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    74
!LimitedPrecisionReal methodsFor:'arithmetic'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    75
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    76
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    77
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    78
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    79
    ^ aNumber productFromDouble:self asDouble
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    80
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    81
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    82
+ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    83
    "return the sum of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    84
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    85
    ^ aNumber sumFromDouble:self asDouble
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    86
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    87
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    88
- aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    89
    "return the difference of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    90
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    91
    ^ aNumber differenceFromDouble:self asDouble
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    92
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    93
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    94
/ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    95
    "return the quotient of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    96
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    97
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
    98
	^ DivisionByZeroSignal raise.
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    99
    ].
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   100
    ^ aNumber quotientFromDouble:self asDouble
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   101
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   102
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   103
// aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   104
    "return the integer quotient of dividing the receiver by aNumber with
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   105
    truncation towards negative infinity."
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   106
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   107
    ^ (self / aNumber) floor asInteger
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   108
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   109
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   110
\\ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   111
    "return the integer remainder of dividing the receiver by aNumber with
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   112
    truncation towards negative infinity."
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   113
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   114
    ^ (self - ((self / aNumber) floor * aNumber)) floor asInteger
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   115
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   116
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   117
!LimitedPrecisionReal methodsFor:'coercion and converting'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   118
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   119
asFraction
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   120
    "return a corresponding fraction
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   121
     - notice, that 'aFract asFloat asFraction' does not always return
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   122
     a good fraction ... due to rounding errors when converting to float"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   123
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   124
    |fract digits power num denom|
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   125
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   126
    "we (indirectly) use printf which knows the precision of floats"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   127
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   128
    fract := self fractionPart.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   129
    digits := fract printString copyFrom:3.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   130
    power := digits size.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   131
    num := (self - fract) asInteger.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   132
    denom := (10 raisedToInteger:power).
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   133
    num := num * denom.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   134
    num := num + (Integer readFromString:digits).
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   135
    ^ (Fraction numerator:num denominator:denom) reduced
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   136
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   137
    "0.3 asFraction"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   138
    "0.5 asFraction"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   139
    "(1/5) asFloat asFraction"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   140
    "(1/8) asFloat asFraction"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   141
    "(1/13) asFloat asFraction -> inexact result due to rounding errors"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   142
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   143
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   144
asInteger
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   145
    "return an integer with same value - might truncate"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   146
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   147
    |l v sign|
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   148
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   149
    "this is stupid code - rounding errors accumulate; fix later"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   150
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   151
    sign := self sign.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   152
    v := self abs.
85
claus
parents: 55
diff changeset
   153
    (v >= 10.0) ifTrue:[
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   154
	l := (v / 10.0) asInteger * 10
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   155
    ] ifFalse:[
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   156
	l := 0
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   157
    ].
85
claus
parents: 55
diff changeset
   158
    v := v - ((v / 10.0) floor * 10) floor.
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   159
    l := l + v truncated.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   160
    ^ l * sign
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   161
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   162
    "12345.0 asInteger"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   163
    "1e15 asInteger"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   164
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   165
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   166
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   167
    "return aNumber converted into receivers type"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   168
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   169
    ^ aNumber asDouble
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   170
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   171
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   172
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   173
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   174
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   175
    ^ 80
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   176
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   177
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   178
!LimitedPrecisionReal methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   179
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   181
    "return true, if the argument is greater"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   182
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
    ^ aNumber lessFromDouble:self asDouble
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   184
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   185
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   186
<= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   187
    "return true, if the argument is greater or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   188
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   189
    ^ self retry:#<= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   190
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   191
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   192
= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   193
    "return true, if the arguments value are equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   194
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   195
    ^ self retry:#= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   196
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   197
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   198
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   199
    "return true, if the argument is less"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   200
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   201
    ^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   202
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   203
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   204
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   205
    "return true, if the argument is less or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   206
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   207
    ^ self retry:#>= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   208
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   209
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   210
~= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   211
    "return true, if the arguments value are not equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   212
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   213
    ^ self retry:#~= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   214
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   215
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   216
!LimitedPrecisionReal methodsFor:'copying'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   217
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   218
deepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   219
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   220
     - 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
   221
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   222
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   223
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   224
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   225
deepCopyUsing:aDictionary
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   226
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
     - 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
   228
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   229
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   230
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   231
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   232
shallowCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   233
    "return a shallow copy of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   234
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   235
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   236
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   237
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   238
simpleDeepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   239
    "return a deep copy of the receiver
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   240
     - 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
   241
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   242
    ^ self
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
!LimitedPrecisionReal methodsFor:'double dispatching'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   246
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   247
differenceFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   248
    "sent when a fraction does not know how to subtract the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   249
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   250
    |d|
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   251
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   252
    d := aFraction denominator.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   253
    ^ (aFraction numerator - (self * d)) / d
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   254
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   255
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   256
productFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   257
    "sent when a fraction does not know how to multiply the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   258
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   259
    ^ self * aFraction numerator / aFraction denominator
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   260
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   261
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   262
quotientFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   263
    "sent when a fraction does not know how to divide by the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   264
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   265
    ^ aFraction numerator / (self * aFraction denominator)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   266
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   267
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   268
sumFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   269
    "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
   270
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   271
    |d|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   272
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   273
    d := aFraction denominator.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   274
    ^ (self * d + aFraction numerator) / d
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   275
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   276
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   277
!LimitedPrecisionReal methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   278
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   279
printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   280
    "append a printed representation of the receiver to
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   281
     the argument, aStream"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   282
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   283
    aStream nextPutAll:self printString
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   284
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   285
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   286
!LimitedPrecisionReal methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   288
isReal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   289
    "return true, if the receiver is some kind of real number;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   290
     false is returned here - the method is redefined from Object."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   291
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   292
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   293
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   294
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   295
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
    "return true if the receiver is less than zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   297
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   298
    ^ self asDouble negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
    "return true if the receiver is greater or equal to zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
    ^ self asDouble positive
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   305
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   306
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   307
!LimitedPrecisionReal methodsFor:'truncation and rounding'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   308
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   309
fractionPart
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   310
    "return a float with value from digits after the decimal point"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   311
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   312
    ^ self - self truncated asFloat
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   313
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   314
    "1234.56789 fractionPart"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   315
    "1.2345e6 fractionPart"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   316
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   317
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   318
!LimitedPrecisionReal class methodsFor:'documentation'!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   319
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   320
version
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   321
    ^ '$Header: /cvs/stx/stx/libbasic/Attic/LPReal.st,v 1.11 1995-12-07 21:35:42 cg Exp $'
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   322
! !