Fraction.st
author Claus Gittinger <cg@exept.de>
Wed, 31 Jul 2002 12:24:32 +0200
changeset 6675 c7e2757d5e80
parent 6650 35de1d8400b2
child 6891 212aa8576cf7
permissions -rw-r--r--
documentation comment experimental int-printing (see class documentation)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
     3
              All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5364
diff changeset
    13
"{ Package: 'stx:libbasic' }"
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5364
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
Number subclass:#Fraction
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5364
diff changeset
    16
	instanceVariableNames:'numerator denominator'
6675
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    17
	classVariableNames:'FractionOne FractionZero PrintWholeNumbers'
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5364
diff changeset
    18
	poolDictionaries:''
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5364
diff changeset
    19
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    22
!Fraction class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    27
              All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    Instances of Fraction represent fractional numbers consisting of
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    a numerator and denominator. Both are themselfes arbitrary precision
6675
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    42
    integers. 
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    43
    Fractions are usually created by dividing Integers using / (for exact division).
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    44
    Notice, that all operations on fractions reduce their result; this means, that
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    45
    the result of a fraction-operation may return an integer.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    46
    Aka:
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    47
        (1 / 7) * 7   ->  1  (not 0.99999999...)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    48
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
    49
    Mixed mode arithmetic:
6675
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    50
        fraction op fraction    -> fraction/integer
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    51
        fraction op fix         -> fix; scale is fix's scale
6675
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    52
        fraction op integer     -> fraction/integer
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    53
        fraction op float       -> float
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
    54
6675
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    55
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    56
    [classVariables:]
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    57
        PrintWholeNumbers       Booolean        experimental: 
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    58
                                                controls how fractions which are greater than 1 are printed.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    59
                                                if true, print them as a sum of an integral and the fractional part. 
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    60
                                                (Large ones are easier to read this way)
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    61
                                                     (17/3) printString  -> '(5+(2/3))'  
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    62
                                                for now, the default is false, for backward compatibility
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
    63
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    64
    [author:]
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    65
        Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    66
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    67
    [see also:]
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    68
        Number
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    69
        Float Integer FixedPoint 
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    70
"
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    71
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    73
!Fraction class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
initialize
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
    76
    FractionZero isNil ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    77
        FractionZero := self numerator:0 denominator:1.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    78
        FractionOne := self numerator:1 denominator:1
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
    79
    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    82
!Fraction class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
new
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
    "create and return a new fraction with value 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
    87
    ^ self numerator:0 denominator:1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    89
a27a279701f8 Initial revision
claus
parents:
diff changeset
    90
numerator:num denominator:den
a27a279701f8 Initial revision
claus
parents:
diff changeset
    91
    "create and return a new fraction with numerator num and denominator den"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    92
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
    93
    |newFraction|
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
    94
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
%{  /* NOCONTEXT */
369
claus
parents: 359
diff changeset
    96
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
    97
    /* this check allows subclassing .. */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    98
    if (self == Fraction) {
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    99
        if (__bothSmallInteger(num, den)) {
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   100
            if (__CanDoQuickAlignedNew(sizeof(struct __Fraction))) {    /* OBJECT ALLOCATION */
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   101
                OBJ newFraction;
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   102
                int spc;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   103
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   104
                __qCheckedAlignedNew(newFraction, sizeof(struct __Fraction));
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   105
                __InstPtr(newFraction)->o_class = self;
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   106
                if (__intVal(den) < 0) {
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   107
                    __FractionInstPtr(newFraction)->f_numerator = __MKSMALLINT(- __intVal(num));
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   108
                    __FractionInstPtr(newFraction)->f_denominator = __MKSMALLINT(- __intVal(den));
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   109
                } else {
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   110
                    __FractionInstPtr(newFraction)->f_numerator = num;
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   111
                    __FractionInstPtr(newFraction)->f_denominator = den;
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   112
                }
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   113
                if (num == __MKSMALLINT(1)) {
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   114
                    RETURN ( newFraction );
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   115
                }
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   116
            }
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   117
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
    }
2790
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   119
%}.
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   120
    newFraction isNil ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   121
        newFraction :=  self basicNew setNumerator:num denominator:den.
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   122
    ].
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   123
    ^ newFraction reduced
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   124
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   126
!Fraction class methodsFor:'constants'!
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   127
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   128
pi
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   129
    "return the constant pi as Fraction"
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   130
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   131
    ^ self 
