FixedPoint.st
author Claus Gittinger <cg@exept.de>
Thu, 20 Jul 2006 22:43:19 +0200
changeset 9452 921f2690dfe6
parent 9137 9692c2409b38
child 10192 7346a254d672
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
     2
     This is public domain code, not covered by the ST/X copyright.
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
     3
     Code is provided 'as is', as a goody, without any warranty.
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
     4
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
     this comes from:
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
     Jan Steinman, Bytesmiths
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
     2002 Parkside Court, West Linn, OR 97068-2767 USA, +1 503 657 7703
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
     Friedlistrasse 19, CH-3006, Bern, Switzerland, +41 31 999 3946
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
     this code was published in comp.lang.smalltalk; 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
     added here as an example ...
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
5570
e6e14f50d721 category change
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
    15
"{ Package: 'stx:libbasic' }"
e6e14f50d721 category change
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
    16
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
Fraction subclass:#FixedPoint
6895
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
    18
	instanceVariableNames:'scale'
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
    19
	classVariableNames:'PI_1000 PrintTruncated'
6895
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
    20
	poolDictionaries:''
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
    21
	category:'Magnitude-Numbers'
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
FixedPoint comment:'
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
Description: This class implements infinite precision fixed-point numbers. 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
It doesn''t really do anything too interesting except creating instances, converting, and printing, 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
since its superclass Fraction does all the work.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
Test: "''123456789012345678901234567890.123456789'' asFixed * 1000000000 = 123456789012345678901234567890123456789"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
Notes: 1) The current implementation does not convert arbitrarily-based String representations, 
6704
abdf0002a791 oops - I messed mixed arithmetic up
penk
parents: 6650
diff changeset
    32
          which shouldn''t be too much a problem for financial types.'
6237
4dc908af4f5c report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents: 5570
diff changeset
    33
!
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!FixedPoint class methodsFor:'documentation'!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
copyright
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
    39
     This is public domain code, not covered by the ST/X copyright.
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
    40
     Code is provided 'as is', as a goody, without any warranty.
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
    41
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
     this comes from:
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
     Jan Steinman, Bytesmiths
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
     2002 Parkside Court, West Linn, OR 97068-2767 USA, +1 503 657 7703
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
     Friedlistrasse 19, CH-3006, Bern, Switzerland, +41 31 999 3946
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
     this code was published in comp.lang.smalltalk; 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
     added here as an example ...
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
documentation
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
"
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7376
diff changeset
    55
    This class implements infinite precision fixed-point numbers,
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    which internally hold exact (fractional) results, but print themself with
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
    57
    a limited number of digits after the decimal point (rounded). 
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
    58
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
    59
    NOTICE:
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
    60
        it seems that squeak prints these truncated,
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
    61
        whereas ST/X prints them rounded.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
    62
        This behavior should probably be controllable by providing      
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
    63
        a subclass (RoundedFixedPoint ?) which redefines the printOn: method.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
    64
        (it is now controlled by a classVar, which is of course not a thread-safe
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
    65
        solution).
7380
c704ff45bb80 documentation
Claus Gittinger <cg@exept.de>
parents: 7376
diff changeset
    66
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    These can be used in computation, where rounding errors should not accumulate,
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    but only a limited precision is required for the final result.
1898
883a1046ca9a commentary
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
    69
    (i.e. business applications)
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    It doesn't really do anything too interesting except creating instances, 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    converting, and printing, since its superclass Fraction does all the work.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    Test: 
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
    75
        '123456789012345678901234567890.123456789' asFixedPoint * 1000000000
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
        -> 123456789012345678901234567890123456789'
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    Notes: 1) The current implementation does not convert arbitrarily-based 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
              String representations, which shouldn't be too much a problem 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
              for financial types.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
           2) the implementation is a hack - it has not been optimized for speed
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
              in particular.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
    85
    Mixed mode arithmetic:
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
    86
        fix op fix       -> fix, scale is max. of operands
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
    87
        fix op fraction  -> fix; scale is fix's scale
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
    88
        fix op integer   -> fix; scale is fix's scale
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
    89
        fix op float     -> float
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
    90
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    [author:]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
        Jan Steinman, Bytesmiths
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
    93
        adapted, modified & enhanced by Claus Gittinger
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    [see also:]
9129
f1451239cd4b comment
Claus Gittinger <cg@exept.de>
parents: 7442
diff changeset
    96
        Number Fraction Integer Float ShortFloat LongFloat Complex
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
examples
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
                                                                [exBegin]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
     a := (FixedPoint fromString:'123.456').
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   106
     b := '1.10' asFixedPoint.
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
     r := a + b.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
     Transcript showCR:r.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
     Transcript showCR:(r withScale:1).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
     Transcript showCR:(r rounded).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
                                                                [exEnd]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
                                                                [exBegin]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
     a := (FixedPoint fromString:'0.9999999').
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   118
     b := 0.0000001 asFixedPoint. 
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
     r := a + b.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
     Transcript showCR:r.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
     Transcript showCR:(r withScale:1).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
     Transcript showCR:(r rounded).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
                                                                [exEnd]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
                                                                [exBegin]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
     a := (FixedPoint fromString:'0.9999998').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
     r := a + b.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
     Transcript showCR:r.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
     Transcript showCR:(r withScale:1).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
     Transcript showCR:(r rounded).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
                                                                [exEnd]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
                                                                [exBegin]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
     a := (FixedPoint fromString:'1.0').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
     r := a + b.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
     Transcript showCR:r.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
     Transcript showCR:(r withScale:1).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
     Transcript showCR:(r rounded).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
                                                                [exEnd]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
                                                                [exBegin]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
     a := (FixedPoint fromString:'0.99').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
     r := a + b.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
     Transcript showCR:r.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
     Transcript showCR:(r withScale:1).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
     Transcript showCR:(r rounded).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
                                                                [exEnd]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
! !
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
!FixedPoint class methodsFor:'instance creation'!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
6237
4dc908af4f5c report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents: 5570
diff changeset
   167
numerator:n denominator:d 
4dc908af4f5c report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents: 5570
diff changeset
   168
    self shouldNotImplement. "use #numerator:denominator:scale"
4dc908af4f5c report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents: 5570
diff changeset
   169
    "/ ^ self numerator:n denominator:d scale:(d log max:n log) ceiling