6063
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   132
        numerator:  314159265358979323846264343
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   133
        denominator:100000000000000000000000000
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   134
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   135
"/    ^ self 
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   136
"/        numerator:  314159265358979323846264338327950288419716939937510582097494459
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   137
"/        denominator:100000000000000000000000000000000000000000000000000000000000000
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   138
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   139
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   140
     Fraction pi         
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   141
     Fraction pi asFloat
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   142
     Float pi            
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   143
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   144
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   145
    "Modified: 5.11.1996 / 11:11:44 / cg"
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   146
!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   147
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   148
unity
1555
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   149
    "return the neutral element for multiplication (1 / 1)"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   150
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   151
    ^ FractionOne
1555
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   152
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   153
    "Modified: 18.7.1996 / 12:26:06 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   154
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   155
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   156
zero
1555
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   157
    "return the neutral element for addition (0 / 1)"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   158
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   159
    ^ FractionZero
1555
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   160
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   161
    "Modified: 18.7.1996 / 12:26:12 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   162
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   163
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   164
!Fraction class methodsFor:'queries'!
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   165
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   166
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   167
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   168
     Here, true is returned for myself, false for subclasses."
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   169
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   170
    ^ self == Fraction
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   171
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   172
    "Modified: 23.4.1996 / 15:59:10 / cg"
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   173
! !
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   174
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   175
!Fraction methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   176
a27a279701f8 Initial revision
claus
parents:
diff changeset
   177
denominator
a27a279701f8 Initial revision
claus
parents:
diff changeset
   178
    "return the denominator"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   179
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
    ^ denominator
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   182
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
numerator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   184
    "return the numerator"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   185
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   186
    ^ numerator
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   187
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   188
a27a279701f8 Initial revision
claus
parents:
diff changeset
   189
!Fraction methodsFor:'arithmetic'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   190
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   191
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   192
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   193
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   194
    |n d|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   195
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   196
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   197
    "/ notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   198
    "/ the following code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   199
    "/ and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   200
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   201
    "/ Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   202
    "/ mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   203
    "/ (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   204
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   205
6646
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   206
    aNumber isInteger ifTrue:[
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   207
        ^ self class 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   208
                numerator:(numerator * aNumber)
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   209
                denominator:denominator
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   210
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   211
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   212
        aNumber isFixedPoint ifFalse:[  "/ the value was corrent, but the scale is lost
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   213
            n := numerator * aNumber numerator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   214
            d := denominator * aNumber denominator.
6646
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   215
            ^ self class 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   216
                numerator:n 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   217
                denominator:d
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   218
        ]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   219
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   220
    (aNumber isMemberOf:Float) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   221
        ^ (numerator * aNumber) / denominator
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   222
    ].
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   223
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   224
    ^ aNumber productFromFraction:self
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   225
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   226
    "Modified: 28.7.1997 / 19:09:23 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   228
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   229
+ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   230
    "return the sum of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   231
a27a279701f8 Initial revision
claus
parents:
diff changeset
   232
    |n d|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   233
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   234
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   235
    "/ notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   236
    "/ the following code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   237
    "/ and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   238
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   239
    "/ Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   240
    "/ mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   241
    "/ (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   242
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   243
6646
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   244
    aNumber isInteger ifTrue:[
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   245
        ^ self class 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   246
                numerator:(numerator + (denominator * aNumber))
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   247
                denominator:denominator
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   248
    ].
259
   249
    aNumber isFraction ifTrue:[
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   250
        aNumber isFixedPoint ifFalse:[  "/ the value was correct, but the scale is lost
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   251
            n := aNumber numerator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   252
            d := aNumber denominator.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   253
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   254
            "save a multiplication if possible"
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   255
            denominator == d ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   256
                n := numerator + n
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   257
            ] ifFalse:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   258
                n := (numerator * d) + (n * denominator).
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   259
                d := denominator * d.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   260
            ].
6646
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   261
            ^ self class 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   262
                numerator:n 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   263
                denominator:d
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   264
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   265
    ].
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   266
    (aNumber isMemberOf:Float) ifTrue:[
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   267
        ^ aNumber + self asFloat
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   268
    ].
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   269
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
    ^ aNumber sumFromFraction:self
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   271
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   272
    "Modified: 28.7.1997 / 19:09:16 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   274
a27a279701f8 Initial revision
claus
parents:
diff changeset
   275
- aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
    "return the difference of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
a27a279701f8 Initial revision
claus
parents:
diff changeset
   278
    |n d|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   279
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   280
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   281
    "/ notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   282
    "/ the following code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   283
    "/ and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   284
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   285
    "/ Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   286
    "/ mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   287
    "/ (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   288
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   289
6646
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   290
    aNumber isInteger ifTrue:[
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   291
        ^ self class 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   292
                numerator:(numerator - (denominator * aNumber))
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   293
                denominator:denominator
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   294
    ].
259
   295
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   296
        aNumber isFixedPoint ifFalse:[  "/ the value was corrent, but the scale is lost
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   297
            n := aNumber numerator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   298
            d := aNumber denominator.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   299
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   300
            "save a multiplication if possible"
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   301
            denominator == d ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   302
                n := numerator - n
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   303
            ] ifFalse:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   304
                n := (numerator * d) - (n * denominator).
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   305
                d := denominator * d
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   306
            ].
6646
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   307
            ^ self class 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   308
                numerator:n 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   309
                denominator:d
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   310
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   311
    ].
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   312
    (aNumber isMemberOf:Float) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   313
        ^ (numerator asFloat / denominator asFloat) - aNumber
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   314
    ].
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   315
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   316
    ^ aNumber differenceFromFraction:self
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   317
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   318
    "
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   319
     (1/3) - (1/9)      
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   320
     (1/9) - (1/3)      
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   321
     (999/1000) - (1/1000)      
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   322
     (999/1000) - (1/1000000)      
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   323
     (999000/1000000) - (1/1000000)      
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   324
    "
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   325
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   326
    "Modified: 28.7.1997 / 19:09:11 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   327
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   328
a27a279701f8 Initial revision
claus
parents:
diff changeset
   329
/ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   330
    "return the quotient of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   331
a27a279701f8 Initial revision
claus
parents:
diff changeset
   332
    |n d|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   333
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   334
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   335
    "/ notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   336
    "/ the following code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   337
    "/ and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   338
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   339
    "/ Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   340
    "/ mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   341
    "/ (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   342
    "/
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   343
6646
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   344
    aNumber isInteger ifTrue:[
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   345
        ^ self class 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   346
                numerator:numerator
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   347
                denominator:(denominator * aNumber)
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   348
    ].
259
   349
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   350
        aNumber isFixedPoint ifFalse:[  "/ the value was corrent, but the scale is lost
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   351
            n := numerator * aNumber denominator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   352
            d := denominator * aNumber numerator.
6646
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   353
            ^ self class 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   354
                numerator:n 
875d9668d82b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6576
diff changeset
   355
                denominator:d
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   356
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   357
    ].
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   358
    (aNumber isMemberOf:Float) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   359
        ^ numerator / (denominator * aNumber)
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   360
    ].
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 6063
diff changeset
   361
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   362
    ^ aNumber quotientFromFraction:self
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   363
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   364
    "Modified: 28.7.1997 / 19:09:06 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   365
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   366
a27a279701f8 Initial revision
claus
parents:
diff changeset
   367
// aNumber
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   368
    "return the integer quotient of dividing the receiver by aNumber with
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   369
     truncation towards negative infinity."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   370
a27a279701f8 Initial revision
claus
parents:
diff changeset
   371
    ^ (numerator * aNumber denominator) // (denominator * aNumber numerator)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   372
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   373
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   374
     0.5 // 1
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   375
     -0.5 // 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3899
diff changeset
   376
     (1/2) // 1  = 0 ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3899
diff changeset
   377
     (-1/2) // 1 = -1 ifFalse:[self halt].
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   378
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   379
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3899
diff changeset
   380
    "Modified: / 5.11.1996 / 11:47:14 / cg"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3899