4dc908af4f5c report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents: 5570
diff changeset
   170
4dc908af4f5c report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents: 5570
diff changeset
   171
    "
4dc908af4f5c report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents: 5570
diff changeset
   172
     self numerator:123 denominator:100    
4dc908af4f5c report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents: 5570
diff changeset
   173
    "
4dc908af4f5c report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents: 5570
diff changeset
   174
!
4dc908af4f5c report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents: 5570
diff changeset
   175
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
numerator:n denominator:d scale:s
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
    ^ self basicNew
6894
64f27ed2753f do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents: 6886
diff changeset
   178
        setNumerator:n denominator:d scale:s
64f27ed2753f do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents: 6886
diff changeset
   179
        "/ ; reduced
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   182
readFrom:aStringOrStream 
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   183
    "return the next FixedPoint from the (character-)stream aStream. 
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   184
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   185
     NOTICE:   
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   186
       This behaves different from the default readFrom:, in returning
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   187
       0 (instead of raising an error) in case no number can be read.
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   188
       It is unclear, if this is the correct behavior (ST-80 does this)
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   189
       - depending on the upcoming ANSI standard, this may change."
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   190
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   191
    ^ self readFrom:aStringOrStream onError:0
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   193
    "
6636
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   194
     FixedPoint readFrom:'123.456'
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   195
     FixedPoint readFrom:'3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788'
3060
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   196
     FixedPoint readFrom:(ReadStream on:'foobar')     
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   197
     FixedPoint readFrom:(ReadStream on:'foobar') onError:nil  
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   198
    "
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   199
0faf242e1142 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2563
diff changeset
   200
    "Modified: / 25.10.1997 / 15:30:29 / cg"
6895
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   201
!
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   202
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   203
readFrom:aStringOrStream onError:exceptionBlock
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   204
    "return an instance of me as described on the string or stream, aStringOrStream.
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   205
     If an error occurs during conversion, return the result
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   206
     from evaluating exceptionBlock"
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   207
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   208
    | aStream sign integerPart fractionStream char fractionPart scale |
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   209
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   210
    aStream := aStringOrStream readStream.
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   211
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   212
    aStream peek == $- ifTrue:[
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   213
        sign := -1.
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   214
        aStream next.
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   215
    ] ifFalse:[
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   216
        sign := 1
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   217
    ].
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   218
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   219
    (aStream atEnd or:[aStream peek isLetter]) ifTrue: [^ exceptionBlock value].
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   220
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   221
    integerPart := (aStream upTo:$.) asNumber.
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   222
    (aStream atEnd or: [aStream peek isLetter]) ifTrue: [
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   223
        fractionPart := 0.
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   224
        scale := 1.
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   225
    ] ifFalse:[
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   226
        fractionStream := ReadWriteStream on:(String new: 10).
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   227
        [
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   228
            char := aStream next.
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   229
            char ~~ nil and:[char isDigit]
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   230
        ] whileTrue:[
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   231
            fractionStream nextPut:char
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   232
        ].
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   233
7053
13e04c48e23c prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 6898
diff changeset
   234
        scale := fractionStream position0Based.
6895
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   235
        fractionStream reset.
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   236
        fractionPart := Number readFrom:fractionStream.
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   237
    ].
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   238
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   239
    ^ self basicNew 
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   240
        setNumerator:(integerPart * (10 raisedTo:scale) + fractionPart) * sign
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   241
        scale:scale
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   242
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   243
    "
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   244
     FixedPoint readFrom:'1.00' 
7053
13e04c48e23c prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 6898
diff changeset
   245
     FixedPoint readFrom:'123.456' 
6895
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   246
     FixedPoint readFrom:'-123.456' 
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   247
     FixedPoint readFrom:'123' 
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   248
     FixedPoint readFrom:'-123' 
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   249
     FixedPoint readFrom:'-123.abcd' onError:[47.5] 
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   250
     FixedPoint readFrom:'-1a.bcd' onError:[47.5] 
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   251
     FixedPoint readFrom:'foot' onError:['bad fixedpoint'] 
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   252
    "
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   253
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   254
    "Created: / 25.10.1997 / 15:28:59 / cg"
2434bee328c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6894
diff changeset
   255
    "Modified: / 25.10.1997 / 15:31:47 / cg"
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
! !
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
6636
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   258
!FixedPoint class methodsFor:'constants'!
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   259
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   260
pi
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   261
    "pi with 1000 valid digits..."
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   262
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   263
    PI_1000 isNil ifTrue:[
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   264
        PI_1000 := self
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   265
                     readFrom:'3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788'
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   266
    ].
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   267
    ^ PI_1000.
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   268
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   269
    "
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   270
     self pi squared    
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   271
     self pi reciprocal 
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   272
     1 / self pi 
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   273
     self pi * 1000000000000000000000000000000000000000000    
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   274
    "
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   275
! !
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   276
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   277
!FixedPoint class methodsFor:'printing control'!
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   278
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   279
printTruncated
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   280
    ^ PrintTruncated ? false.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   281
!
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   282
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   283
printTruncated:aBoolean
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   284
    PrintTruncated := aBoolean.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   285
! !
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   286
6898
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6897
diff changeset
   287
!FixedPoint class methodsFor:'queries'!
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6897
diff changeset
   288
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6897
diff changeset
   289
exponentCharacter
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6897
diff changeset
   290
    ^ $s
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6897
diff changeset
   291
! !
d0182256f3ff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6897
diff changeset
   292
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
!FixedPoint methodsFor:'accessing'!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
scale
2538
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
   296
    "return the number of places of significance that is carried by the receiver."
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
    ^ scale