diff changeset
   381
    "Modified: / 13.2.1998 / 09:15:35 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   382
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   383
a27a279701f8 Initial revision
claus
parents:
diff changeset
   384
negated
a27a279701f8 Initial revision
claus
parents:
diff changeset
   385
    "optional - could use inherited method ..."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   386
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   387
    ^ self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   388
        numerator:(numerator negated)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   389
        denominator:denominator
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   390
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   391
    "Modified: 5.11.1996 / 10:29:11 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   392
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   393
a27a279701f8 Initial revision
claus
parents:
diff changeset
   394
reciprocal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   395
    "optional - could use inherited method ..."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   396
a27a279701f8 Initial revision
claus
parents:
diff changeset
   397
    numerator == 1 ifTrue:[^ denominator].
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   398
    ^ self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   399
        numerator:denominator
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   400
        denominator:numerator
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   401
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   402
    "Modified: 5.11.1996 / 10:29:22 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   403
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   404
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   405
!Fraction methodsFor:'coercing & converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   406
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   407
asFixedPoint
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   408
    "return the receiver as fixedPoint number.
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   409
     Q: what should the scale be here ?"
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   410
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   411
    ^ FixedPoint numerator:numerator denominator:denominator scale:2
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   412
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   413
    "
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   414
     (1/2) asFixedPoint
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   415
    "
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   416
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   417
    "Created: 5.11.1996 / 15:15:54 / cg"
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   418
!
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   419
2140
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   420
asFixedPoint:scale
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   421
    "return the receiver as fixedPoint number, with the given number
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   422
     of post-decimal-point digits."
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   423
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   424
    ^ FixedPoint numerator:numerator denominator:denominator scale:scale
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   425
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   426
    "
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   427
     (1/2) asFixedPoint:2 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   428
     (1/3) asFixedPoint:2 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   429
     (1/3) asFixedPoint:5 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   430
     (2/3) asFixedPoint:2 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   431
     (2/3) asFixedPoint:5 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   432
    "
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   433
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   434
    "Created: 5.11.1996 / 15:15:54 / cg"
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   435
    "Modified: 10.1.1997 / 19:54:50 / cg"
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   436
!
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   437
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   438
asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   439
    "return a float with (approximately) my value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   440
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   441
    |num den numShift denShift bits|
6571
101905a14870 Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents: 6486
diff changeset
   442
101905a14870 Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents: 6486
diff changeset
   443
    (numerator class == SmallInteger and:[denominator class == SmallInteger]) ifTrue:[
101905a14870 Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents: 6486
diff changeset
   444
        ^ (numerator asFloat) / (denominator asFloat)
101905a14870 Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents: 6486
diff changeset
   445
    ].
101905a14870 Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents: 6486
diff changeset
   446
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   447
    "Do it the hard way: reduce magnitude and undo reduction on the quotient"
6571
101905a14870 Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents: 6486
diff changeset
   448
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   449
    bits := Float precision * 2.    "number of bits to preserve (conservative)"
6571
101905a14870 Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents: 6486
diff changeset
   450
    num := numerator abs.
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   451
    numShift := bits - num highBit. "(num highBit - bits) negated"
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   452
    numShift < 0 ifTrue:[num := num bitShift:numShift] ifFalse:[numShift := 0].
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   453
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   454
    den :=  denominator.
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   455
    denShift := bits - den highBit. "(den highBit - bits) negated"
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   456
    denShift < 0 ifTrue:[den := den bitShift:denShift] ifFalse:[denShift := 0].
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   457
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   458
    ^ (num asFloat / den asFloat) * (2.0 raisedToInteger:denShift-numShift) * (num sign)
6571
101905a14870 Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents: 6486
diff changeset
   459
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   460
    " 
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   461
      (5/9) asFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   462
      (-5/9) asFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   463
      (500000000000/900000000000) asFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   464
      (-500000000000/900000000000) asFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   465
      (500000000000/9) asFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   466
      (5/900000000000) asFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   467
      89012345678901234567 asFloat / 123456789123456789 asFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   468
      (89012345678901234567 / 123456789123456789) asFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   469
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   470
      (
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   471
       180338700661043257034670206806167960222709397862806840937993331366591676308781197477183367018067356365812757479444845320188679437752013593674158587947149815441890236037219685250845721864713487208757788709113534916165172927384095182655935222723385253851776639985379367854545495930551624041981995105743408203125
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   472
        /
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   473
       180331613628627651967947866455016278082980736719853750685591387625058011528928110602436691256100991596843001549483950600930062886280582766771424470965440873615557144641435276844465734361353086032476712374317224249252177316815544331763696909434844464464323192083930469387098582956241443753242492675781250
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   474
      ) asFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   475
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   476
      180338700661043257034670206806167960222709397862806840937993331366591676308781197477183367018067356365812757479444845320188679437752013593674158587947149815441890236037219685250845721864713487208757788709113534916165172927384095182655935222723385253851776639985379367854545495930551624041981995105743408203125
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   477
         asFloat /
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   478
      180331613628627651967947866455016278082980736719853750685591387625058011528928110602436691256100991596843001549483950600930062886280582766771424470965440873615557144641435276844465734361353086032476712374317224249252177316815544331763696909434844464464323192083930469387098582956241443753242492675781250
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   479
         asFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   480
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   481
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   482
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   483
asFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   484
    "return the receiver as fraction - thats itself"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   485
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   486
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   487
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   488
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   489
asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   490
    "return an integer with my value - will usually truncate"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   491
a27a279701f8 Initial revision
claus
parents:
diff changeset
   492
    ^ numerator // denominator