2538
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
   299
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
   300
    "Modified: 12.4.1997 / 11:21:05 / cg"
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
! !
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
!FixedPoint methodsFor:'arithmetic'!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
* aNumber
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
    "return the product of the receiver and the argument, aNumber.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
     Redefined to care for the scale if the argument is another fixPoint number.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   308
     The results scale is the maximum of the receivers scale and the arguments scale."
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   310
    "/ notice:
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   311
    "/ the following code handles some common cases,
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   312
    "/ and exists as an optimization, to speed up those cases.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   313
    "/ also notice, that checks for those cases must be inlinable without
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   314
    "/ a message send; otherwise double-dispatch is just as fast.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   315
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   316
    (aNumber isMemberOf:SmallInteger) ifTrue:[
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
        ^ self class 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
                numerator:(numerator * aNumber)
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
                denominator:denominator
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
                scale:scale
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
    ].
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
    ^ aNumber productFromFixedPoint:self
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
    "                       
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
     |a r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
     a := (FixedPoint fromString:'123.456').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
     r := a * 5.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
     Transcript showCR:r.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
    "                       
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
     a := (FixedPoint fromString:'123.456').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
     b := (FixedPoint fromString:'1.10').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
     r := a * b.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
     Transcript showCR:r.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
    "                       
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
     a := (FixedPoint fromString:'123.456').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
     b := (FixedPoint fromString:'-1.10').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
     r := a * b.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
     Transcript showCR:r.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
     a := (FixedPoint fromString:'0.9999999').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
     b := (FixedPoint fromString:'0.9999999').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
     r := a * b.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
     Transcript show:'fixed (exact)  : '; showCR:r.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
     Transcript show:'fixed (scale2) : '; showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
     Transcript show:'float (inexact): '; showCR:(0.9999999 * 0.9999999).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
     a := 1.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
     b := (FixedPoint fromString:'0.9999999').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
     r := a * b.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
     Transcript show:'fixed (exact)  : '; showCR:r.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
     Transcript show:'fixed (scale2) : '; showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
     Transcript show:'float (inexact): '; showCR:(0.9999999 * 0.9999999).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
    "
6636
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   376
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   377
    "                       
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   378
     |a r|
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   379
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   380
     a := (FixedPoint fromString:'123.456').
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   381
     r := a * 5.0.    
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   382
     Transcript showCR:r.    
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   383
     Transcript showCR:(r withScale:2).
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   384
    "
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   385
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   386
    "                       
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   387
     |a r|
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   388
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   389
     a := (FixedPoint fromString:'123.456').
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   390
     r := 5.0 * a.    
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   391
     Transcript showCR:r.    
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   392
     Transcript showCR:(r withScale:2).
dedc341eb3ab arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents: 6625
diff changeset
   393
    "
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
+ aNumber
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
    "return the sum of the receiver and the argument, aNumber.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
     Redefined to care for the scale if the argument is another fixPoint number.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   399
     The results scale will be the maximum of the receivers and the arguments scale."
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   401
    |n|
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   403
    "/ notice:
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   404
    "/ the following code handles some common cases,
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   405
    "/ and exists as an optimization, to speed up those cases.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   406
    "/ also notice, that checks for those cases must be inlinable without
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   407
    "/ a message send; otherwise double-dispatch is just as fast.
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   409
    (aNumber isMemberOf:SmallInteger) ifTrue:[
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
        "save a multiplication if possible"
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   411
        denominator == 1 ifTrue:[
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   412
            n := numerator + aNumber.
6645
b25be4db9230 arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents: 6638
diff changeset
   413
        ] ifFalse:[
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   414
            n := numerator + (aNumber * denominator).
6645
b25be4db9230 arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents: 6638
diff changeset
   415
        ].
b25be4db9230 arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents: 6638
diff changeset
   416
        ^ self class 
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   417
            numerator:n 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   418
            denominator:denominator
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   419
            scale:scale
6645
b25be4db9230 arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents: 6638
diff changeset
   420
    ].
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
    ^ aNumber sumFromFixedPoint:self
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
    "
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   424
     ((1/3) asFixedPoint:2) + 1    
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   425
     ((1/3) asFixedPoint:2) + (1/3)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   426
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   427
    "
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
     a := (FixedPoint fromString:'123.456').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
     b := (FixedPoint fromString:'1.10').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
     a + b
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
     a := (FixedPoint fromString:'0.9999999').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
     a + b                   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
     a := (FixedPoint fromString:'0.99').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
     a + b                             
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
     a := (FixedPoint fromString:'0.99').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
     (a + b) withScale:2  
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
     a := (FixedPoint fromString:'0.99').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
     (a + b) withScale:1  
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
     a := 1.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
     Transcript showCR:((a + b) withScale:1).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
     Transcript showCR:(a + b)
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
- aNumber
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
    "return the difference of the receiver and the argument, aNumber.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
     Redefined to care for the scale if the argument is another fixPoint number.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   479
     The results scale is the maximum of the receivers scale and the arguments scale."
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   481
    |n|
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   483
    "/ notice:
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   484
    "/ the following code handles some common cases,
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   485
    "/ and exists as an optimization, to speed up those cases.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   486
    "/ also notice, that checks for those cases must be inlinable without
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   487
    "/ a message send; otherwise double-dispatch is just as fast.
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   489
    (aNumber isMemberOf:SmallInteger) ifTrue:[
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
        "save a multiplication if possible"
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   491
        denominator == 1 ifTrue:[
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   492
            n := numerator - aNumber.
6645
b25be4db9230 arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents: 6638
diff changeset
   493
        ] ifFalse:[
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   494
            n := numerator - (aNumber * denominator).
6645
b25be4db9230 arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents: 6638
diff changeset
   495
        ].
b25be4db9230 arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents: 6638
diff changeset
   496
        ^ self class 
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   497
            numerator:n 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   498
            denominator:denominator
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   499
            scale:scale
6645
b25be4db9230 arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents: 6638
diff changeset
   500
    ].
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
    ^ aNumber differenceFromFixedPoint:self
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
     a := (FixedPoint fromString:'123.456').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
     b := (FixedPoint fromString:'1.10').
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   508
     a - b     
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
     a := (FixedPoint fromString:'0.9999999').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
     b := (FixedPoint fromString:'0.0000009').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
     a - b                   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
     a := (FixedPoint fromString:'0.99').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
     a - b                          
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
     a := (FixedPoint fromString:'0.99').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
     (a - b) withScale:2  
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
     a := (FixedPoint fromString:'0.99').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
     (a - b) withScale:1  
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   541
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
     a := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
     b := (FixedPoint fromString:'0.99').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   548
     (a - b) withScale:2   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
     |a b|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
     a := 1.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
     b := (FixedPoint fromString:'0.0000001').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
     Transcript showCR:((a - b) withScale:1).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
     Transcript showCR:(a - b)
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
/ aNumber
1898
883a1046ca9a commentary
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   562
    "return the quotient of the receiver and the argument, aNumber.
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
     Redefined to care for the scale if the argument is another fixPoint number.
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   564
     The results scale is the maximum of the receivers scale and the arguments scale."
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   566
    "/ notice:
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   567
    "/ the following code handles some common cases,
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   568
    "/ and exists as an optimization, to speed up those cases.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   569
    "/ also notice, that checks for those cases must be inlinable without
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   570
    "/ a message send; otherwise double-dispatch is just as fast.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   571
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   572
    (aNumber isMemberOf:SmallInteger) ifTrue:[
6886
7acddeb0e526 checkin from browser
Stefan Vogel <sv@exept.de>
parents: 6704
diff changeset
   573
        ^ self class 
6894
64f27ed2753f do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents: 6886
diff changeset
   574
                numerator:numerator
64f27ed2753f do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents: 6886
diff changeset
   575
                denominator:(denominator * aNumber)
64f27ed2753f do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents: 6886
diff changeset
   576
                scale:scale
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   577
    ].
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
    ^ aNumber quotientFromFixedPoint:self
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   581
    "                       
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   582
     |a r|                     
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   583
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   584
     a := (FixedPoint fromString:'123.456').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   585
     r := a / 5.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   586
     Transcript showCR:r.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   587
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   588
     Transcript showCR:(r withScale:9).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   590
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   591
    "                       
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   592
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   593
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   594
     a := (FixedPoint fromString:'123.456').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
     b := (FixedPoint fromString:'1.10').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   596
     r := a / b.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   597
     Transcript showCR:r.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   598
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   600
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   601
    "                       
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   602
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   603
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
     a := (FixedPoint fromString:'-123.456').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   605
     b := (FixedPoint fromString:'-1.10').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   606
     r := a / b.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
     Transcript showCR:r.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   609
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   610
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
    "                       
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   613
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
     a := (FixedPoint fromString:'123.456').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
     b := (FixedPoint fromString:'-1.10').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
     r := a / b.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   617
     Transcript showCR:r.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
     Transcript showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   619
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   620
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
     a := 1.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
     b := (FixedPoint fromString:'0.9999999').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
     r := a / b.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
     Transcript show:'fixed (exact)  : '; showCR:r.    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
     Transcript show:'fixed (scale2) : '; showCR:(r withScale:2).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   629
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
     Transcript show:'float (inexact): '; showCR:(1 / 0.9999999).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
    "
6570
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   632
!
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   633
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   634
negated
6894
64f27ed2753f do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents: 6886
diff changeset
   635
    "redefined from Fraction to preserve scale"
6570
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   636
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   637
    ^ self class 
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   638
        numerator:(numerator negated)
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   639
        denominator:denominator
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   640
        scale:scale
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   641
!
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   642
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   643
reciprocal
6894
64f27ed2753f do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents: 6886
diff changeset
   644
    "redefined from Fraction to preserve scale"
6570
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   645
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   646
    numerator == 1 ifTrue:[^ denominator].
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   647
    ^ self class 
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   648
        numerator:denominator
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   649
        denominator:numerator
1d115f1687e3 Fix #negated and #reciprocal
Stefan Vogel <sv@exept.de>
parents: 6237
diff changeset
   650
        scale:scale
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
! !
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
!FixedPoint methodsFor:'coercing & converting'!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   654
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   655
asFixedPoint
2140
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   656
    "return the receiver as a fixedPoint number - thats the receiver itself"
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   657
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
    ^ self
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
2140
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   660
    "Modified: 10.1.1997 / 19:53:14 / cg"
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   661
!
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   662
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   663
asFixedPoint:newScale
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   664
    "return a fixedPoint with the same value as the receiver, 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   665
     and newScale number of post-decimal digits"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   666
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   667
    |minRequiredDenominator factor|
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   668
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   669
    newScale == scale ifTrue:[^ self].
2140
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   670
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   671
    minRequiredDenominator := 10 raisedTo:newScale.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   672
    denominator < minRequiredDenominator ifTrue:[
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   673
        factor := minRequiredDenominator / denominator.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   674
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   675
        ^ self class
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   676
            numerator:(numerator * factor)
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   677
            denominator:minRequiredDenominator
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   678
            scale:newScale
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   679
    ].
2140
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   680
    ^ self class
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   681
        numerator:numerator
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   682
        denominator:denominator
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   683
        scale:newScale
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   684
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   685
    "
6638
7523142a1152 comment
Claus Gittinger <cg@exept.de>
parents: 6636
diff changeset
   686
     '12345.12345' asFixedPoint:2   
2140
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   687
     (FixedPoint fromString:'12345.12345') asFixedPoint:2 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   688
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   689
     ((FixedPoint fromString:'0.33333333')
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   690
      + 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   691
      (FixedPoint fromString:'0.33333333')
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   692
     ) asFixedPoint:2   
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   693
    "
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1898
diff changeset
   694
2538
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
   695
    "Modified: 12.4.1997 / 11:20:37 / cg"
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   696
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   697
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
asFraction
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   699
    "return the receiver as a fraction"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   701
    ^ Fraction
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
        numerator:numerator
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   703
        denominator:denominator
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   704
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
     (FixedPoint fromString:'0.2')           
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   707
     (FixedPoint fromString:'0.2') asFraction
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
     (FixedPoint fromString:'0.2') asFloat
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   709
     (FixedPoint fromString:'0.2') asShortFloat
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   710
     (FixedPoint fromString:'0.2') asInteger
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   711
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
coerce:aNumber
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   715
    "return aNumber converted into receivers type"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   716
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   717
    ^ aNumber asFixedPoint
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   719
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   720
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
generality
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
    "return the generality value - see ArithmeticValue>>retry:coercing:"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   724
    ^ 65
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   725
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
     (FixedPoint fromString:'1.001') + 1      
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
     (FixedPoint fromString:'1.001') + 1.0    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
     (FixedPoint fromString:'1.001') + (1/2)   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
     (FixedPoint fromString:'1.001') + 1.0 asShortFloat 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   731
     (FixedPoint fromString:'1.001') + 1 asLargeInteger 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   732
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   733
     1 + (FixedPoint fromString:'1.001') 
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   734
     1.0 + (FixedPoint fromString:'1.001')      