a27a279701f8 Initial revision
claus
parents:
diff changeset
   493
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   494
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   495
asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   496
    "return an integer with my value - will usually truncate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   497
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   498
    ^ self asInteger asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   499
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   500
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   501
asShortFloat
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   502
    "return a short float with (approximately) my value"
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   503
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   504
    (numerator class == SmallInteger and:[denominator class == SmallInteger]) ifTrue:[
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   505
        ^ (numerator asShortFloat) / (denominator asShortFloat)
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   506
    ].
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   507
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   508
    ^ self asFloat asShortFloat
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   509
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   510
    "
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   511
      (5/9) asShortFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   512
      (500000000000/900000000000) asShortFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   513
      (500000000000/9) asShortFloat
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   514
    "
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   515
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   516
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   517
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   518
    "return aNumber converted into receivers type"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   519
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   520
    ^ aNumber asFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   521
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   522
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   523
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   524
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   525
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   526
    ^ 60
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   527
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   528
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   529
!Fraction methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   530
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   531
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   532
    "return true if the receiver is less
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   533
     than aNumber, false otherwise."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   534
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   535
    |d n|
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   536
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   537
    (aNumber isMemberOf:SmallInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   538
        ^ numerator < (denominator * aNumber)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   539
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   540
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   541
        d := aNumber denominator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   542
        n := aNumber numerator.
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   543
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   544
        "/ save a multiplication if possible
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   545
        d == denominator ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   546
            ^ numerator < n
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   547
        ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   548
        ^ (numerator * d) < (denominator * n)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   549
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   550
    ^ aNumber lessFromFraction:self
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   551
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   552
    "Modified: 5.11.1996 / 10:30:52 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   553
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   554
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   555
= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   556
    "return true, if the argument represents the same numeric value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   557
     as the receiver, false otherwise"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   558
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   559
    (aNumber isMemberOf:SmallInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   560
        (denominator = 1) ifFalse:[^ false].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   561
        ^ numerator = aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   562
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   563
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   564
        denominator = aNumber denominator ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   565
            ^ numerator = aNumber numerator
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   566
        ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   567
        ^ self sameFractionValueAs:aNumber
3631
26a44b284912 handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   568
    ].
26a44b284912 handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   569
    (aNumber isInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   570
        (denominator = 1) ifFalse:[^ false].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   571
        ^ numerator = aNumber
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   572
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   573
    ^ self retry:#= coercing:aNumber
3631
26a44b284912 handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   574
26a44b284912 handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   575
    "Modified: / 7.7.1998 / 17:17:07 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   576
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   577
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   578
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   579
    "return true if the receiver is greater
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   580
     than aNumber, false otherwise."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   581
    "optional - could use inherited method ..."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   582
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   583
    |d n|
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   584
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   585
    (aNumber isMemberOf:SmallInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   586
        ^ numerator > (denominator * aNumber)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   587
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   588
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   589
        d := aNumber denominator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   590
        n := aNumber numerator.
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   591
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   592
        "/ save a multiplication if possible
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   593
        d == denominator ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   594
            ^ numerator > n
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   595
        ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   596
        ^ (numerator * d) > (denominator * n)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   597
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   598
    ^ self retry:#> coercing:aNumber
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   599
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   600
    "Modified: 5.11.1996 / 10:31:28 / cg"
4593
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   601
!
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   602
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   603
hash
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   604
    "return a number for hashing; redefined, since fractions compare
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   605
     by numeric value (i.e. (9/3) = 3), therefore (9/3) hash must be the same
4594
eb09f567a3bc float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents: 4593
diff changeset
   606
     as 3 hash."
4593
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   607
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   608
    (denominator = 1) ifTrue:[^ numerator hash].
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   609
4594
eb09f567a3bc float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents: 4593
diff changeset
   610
    ^ self asFloat hash
4593
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   611
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   612
    "
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   613
     3 hash           
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   614
     (9/3) hash       
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   615
     3.0 hash         
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   616
     (1/2) hash       
4594
eb09f567a3bc float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents: 4593
diff changeset
   617
     (1/4) hash       
4593
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   618
     0.0 hash         
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   619
     0.5 hash         
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   620
     0.25 hash         
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   621
     0.4 hash         
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   622
    "
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   623
!
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   624
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   625
sameFractionValueAs:aNumber
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   626
    "return true, if the argument represents the same numeric value
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   627
     as the receiver, false otherwise"
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   628
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   629
    |rSelf rNum|
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   630
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   631
    rSelf := self reduced.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   632
    rNum := aNumber reduced.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   633
    rSelf denominator = rNum denominator ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   634
        ^ rSelf numerator = rNum numerator
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   635
    ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   636
    ^ false
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   637
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   638
a27a279701f8 Initial revision
claus
parents:
diff changeset
   639
!Fraction methodsFor:'double dispatching'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   640
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   641
differenceFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   642
    "sent when a float does not know how to subtract the receiver, a fraction"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   643
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   644
    ^ (aFloat * denominator - numerator) / denominator
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   645
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   646
a27a279701f8 Initial revision
claus
parents:
diff changeset
   647
differenceFromInteger:anInteger
213
3b56a17534fd *** empty log message ***
claus
parents: 92
diff changeset
   648
    "sent when an integer does not know how to subtract the receiver, a fraction"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   649
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   650
    ^ (self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   651
        numerator:((anInteger * denominator) - numerator)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   652
        denominator:denominator)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   653
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   654
    "Modified: 28.7.1997 / 19:08:53 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   655
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   656
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   657
lessFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   658
    "sent when an integer does not know how to compare to the receiver, a fraction"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   659
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   660
    ^ (denominator * anInteger) < numerator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   661
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   662
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   663
productFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   664
    "sent when a float does not know how to multiply the receiver, a fraction"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   665
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   666
    ^ aFloat * numerator / denominator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   667
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   668
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   669
productFromInteger:anInteger
213
3b56a17534fd *** empty log message ***
claus
parents: 92
diff changeset
   670
    "sent when an integer does not know how to multiply the receiver, a fraction"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   671
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   672
    ^ (self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   673
        numerator:(anInteger * numerator)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   674
        denominator:denominator)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   675
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   676
    "Modified: 28.7.1997 / 19:06:22 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   677
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   678
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   679
quotientFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   680
    "sent when a float does not know how to divide by the receiver, a fraction"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   681
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   682
    ^ (aFloat * denominator) / numerator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   683
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   684
324
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
   685
quotientFromInteger:anInteger
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
   686
    "sent when an integer does not know how to divide by the receiver, a fraction"
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
   687
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   688
    ^ (self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   689
        numerator:(anInteger * denominator)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   690
        denominator:numerator)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   691
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   692
    "Modified: 28.7.1997 / 19:08:46 / cg"
324
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
   693
!
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
   694
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   695
sumFromFloat:aFloat
213
3b56a17534fd *** empty log message ***
claus
parents: 92
diff changeset
   696
    "sent when a float does not know how to add the receiver, a fraction"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   697
a27a279701f8 Initial revision
claus
parents:
diff changeset
   698
    ^ (aFloat * denominator + numerator) / denominator
a27a279701f8 Initial revision
claus
parents:
diff changeset
   699
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   700
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   701
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   702
    "sent when an integer does not know how to add the receiver, a fraction"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   703
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   704
    ^ (self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   705
        numerator:(numerator + (anInteger * denominator))
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   706
        denominator:denominator)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   707
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   708
    "Modified: 28.7.1997 / 19:08:40 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   709
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   710
6486
38ae7f67ee12 Object coding
Stefan Vogel <sv@exept.de>
parents: 6153
diff changeset
   711
!Fraction methodsFor:'encoding'!
38ae7f67ee12 Object coding
Stefan Vogel <sv@exept.de>
parents: 6153
diff changeset
   712
38ae7f67ee12 Object coding
Stefan Vogel <sv@exept.de>
parents: 6153
diff changeset
   713
encodeOn:anEncoder with:aParameter
38ae7f67ee12 Object coding
Stefan Vogel <sv@exept.de>
parents: 6153
diff changeset
   714
38ae7f67ee12 Object coding
Stefan Vogel <sv@exept.de>
parents: 6153
diff changeset
   715
    anEncoder encodeFraction:self with:aParameter
38ae7f67ee12 Object coding
Stefan Vogel <sv@exept.de>
parents: 6153
diff changeset
   716
! !
38ae7f67ee12 Object coding
Stefan Vogel <sv@exept.de>
parents: 6153
diff changeset
   717
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   718
!Fraction methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   719
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   720
printOn:aStream
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   721
    "append a printed representation of the receiver to the
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   722
     argument, aStream"
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   723
6675
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   724
    |t|
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   725
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   726
    PrintWholeNumbers == true ifTrue:[
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   727
        "/ experimental: print fractions which are greater than 1 as a sum of
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   728
        "/ an integral and the fractional part. They are easier to read this way.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   729
        numerator > denominator ifTrue:[
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   730
            aStream nextPut:$(.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   731
            t := numerator // denominator.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   732
            t printOn:aStream.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   733
            aStream nextPutAll:'+('.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   734
            (numerator - (t*denominator)) printOn:aStream.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   735
            aStream nextPut:$/.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   736
            denominator printOn:aStream.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   737
            aStream nextPutAll:'))'.
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   738
            ^ self
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   739
        ].
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   740
    ].
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   741
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   742
    aStream nextPut:$(.
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   743
    numerator printOn:aStream.
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   744
    aStream nextPut:$/.
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   745
    denominator printOn:aStream.
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   746
    aStream nextPut:$)
6675
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   747
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   748
    "Modified: / 31.7.2002 / 09:56:41 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   749
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   750
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   751
!Fraction methodsFor:'private'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   752
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   753
reduced
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   754
    "reduce the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   755
2790
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   756
    |gcd den|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   757
2790
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   758
    den := denominator.
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   759
    den < 0 ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   760
        numerator := numerator negated.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   761
        den := denominator := den negated.
2789
e3e8707d26b4 make certain, that denominator is positive (in #reduce)
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
   762
    ].
e3e8707d26b4 make certain, that denominator is positive (in #reduce)
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
   763
2790
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   764
    den == 1 ifTrue:[^ numerator].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   765
    numerator == 1 ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   766
    numerator == 0 ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   767
2790
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   768
    gcd := numerator gcd:den.
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   769
    (gcd ~~ 1) ifTrue:[
6576
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   770
        gcd < 0 ifTrue:[
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   771
             gcd := gcd negated.
c28cdeb0bfb0 Fix asFloat
Stefan Vogel <sv@exept.de>
parents: 6571
diff changeset
   772
        ].
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   773
        numerator := numerator // gcd.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   774
        denominator := den := den // gcd.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   775
        (den == 1) ifTrue:[^ numerator].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   776
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   777
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   778
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   779
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   780
setNumerator:num denominator:den
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   781
    "set both numerator and denominator"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   782
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   783
    numerator := num.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   784
    denominator := den
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   785
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   786
6650
35de1d8400b2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6646
diff changeset
   787
!Fraction methodsFor:'testing'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   788
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   789
isFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   790
    "return true, if the receiver is some kind of fraction;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   791
     true is returned here - the method is redefined from Object."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   792
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   793
    ^ true
6650
35de1d8400b2 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 6646
diff changeset
   794
!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   795
4658
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   796
isLiteral
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   797
    "return true, if the receiver can be used as a literal constant in ST syntax
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   798
     (i.e. can be used in constant arrays)"
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   799
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   800
    ^ true
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   801
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   802
!
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   803
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   804
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   805
    "return true if the receiver is negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   806
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   807
    (numerator < 0) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   808
        ^ (denominator < 0) not
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   809
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   810
    ^ (denominator < 0)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   811
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   812
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5364
diff changeset
   813
!Fraction methodsFor:'truncation & rounding'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   814
3899
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   815
fractionPart
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   816
    "extract the after-decimal fraction part."
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   817
6153
e92766db42c6 integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   818
    numerator abs < denominator abs ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   819
        ^ self
3899
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   820
    ].
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   821
    ^ super fractionPart
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   822
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   823
    "
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   824
     (3/2) fractionPart 
6153
e92766db42c6 integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   825
     (-3/2) fractionPart     
3899
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   826
     (2/3) fractionPart 
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   827
     ((3/2)*(15/4)) fractionPart   
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   828
     ((2/3)*(4/15)) fractionPart   
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   829
    "
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   830
6153
e92766db42c6 integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   831
    "Modified: / 5.11.2001 / 17:55:25 / cg"
3899
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   832
!
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   833
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   834
integerPart
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   835
    "extract the pre-decimal integer part."
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   836
6153
e92766db42c6 integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   837
    numerator abs < denominator abs ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   838
        ^ 0
3899
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   839
    ].
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   840
    ^ super integerPart
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   841
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   842
    "
6153
e92766db42c6 integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   843
     (3/2) integerPart        
e92766db42c6 integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   844
     (-3/2) integerPart        
3899
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   845
     (2/3) integerPart           
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   846
     ((3/2)*(15/4)) integerPart   
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   847
     ((2/3)*(4/15)) integerPart   
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   848
    "
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   849
6153
e92766db42c6 integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   850
    "Modified: / 5.11.2001 / 17:55:01 / cg"
3899
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   851
!
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   852
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   853
rounded
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   854
    "return the receiver rounded to the nearest integer as integer"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   855
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   856
    "/ mhmh - what about -(1/2)
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   857
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   858
    |t|
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   859
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   860
    self negative ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   861
        t := self - (1/2)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   862
    ] ifFalse:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   863
        t := self + (1/2)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   864
    ].
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   865
    ^ t truncated.
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   866
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   867
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   868
     (1/3) rounded           
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   869
     (1/3) negated rounded     
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   870
     (1/2) rounded           
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   871
     (1/2) negated rounded   
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   872
     0.5 rounded  
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   873
     -0.5 rounded 
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   874
     (2/3) rounded             
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   875
     (2/3) negated rounded     
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   876
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   877
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   878
    "Modified: 5.11.1996 / 11:32:32 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   879
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   880
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   881
truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   882
    "return the receiver truncated towards zero as Integer"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   883
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   884
    ^ numerator quo: denominator
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   885
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   886
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   887
     (3/2) truncated     
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   888
     (3/2) negated truncated  
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   889
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   890
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   891
    "Modified: 5.11.1996 / 12:18:46 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   892
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   893
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   894
!Fraction class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   895
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   896
version
6675
c7e2757d5e80 documentation comment
Claus Gittinger <cg@exept.de>
parents: 6650
diff changeset
   897
    ^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.59 2002-07-31 10:24:32 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   898
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   899
Fraction initialize!