1891
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
   735
     (1/2) + (FixedPoint fromString:'1.001')    
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
     1.0 asShortFloat + (FixedPoint fromString:'1.001')
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
     1 asLargeInteger + (FixedPoint fromString:'1.001')
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
! !
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
!FixedPoint methodsFor:'double dispatching'!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   743
differenceFromFixedPoint:aFixedPoint
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   744
    |n d otherNumerator otherDenominator|
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   745
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   746
    otherNumerator := aFixedPoint numerator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   747
    otherDenominator := aFixedPoint denominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   748
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   749
    "save a multiplication if possible"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   750
    denominator = otherDenominator ifTrue:[
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   751
        n := otherNumerator - numerator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   752
        d := otherDenominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   753
    ] ifFalse:[
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   754
        n := (otherNumerator * denominator) - (numerator * otherDenominator).
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   755
        d := denominator * otherDenominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   756
    ].
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   757
    ^ self class 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   758
            numerator:n 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   759
            denominator:d
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   760
            scale:(scale max:aFixedPoint scale)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   761
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   762
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   763
     ((1/3) asFixedPoint:2) - ((1/3) asFixedPoint:2)        
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   764
     ((1/3) asFixedPoint:2) - ((2/3) asFixedPoint:2)     
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   765
     (1/3) - ((2/3) asFixedPoint:2)     
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   766
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   767
     ((1/3) asFixedPoint:2) - ((1/3) asFixedPoint:4)        
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   768
     ((1/3) asFixedPoint:2) - ((2/3) asFixedPoint:4)        
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   769
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   770
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   771
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   772
differenceFromFraction:aFraction
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   773
    |n d otherNumerator otherDenominator|
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   774
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   775
    otherNumerator := aFraction numerator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   776
    otherDenominator := aFraction denominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   777
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   778
    "save a multiplication if possible"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   779
    denominator = otherDenominator ifTrue:[
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   780
        n := otherNumerator - numerator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   781
        d := otherDenominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   782
    ] ifFalse:[
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   783
        n := (otherNumerator * denominator) - (numerator * otherDenominator).
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   784
        d := denominator * otherDenominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   785
    ].
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   786
    ^ self class 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   787
            numerator:n 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   788
            denominator:d
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   789
            scale:scale
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   790
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   791
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   792
     (1/3) - ((2/3) asFixedPoint:2)     
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   793
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   794
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   795
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
differenceFromInteger:anInteger
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   797
    "sent when an integer does not know how to subtract the receiver.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   798
     Redefined here to preserve the scale."
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   799
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   800
    ^ self class 
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   801
        numerator:((anInteger * denominator) - numerator)
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   802
        denominator:denominator
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   803
        scale:scale
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   804
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   805
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   806
productFromFixedPoint:aFixedPoint
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   807
    ^ aFixedPoint class 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   808
        numerator:(aFixedPoint numerator * numerator) 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   809
        denominator:(aFixedPoint denominator * denominator)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   810
        scale:(scale max:aFixedPoint scale)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   811
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   812
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   813
     ((1/3) asFixedPoint:2) * ((1/3) asFixedPoint:4)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   814
     (1/3) * ((1/3) asFixedPoint:4)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   815
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   816
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   817
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   818
productFromFraction:aFraction
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   819
    ^ self class 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   820
        numerator:(aFraction numerator * numerator) 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   821
        denominator:(aFraction denominator * denominator)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   822
        scale:scale
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   823
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   824
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   825
     (1/3) * ((1/3) asFixedPoint:4) 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   826
    "
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   827
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   828
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   829
productFromInteger:anInteger
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
    "sent when an integer does not know how to multiply the receiver.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   831
     Redefined here to preserve the scale."
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   833
    ^ self class 
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   834
        numerator:(anInteger * numerator)
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   835
        denominator:denominator
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   836
        scale:scale
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
    "Modified: 5.11.1996 / 10:32:28 / cg"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   841
quotientFromFixedPoint:aFixedPoint
7442
1b0a20747a64 double dispatching
Claus Gittinger <cg@exept.de>
parents: 7380
diff changeset
   842
    "Return the quotient of the argument, aFixedPoint and the receiver."
1b0a20747a64 double dispatching
Claus Gittinger <cg@exept.de>
parents: 7380
diff changeset
   843
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   844
    ^ aFixedPoint class 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   845
        numerator:(aFixedPoint numerator * denominator) 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   846
        denominator:(aFixedPoint denominator * numerator)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   847
        scale:(scale max:aFixedPoint scale)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   848
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   849
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   850
     ((1/3) asFixedPoint:2) / ((1/3) asFixedPoint:2) 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   851
     ((1/3) asFixedPoint:2) / ((1/3) asFixedPoint:4) 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   852
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   853
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   854
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   855
quotientFromFraction:aFraction
7442
1b0a20747a64 double dispatching
Claus Gittinger <cg@exept.de>
parents: 7380
diff changeset
   856
    "Return the quotient of the argument, aFraction and the receiver.
1b0a20747a64 double dispatching
Claus Gittinger <cg@exept.de>
parents: 7380
diff changeset
   857
     Sent when aFraction does not know how to divide by the receiver.
1b0a20747a64 double dispatching
Claus Gittinger <cg@exept.de>
parents: 7380
diff changeset
   858
     Redefined here to preserve the scale."
1b0a20747a64 double dispatching
Claus Gittinger <cg@exept.de>
parents: 7380
diff changeset
   859
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   860
    ^ aFraction class 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   861
        numerator:(aFraction numerator * denominator) 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   862
        denominator:(aFraction denominator * numerator)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   863
        scale:scale
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   864
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   865
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   866
     ((1/3) asFixedPoint:2) / ((1/3) asFixedPoint:2)  
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   867
     ((1/3) asFixedPoint:2) / ((1/3) asFixedPoint:4)  
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   868
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   869
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   870
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   871
quotientFromInteger:anInteger
7442
1b0a20747a64 double dispatching
Claus Gittinger <cg@exept.de>
parents: 7380
diff changeset
   872
    "Return the quotient of the argument, anInteger and the receiver.
1b0a20747a64 double dispatching
Claus Gittinger <cg@exept.de>
parents: 7380
diff changeset
   873
     Sent when anInteger does not know how to divide by the receiver.
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   874
     Redefined here to preserve the scale."
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   875
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   876
    ^ self class 
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
        numerator:(anInteger * denominator)
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   878
        denominator:numerator
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   879
        scale:scale
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   880
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   881
    "Modified: 5.11.1996 / 10:32:35 / cg"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   882
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   883
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   884
sumFromFixedPoint:aFixedPoint
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   885
    |n d otherNumerator otherDenominator|
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   886
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   887
    otherNumerator := aFixedPoint numerator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   888
    otherDenominator := aFixedPoint denominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   889
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   890
    "save a multiplication if possible"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   891
    denominator = otherDenominator ifTrue:[
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   892
        n := numerator + otherNumerator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   893
        d := otherDenominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   894
    ] ifFalse:[
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   895
        n := (numerator * otherDenominator) + (otherNumerator * denominator).
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   896
        d := denominator * otherDenominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   897
    ].
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   898
    ^ self class 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   899
            numerator:n 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   900
            denominator:d
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   901
            scale:(scale max:aFixedPoint scale)
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   902
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   903
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   904
     ((1/3) asFixedPoint:2) + ((1/3) asFixedPoint:2)        
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   905
     ((1/3) asFixedPoint:2) + ((2/3) asFixedPoint:2)     
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   906
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   907
     ((1/3) asFixedPoint:2) + ((1/3) asFixedPoint:4)        
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   908
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   909
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   910
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   911
sumFromFraction:aFraction
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   912
    |n d otherNumerator otherDenominator|
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   913
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   914
    otherNumerator := aFraction numerator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   915
    otherDenominator := aFraction denominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   916
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   917
    "save a multiplication if possible"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   918
    denominator = otherDenominator ifTrue:[
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   919
        n := numerator + otherNumerator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   920
        d := otherDenominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   921
    ] ifFalse:[
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   922
        n := (numerator * otherDenominator) + (otherNumerator * denominator).
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   923
        d := denominator * otherDenominator.
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   924
    ].
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   925
    ^ self class 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   926
            numerator:n 
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   927
            denominator:d
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   928
            scale:scale
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   929
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   930
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   931
     (1/3) + ((1/3) asFixedPoint:2)        
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   932
    "
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   933
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   934
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   935
sumFromInteger:anInteger
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   936
    "sent when an integer does not know how to add the receiver.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   937
     Redefined here to preserve the scale."
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   938
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   939
    ^ self class 
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   940
        numerator:(numerator + (anInteger * denominator))
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   941
        denominator:denominator
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7053
diff changeset
   942
        scale:scale
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   943
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   944
    "Modified: 5.11.1996 / 10:32:43 / cg"
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   945
! !
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   946
5570
e6e14f50d721 category change
Claus Gittinger <cg@exept.de>
parents: 3731
diff changeset
   947
!FixedPoint methodsFor:'printing & storing'!
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   948
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   949
printDecimalOn:aStream roundToScale:roundToScale truncateToScale:truncateToScale
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   950
    "common helper for printing (with round or truncate)
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   951
     and storing (neither rounding, nor truncating)"
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   952
9133
2d3e3d083be8 storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents: 9132
diff changeset
   953
    |e integerPart fractionPart negative num rest|
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   954
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   955
    numerator < 0 ifTrue:[
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   956
        negative := true.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   957
        num := numerator negated.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   958
    ] ifFalse:[
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   959
        negative := false.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   960
        num := numerator.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   961
    ].
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   962
    integerPart := (num // denominator).
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   963
    fractionPart := (num \\ denominator).
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   964
    (roundToScale or:[truncateToScale]) ifTrue:[    
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
   965
        e := 10 raisedTo:scale.
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
   966
    ] ifFalse:[
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   967
        (denominator isPowerOf:10) ifTrue:[
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   968
            e := denominator.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   969
        ] ifFalse:[
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   970
            e := 10 raisedTo:(denominator log:10) asInteger + scale + 2.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   971
        ].
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
   972
    ].
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   973
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   974
    "/ the most common case is a denominator fitting the scale
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   975
    "/ (fixedPoint numbers are created this way)
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   976
    e = denominator ifFalse:[
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   977
        fractionPart := fractionPart * (e * 10) // denominator.
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   978
        roundToScale ifTrue:[
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   979
            fractionPart := (fractionPart roundTo:10) // 10.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   980
        ] ifFalse:[
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   981
            fractionPart := fractionPart // 10.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   982
        ].
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   983
        fractionPart >= e ifTrue:[
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   984
            integerPart := integerPart + 1.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   985
            fractionPart := 0.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   986
        ]
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   987
    ].
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   988
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   989
    "/
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   990
    "/ add a 1000..., so we can (mis-)use integer-printString ...
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   991
    "/ the highest-1 will be cutoff after padding.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   992
    "/
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   993
    fractionPart := e + fractionPart.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   994
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   995
    negative ifTrue:[
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   996
        aStream nextPut:$-
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   997
    ].
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   998
    integerPart printOn:aStream.
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
   999
    (roundToScale or:[truncateToScale]) ifTrue:[
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1000
        scale > 0 ifTrue:[
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1001
            aStream nextPut: $..
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1002
            ((fractionPart printStringPaddedTo:scale with:$0) copyFrom:2) printOn:aStream
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1003
        ].
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1004
    ] ifFalse:[
9133
2d3e3d083be8 storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents: 9132
diff changeset
  1005
        rest := ((fractionPart printString) copyFrom:2).
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1006
        scale > 0 ifTrue:[
9133
2d3e3d083be8 storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents: 9132
diff changeset
  1007
            aStream nextPut: $..
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1008
            (rest paddedTo:scale with:$0) printOn:aStream
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1009
        ] ifFalse:[
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1010
            rest notEmpty ifTrue:[
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1011
                aStream nextPut: $..
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1012
                rest printOn:aStream
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1013
            ]
9133
2d3e3d083be8 storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents: 9132
diff changeset
  1014
        ]
6897
7282c0dc54d3 fixed printing for 0-scale
Claus Gittinger <cg@exept.de>
parents: 6895
diff changeset
  1015
    ].
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1016
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1017
    "
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1018
    ((FixedPoint fromString:'0.66666666') withScale:2)
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1019
        printDecimalOn:Transcript roundToScale:false truncateToScale:false
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1020
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1021
    ((FixedPoint fromString:'0.66666666') withScale:2)
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1022
        printDecimalOn:Transcript roundToScale:true truncateToScale:false
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1023
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1024
    ((FixedPoint fromString:'0.66666666') withScale:2)
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1025
        printDecimalOn:Transcript roundToScale:false truncateToScale:true
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1026
    "
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1027
!
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1028
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1029
printOn:aStream 
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1030
    "append to the argument, aStream, a printed representation of the receiver.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1031
     For printout, only scale post-decimal digits are printed
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1032
     (By default, the printout is rounded to that many digits)"
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1033
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1034
    PrintTruncated == true ifTrue:[
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1035
        self printTruncatedOn:aStream
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1036
    ] ifFalse:[
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1037
        self printRoundedOn:aStream
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1038
    ].
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1039
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1040
    "
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1041
     (FixedPoint fromString:'0.66666666')               
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1042
     (FixedPoint fromString:'0.66666666') withScale:2   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1043
     (FixedPoint fromString:'0.99999999')               
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1044
     (FixedPoint fromString:'0.99999999') withScale:2   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1045
     (FixedPoint fromString:'1.00000001')               
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1046
     (FixedPoint fromString:'1.00000001') withScale:2   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1047
     (FixedPoint fromString:'1.005')                    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1048
     (FixedPoint fromString:'1.005') withScale:2        
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1049
     (FixedPoint fromString:'1.005') withScale:1        
6897
7282c0dc54d3 fixed printing for 0-scale
Claus Gittinger <cg@exept.de>
parents: 6895
diff changeset
  1050
     (FixedPoint fromString:'1.5')                    
7282c0dc54d3 fixed printing for 0-scale
Claus Gittinger <cg@exept.de>
parents: 6895
diff changeset
  1051
     (FixedPoint fromString:'1.5') withScale:2        
7282c0dc54d3 fixed printing for 0-scale
Claus Gittinger <cg@exept.de>
parents: 6895
diff changeset
  1052
     (FixedPoint fromString:'1.5') withScale:1        
7282c0dc54d3 fixed printing for 0-scale
Claus Gittinger <cg@exept.de>
parents: 6895
diff changeset
  1053
     (FixedPoint fromString:'1.5') withScale:0        
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1054
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1055
     (FixedPoint fromString:'-0.66666666')              
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1056
     (FixedPoint fromString:'-0.66666666') withScale:2   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1057
     (FixedPoint fromString:'-0.99999999')              
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1058
     (FixedPoint fromString:'-0.99999999') withScale:2   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1059
     (FixedPoint fromString:'-1.00000001')              
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1060
     (FixedPoint fromString:'-1.00000001') withScale:2   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1061
     (FixedPoint fromString:'-1.005')                   
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1062
     (FixedPoint fromString:'-1.005') withScale:2       
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1063
     (FixedPoint fromString:'-1.005') withScale:1       
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1064
     (FixedPoint fromString:'-1.05')                    
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1065
     (FixedPoint fromString:'-1.05') withScale:2      
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1066
     (FixedPoint fromString:'-1.05') withScale:1      
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1067
     (FixedPoint fromString:'-1.04')                  
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1068
     (FixedPoint fromString:'-1.04') withScale:2      
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1069
     (FixedPoint fromString:'-1.04') withScale:1      
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1070
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1071
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1072
    "
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1073
     |a b r|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1074
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1075
     a := (FixedPoint fromString:'0.66666666') withScale:2.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1076
     b := (FixedPoint fromString:'0.33333333').
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1077
     r := (a + b) withScale:4.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1078
     Transcript show:'printout with scale of 4 :'; showCR:r.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1079
     Transcript show:'more precise value       :'; showCR:(r withScale:8)
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1080
    "
2538
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1081
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1082
    "Modified: 12.4.1997 / 11:20:51 / cg"
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1083
!
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1084
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1085
printRoundedOn:aStream 
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1086
    "append to the argument, aStream, a printed representation of the receiver.
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1087
     For printout, only scale post-decimal digits are printed,
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1088
     the printout is rounded to that many digits"
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1089
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1090
    self printDecimalOn:aStream roundToScale:true truncateToScale:false
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1091
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1092
    "
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1093
     ((FixedPoint fromString:'0.66666666') withScale:2) printRoundedOn:Transcript   
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1094
     ((FixedPoint fromString:'0.66666666') withScale:2) printTruncatedOn:Transcript   
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1095
    "
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1096
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1097
    "Modified: 12.4.1997 / 11:20:51 / cg"
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1098
!
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1099
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1100
printTruncatedOn:aStream 
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1101
    "append to the argument, aStream, a printed representation of the receiver.
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1102
     For printout, only scale post-decimal digits are printed,
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1103
     the printout is truncated to that many digits"
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1104
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1105
    self printDecimalOn:aStream roundToScale:false truncateToScale:true
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1106
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1107
    "
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1108
     ((FixedPoint fromString:'0.66666666') withScale:2) printRoundedOn:Transcript   
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1109
     ((FixedPoint fromString:'0.66666666') withScale:2) printTruncatedOn:Transcript   
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1110
    "
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1111
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1112
    "Modified: 12.4.1997 / 11:20:51 / cg"
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1113
!
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1114
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1115
storeOn:aStream
9132
df7fe5738d18 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9131
diff changeset
  1116
    "notice: we MUST preserve the full internal precision when storing/reloading"
df7fe5738d18 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9131
diff changeset
  1117
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1118
    self printDecimalOn:aStream roundToScale:false truncateToScale:false.
9131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1119
    aStream nextPut:$s.
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1120
    scale storeOn:aStream.
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1121
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1122
    "
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1123
     ((FixedPoint fromString:'0.66666666')              ) storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1124
     ((FixedPoint fromString:'0.66666666') withScale:2  ) storeString  
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1125
     ((FixedPoint fromString:'1.5')                     ) storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1126
     ((FixedPoint fromString:'1.5') withScale:2         ) storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1127
     ((FixedPoint fromString:'1.5') withScale:1         ) storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1128
     ((FixedPoint fromString:'1.5') withScale:0         ) storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1129
    "
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1130
!
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1131
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1132
storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1133
    ^ String streamContents:[:s | self storeOn:s]
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1134
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1135
    "
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1136
     ((FixedPoint fromString:'0.66666666')             ) storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1137
     ((FixedPoint fromString:'0.66666666') withScale:2 ) storeString  
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1138
     ((FixedPoint fromString:'1.5')                     ) storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1139
     ((FixedPoint fromString:'1.5') withScale:2         ) storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1140
     ((FixedPoint fromString:'1.5') withScale:1         ) storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1141
     ((FixedPoint fromString:'1.5') withScale:0         ) storeString 
fcbe5d33e038 storeOn / readFrom fixed
Claus Gittinger <cg@exept.de>
parents: 9129
diff changeset
  1142
    "
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1143
! !
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1144
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1145
!FixedPoint methodsFor:'private'!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1146
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1147
reduced
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1148
    |gc|
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1149
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1150
    scale isNil ifTrue:[
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1151
        "/ to catch inherited Fraction reduce calls
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1152
        self error:'should not happen'.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1153
        scale := 3
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1154
    ].
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1155
6573
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1156
    (denominator < 0) ifTrue:[
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1157
        numerator := numerator negated.
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1158
        denominator := denominator negated
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1159
    ].
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1160
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1161
    denominator == 1 ifTrue:[^ numerator].
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1162
    numerator == 1 ifTrue:[^ self].
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1163
    numerator == 0 ifTrue:[^ 0].
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1164
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1165
    gc := numerator gcd:denominator.
6573
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1166
    gc < 0 ifTrue:[
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1167
        gc := gc negated
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1168
    ].
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1169
    gc := gc gcd:(10 raisedToInteger:scale).
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1170
6573
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1171
    (gc ~~ 1) ifTrue:[
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1172
        numerator := numerator // gc.
6573
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1173
        denominator := denominator // gc.
4ea758ea3d4b reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents: 6570
diff changeset
  1174
        denominator == 1 ifTrue:[^ numerator].
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1175
    ].
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1176
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1177
    ^ self
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1178
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1179
3731
8c2ef8f76670 added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  1180
scale:newScale 
8c2ef8f76670 added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  1181
    "set the scale."
8c2ef8f76670 added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  1182
8c2ef8f76670 added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  1183
    scale := newScale.
8c2ef8f76670 added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  1184
8c2ef8f76670 added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  1185
    "Modified: / 12.4.1997 / 11:22:02 / cg"
8c2ef8f76670 added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  1186
    "Created: / 5.8.1998 / 13:28:49 / cg"
8c2ef8f76670 added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  1187
!
8c2ef8f76670 added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents: 3060
diff changeset
  1188
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1189
setNumerator:nInteger denominator:d scale:s 
2538
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1190
    "initialize the instance variables.
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1191
     Assumes that the fraction as specified by numerator and denominator
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1192
     is already reduced."
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1193
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1194
    scale := s.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1195
    super
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1196
        setNumerator:nInteger 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1197
        denominator:d
2538
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1198
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1199
    "Modified: 12.4.1997 / 11:21:47 / cg"
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1200
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1201
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1202
setNumerator:nInteger scale:s 
2538
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1203
    "initialize the instance variables.
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1204
     Assumes that the fraction as specified by numerator and denominator
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1205
     is already reduced."
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1206
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1207
    scale := s.
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1208
    super
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1209
        setNumerator:nInteger 
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1210
        denominator:(10 raisedTo:s)
2538
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1211
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1212
    "Modified: 12.4.1997 / 11:21:55 / cg"
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1213
!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1214
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1215
setScale:newScale 
2538
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1216
    "initialize the scale instance variables."
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1217
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1218
    scale := newScale.
2538
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1219
6bbfd3558458 comments
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
  1220
    "Modified: 12.4.1997 / 11:22:02 / cg"
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1221
! !
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1222
6650
35de1d8400b2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6645
diff changeset
  1223
!FixedPoint methodsFor:'testing'!
1891
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1224
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1225
isFixedPoint
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1226
    "return true, if the receiver is some kind of fixedPoint number;
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1227
     true is returned here - the method is redefined from Object."
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1228
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1229
    ^ true
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1230
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1231
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1232
! !
58073a4e3859 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1886
diff changeset
  1233
7376
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1234
!FixedPoint methodsFor:'truncation & rounding'!
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1235
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1236
roundedToScale
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1237
    "return the receiver rounded to my scale 
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1238
     (i.e. return a number which has the value which is shown when printing)"
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1239
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1240
    |n scale10|
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1241
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1242
    scale10 := 10 raisedToInteger:scale.
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1243
    n := ((numerator * scale10) + (denominator bitShift:-1)) // denominator.
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1244
    ^ self class
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1245
        numerator:n
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1246
        denominator:scale10
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1247
        scale:scale.
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1248
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1249
    "
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1250
     ((2/3) asFixedPoint:2)                     
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1251
     ((2/3) asFixedPoint:2) rounded          
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1252
     ((2/3) asFixedPoint:2) roundedToScale     
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1253
    "
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1254
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1255
    "Modified: 5.11.1996 / 12:18:46 / cg"
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1256
!
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1257
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1258
truncatedToScale
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1259
    "return the receiver truncated towards zero to my scale"
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1260
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1261
    |n scale10|
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1262
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1263
    scale10 := 10 raisedToInteger:scale.
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1264
    n := (numerator * scale10) quo:denominator.
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1265
    ^ self class
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1266
        numerator:n
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1267
        denominator:scale10
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1268
        scale:scale.
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1269
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1270
    "
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1271
     ((2/3) asFixedPoint:2)                     
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1272
     ((2/3) asFixedPoint:2) truncated          
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1273
     ((2/3) asFixedPoint:2) truncatedToScale     
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1274
    "
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1275
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1276
    "Modified: 5.11.1996 / 12:18:46 / cg"
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1277
! !
a166651de99e truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
  1278
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1279
!FixedPoint class methodsFor:'documentation'!
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1280
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1281
version
9137
9692c2409b38 printing fixed;
Claus Gittinger <cg@exept.de>
parents: 9133
diff changeset
  1282
    ^ '$Header: /cvs/stx/stx/libbasic/FixedPoint.st,v 1.35 2006-02-17 14:30:57 cg Exp $'
1886
7c58ef7c2d78 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1283
! !