Fraction.st
author Claus Gittinger <cg@exept.de>
Tue, 02 Oct 2001 10:15:17 +0200
changeset 6063 e07421c13ca0
parent 5552 31b5cc144476
child 6064 04bde2eeb749
permissions -rw-r--r--
pi
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'
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5364
diff changeset
    17
	classVariableNames:'FractionOne FractionZero'
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
324
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
    42
    integers. Fractions are usually created by dividing Integers using /
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    43
    (for exact division).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    44
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
    45
    Mixed mode arithmetic:
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    46
        fraction op fraction    -> fraction
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    47
        fraction op fix         -> fix; scale is fix's scale
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    48
        fraction op integer     -> fraction
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    49
        fraction op float       -> float
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
    50
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    51
    [author:]
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    52
        Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    53
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    54
    [see also:]
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    55
        Number
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    56
        Float Integer FixedPoint 
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    57
"
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    58
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    59
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    60
!Fraction class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    61
a27a279701f8 Initial revision
claus
parents:
diff changeset
    62
initialize
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
    63
    FractionZero isNil ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    64
        FractionZero := self numerator:0 denominator:1.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    65
        FractionOne := self numerator:1 denominator:1
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
    66
    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    67
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    69
!Fraction class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
new
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
    "create and return a new fraction with value 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
    74
    ^ self numerator:0 denominator:1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
numerator:num denominator:den
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
    "create and return a new fraction with numerator num and denominator den"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
    80
    |newFraction|
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
    81
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
%{  /* NOCONTEXT */
369
claus
parents: 359
diff changeset
    83
13
62303f84ff5f *** empty log message ***
claus
parents: 5
diff changeset
    84
    /* this check allows subclassing .. */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
    if (self == Fraction) {
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    86
        if (__bothSmallInteger(num, den)) {
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    87
            if (__CanDoQuickAlignedNew(sizeof(struct __Fraction))) {    /* OBJECT ALLOCATION */
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    88
                OBJ newFraction;
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    89
                int spc;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    90
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    91
                __qCheckedAlignedNew(newFraction, sizeof(struct __Fraction));
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    92
                __InstPtr(newFraction)->o_class = self;
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    93
                if (__intVal(den) < 0) {
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    94
                    __FractionInstPtr(newFraction)->f_numerator = __MKSMALLINT(- __intVal(num));
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    95
                    __FractionInstPtr(newFraction)->f_denominator = __MKSMALLINT(- __intVal(den));
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    96
                } else {
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    97
                    __FractionInstPtr(newFraction)->f_numerator = num;
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    98
                    __FractionInstPtr(newFraction)->f_denominator = den;
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
    99
                }
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   100
                if (num == __MKSMALLINT(1)) {
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   101
                    RETURN ( newFraction );
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   102
                }
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   103
            }
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   104
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   105
    }
2790
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   106
%}.
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   107
    newFraction isNil ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   108
        newFraction :=  self basicNew setNumerator:num denominator:den.
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   109
    ].
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   110
    ^ newFraction reduced
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   111
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   112
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   113
!Fraction class methodsFor:'constants'!
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   114
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   115
pi
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   116
    "return the constant pi as Fraction"
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   117
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   118
    ^ self 
6063
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   119
        numerator:  314159265358979323846264343
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   120
        denominator:100000000000000000000000000
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   121
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   122
"/    ^ self 
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   123
"/        numerator:  314159265358979323846264338327950288419716939937510582097494459
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   124
"/        denominator:100000000000000000000000000000000000000000000000000000000000000
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   125
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   126
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   127
     Fraction pi         
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   128
     Fraction pi asFloat
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   129
     Float pi            
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
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   132
    "Modified: 5.11.1996 / 11:11:44 / cg"
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   133
!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   134
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   135
unity
1555
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   136
    "return the neutral element for multiplication (1 / 1)"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   137
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   138
    ^ FractionOne
1555
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   139
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   140
    "Modified: 18.7.1996 / 12:26:06 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   141
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   142
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   143
zero
1555
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   144
    "return the neutral element for addition (0 / 1)"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   145
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   146
    ^ FractionZero
1555
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   147
316491c1b216 commentary
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   148
    "Modified: 18.7.1996 / 12:26:12 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   149
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   150
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   151
!Fraction class methodsFor:'queries'!
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   152
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   153
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   154
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   155
     Here, true is returned for myself, false for subclasses."
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   156
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   157
    ^ self == Fraction
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   158
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   159
    "Modified: 23.4.1996 / 15:59:10 / cg"
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   160
! !
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   161
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   162
!Fraction methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
a27a279701f8 Initial revision
claus
parents:
diff changeset
   164
denominator
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
    "return the denominator"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
    ^ denominator
a27a279701f8 Initial revision
claus
parents:
diff changeset
   168
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   169
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   170
numerator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   171
    "return the numerator"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   172
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   173
    ^ numerator
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   174
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   175
a27a279701f8 Initial revision
claus
parents:
diff changeset
   176
!Fraction methodsFor:'arithmetic'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   177
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   178
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   179
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   181
    |n d|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   182
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   183
    (aNumber isMemberOf:SmallInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   184
        ^ (self class numerator:(numerator * aNumber)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   185
                    denominator:denominator)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   186
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   187
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   188
        aNumber isFixedPoint ifFalse:[  "/ the value was corrent, but the scale is lost
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   189
            n := numerator * aNumber numerator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   190
            d := denominator * aNumber denominator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   191
            ^ (self class numerator:n denominator:d)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   192
        ]
701
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
    (aNumber isMemberOf:Float) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   195
        ^ (numerator * aNumber) / denominator
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   196
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   197
    ^ aNumber productFromFraction:self
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   198
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   199
    "Modified: 28.7.1997 / 19:09:23 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   200
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   201
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   202
+ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   203
    "return the sum of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   204
a27a279701f8 Initial revision
claus
parents:
diff changeset
   205
    |n d|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   206
a27a279701f8 Initial revision
claus
parents:
diff changeset
   207
    (aNumber isMemberOf:SmallInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   208
        ^ (self class numerator:(numerator + (denominator * aNumber))
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   209
                    denominator:denominator)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   210
    ].
259
   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 := aNumber numerator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   214
            d := aNumber denominator.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   215
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   216
            "save a multiplication if possible"
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   217
            denominator == d ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   218
                n := numerator + n
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   219
            ] ifFalse:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   220
                n := (numerator * d) + (n * denominator).
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   221
                d := denominator * d.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   222
            ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   223
            ^ (self class numerator:n denominator:d)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   224
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   225
    ].
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   226
    (aNumber isMemberOf:Float) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   227
        ^ aNumber + (numerator asFloat / denominator asFloat)
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   228
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   229
    ^ aNumber sumFromFraction:self
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   230
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   231
    "Modified: 28.7.1997 / 19:09:16 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   232
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   233
a27a279701f8 Initial revision
claus
parents:
diff changeset
   234
- aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   235
    "return the difference of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   236
a27a279701f8 Initial revision
claus
parents:
diff changeset
   237
    |n d|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   238
a27a279701f8 Initial revision
claus
parents:
diff changeset
   239
    (aNumber isMemberOf:SmallInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   240
        ^ (self class numerator:(numerator - (denominator * aNumber))
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   241
                    denominator:denominator)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   242
    ].
259
   243
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   244
        aNumber isFixedPoint ifFalse:[  "/ the value was corrent, but the scale is lost
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   245
            n := aNumber numerator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   246
            d := aNumber denominator.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   247
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   248
            "save a multiplication if possible"
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   249
            denominator == d ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   250
                n := numerator - n
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   251
            ] ifFalse:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   252
                n := (numerator * d) - (n * denominator).
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   253
                d := denominator * d
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   254
            ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   255
            ^ (self class numerator:n denominator:d)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   256
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   257
    ].
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   258
    (aNumber isMemberOf:Float) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   259
        ^ (numerator asFloat / denominator asFloat) - aNumber
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   260
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   261
    ^ aNumber differenceFromFraction:self
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   262
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   263
    "
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   264
     (1/3) - (1/9)      
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   265
     (1/9) - (1/3)      
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   266
     (999/1000) - (1/1000)      
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   267
     (999/1000) - (1/1000000)      
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   268
     (999000/1000000) - (1/1000000)      
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   269
    "
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   270
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   271
    "Modified: 28.7.1997 / 19:09:11 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   272
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
a27a279701f8 Initial revision
claus
parents:
diff changeset
   274
/ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   275
    "return the quotient of the receiver and the argument, aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
    |n d|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   278
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   279
    (aNumber isMemberOf:SmallInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   280
        ^ (self class numerator:numerator
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   281
                    denominator:(denominator * aNumber))
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   282
    ].
259
   283
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   284
        aNumber isFixedPoint ifFalse:[  "/ the value was corrent, but the scale is lost
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   285
            n := numerator * aNumber denominator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   286
            d := denominator * aNumber numerator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   287
            ^ (self class numerator:n denominator:d)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   288
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   289
    ].
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   290
    (aNumber isMemberOf:Float) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   291
        ^ numerator / (denominator * aNumber)
16
a580032d04f6 *** empty log message ***
claus
parents: 13
diff changeset
   292
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   293
    ^ aNumber quotientFromFraction:self
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   294
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   295
    "Modified: 28.7.1997 / 19:09:06 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   296
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   297
a27a279701f8 Initial revision
claus
parents:
diff changeset
   298
// aNumber
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   299
    "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
   300
     truncation towards negative infinity."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   301
a27a279701f8 Initial revision
claus
parents:
diff changeset
   302
    ^ (numerator * aNumber denominator) // (denominator * aNumber numerator)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   303
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   304
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   305
     0.5 // 1
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   306
     -0.5 // 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3899
diff changeset
   307
     (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
   308
     (-1/2) // 1 = -1 ifFalse:[self halt].
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   309
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   310
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3899
diff changeset
   311
    "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
   312
    "Modified: / 13.2.1998 / 09:15:35 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   313
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   314
a27a279701f8 Initial revision
claus
parents:
diff changeset
   315
negated
a27a279701f8 Initial revision
claus
parents:
diff changeset
   316
    "optional - could use inherited method ..."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   317
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   318
    ^ self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   319
        numerator:(numerator negated)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   320
        denominator:denominator
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   321
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   322
    "Modified: 5.11.1996 / 10:29:11 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   323
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   324
a27a279701f8 Initial revision
claus
parents:
diff changeset
   325
reciprocal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   326
    "optional - could use inherited method ..."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   327
a27a279701f8 Initial revision
claus
parents:
diff changeset
   328
    numerator == 1 ifTrue:[^ denominator].
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   329
    ^ self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   330
        numerator:denominator
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   331
        denominator:numerator
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   332
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   333
    "Modified: 5.11.1996 / 10:29:22 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   334
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   335
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   336
!Fraction methodsFor:'coercing & converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   337
1892
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   338
asFixedPoint
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   339
    "return the receiver as fixedPoint number.
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   340
     Q: what should the scale be here ?"
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   341
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   342
    ^ FixedPoint numerator:numerator denominator:denominator scale:2
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   343
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   344
    "
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   345
     (1/2) asFixedPoint
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   346
    "
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   347
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   348
    "Created: 5.11.1996 / 15:15:54 / cg"
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   349
!
d3564145c15c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1878
diff changeset
   350
2140
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   351
asFixedPoint:scale
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   352
    "return the receiver as fixedPoint number, with the given number
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   353
     of post-decimal-point digits."
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   354
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   355
    ^ FixedPoint numerator:numerator denominator:denominator scale:scale
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   356
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   357
    "
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   358
     (1/2) asFixedPoint:2 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   359
     (1/3) asFixedPoint:2 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   360
     (1/3) asFixedPoint:5 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   361
     (2/3) asFixedPoint:2 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   362
     (2/3) asFixedPoint:5 
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   363
    "
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   364
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   365
    "Created: 5.11.1996 / 15:15:54 / cg"
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   366
    "Modified: 10.1.1997 / 19:54:50 / cg"
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   367
!
5e2def558185 added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   368
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   369
asFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   370
    "return a float with (approximately) my value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   371
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   372
    ^ (numerator asFloat) / (denominator asFloat)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   373
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   374
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   375
asFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   376
    "return the receiver as fraction - thats itself"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   377
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   378
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   379
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   380
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   381
asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   382
    "return an integer with my value - will usually truncate"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   383
a27a279701f8 Initial revision
claus
parents:
diff changeset
   384
    ^ numerator // denominator
a27a279701f8 Initial revision
claus
parents:
diff changeset
   385
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   386
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   387
asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   388
    "return an integer with my value - will usually truncate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   389
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   390
    ^ self asInteger asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   391
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   392
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   393
asShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   394
    "return a shortFloat with (approximately) my value"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   395
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   396
    ^ (numerator asShortFloat) / (denominator asShortFloat)
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   397
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   398
    "Created: 17.4.1996 / 12:21:08 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   399
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   400
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   401
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   402
    "return aNumber converted into receivers type"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   403
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   404
    ^ aNumber asFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   405
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   406
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   407
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   408
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   409
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   410
    ^ 60
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   411
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   412
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   413
!Fraction methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   414
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   415
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   416
    "return true if the receiver is less
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   417
     than aNumber, false otherwise."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   418
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   419
    |d n|
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   420
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   421
    (aNumber isMemberOf:SmallInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   422
        ^ numerator < (denominator * aNumber)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   423
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   424
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   425
        d := aNumber denominator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   426
        n := aNumber numerator.
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   427
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   428
        "/ save a multiplication if possible
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   429
        d == denominator ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   430
            ^ numerator < n
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   431
        ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   432
        ^ (numerator * d) < (denominator * n)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   433
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   434
    ^ aNumber lessFromFraction:self
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   435
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   436
    "Modified: 5.11.1996 / 10:30:52 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   437
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   438
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   439
= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   440
    "return true, if the argument represents the same numeric value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   441
     as the receiver, false otherwise"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   442
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   443
    (aNumber isMemberOf:SmallInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   444
        (denominator = 1) ifFalse:[^ false].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   445
        ^ numerator = aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   446
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   447
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   448
        denominator = aNumber denominator ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   449
            ^ numerator = aNumber numerator
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   450
        ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   451
        ^ self sameFractionValueAs:aNumber
3631
26a44b284912 handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   452
    ].
26a44b284912 handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   453
    (aNumber isInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   454
        (denominator = 1) ifFalse:[^ false].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   455
        ^ numerator = aNumber
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   456
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   457
    ^ self retry:#= coercing:aNumber
3631
26a44b284912 handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   458
26a44b284912 handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
   459
    "Modified: / 7.7.1998 / 17:17:07 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   460
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   461
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   462
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   463
    "return true if the receiver is greater
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   464
     than aNumber, false otherwise."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   465
    "optional - could use inherited method ..."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   466
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   467
    |d n|
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   468
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   469
    (aNumber isMemberOf:SmallInteger) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   470
        ^ numerator > (denominator * aNumber)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   471
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   472
    aNumber isFraction ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   473
        d := aNumber denominator.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   474
        n := aNumber numerator.
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   475
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   476
        "/ save a multiplication if possible
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   477
        d == denominator ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   478
            ^ numerator > n
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   479
        ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   480
        ^ (numerator * d) > (denominator * n)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   481
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   482
    ^ self retry:#> coercing:aNumber
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   483
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   484
    "Modified: 5.11.1996 / 10:31:28 / cg"
4593
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   485
!
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   486
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   487
hash
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   488
    "return a number for hashing; redefined, since fractions compare
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   489
     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
   490
     as 3 hash."
4593
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   491
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   492
    (denominator = 1) ifTrue:[^ numerator hash].
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   493
4594
eb09f567a3bc float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents: 4593
diff changeset
   494
    ^ self asFloat hash
4593
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   495
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   496
    "
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   497
     3 hash           
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   498
     (9/3) hash       
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   499
     3.0 hash         
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   500
     (1/2) hash       
4594
eb09f567a3bc float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents: 4593
diff changeset
   501
     (1/4) hash       
4593
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   502
     0.0 hash         
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   503
     0.5 hash         
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   504
     0.25 hash         
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   505
     0.4 hash         
1023fa0c779e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3984
diff changeset
   506
    "
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   507
!
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   508
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   509
sameFractionValueAs:aNumber
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   510
    "return true, if the argument represents the same numeric value
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   511
     as the receiver, false otherwise"
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   512
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   513
    |rSelf rNum|
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   514
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   515
    rSelf := self reduced.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   516
    rNum := aNumber reduced.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   517
    rSelf denominator = rNum denominator ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   518
        ^ rSelf numerator = rNum numerator
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   519
    ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   520
    ^ false
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   521
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   522
a27a279701f8 Initial revision
claus
parents:
diff changeset
   523
!Fraction methodsFor:'double dispatching'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   524
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   525
differenceFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   526
    "sent when a float does not know how to subtract the receiver, a fraction"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   527
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   528
    ^ (aFloat * denominator - numerator) / denominator
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   529
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   530
a27a279701f8 Initial revision
claus
parents:
diff changeset
   531
differenceFromInteger:anInteger
213
3b56a17534fd *** empty log message ***
claus
parents: 92
diff changeset
   532
    "sent when an integer does not know how to subtract the receiver, a fraction"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   533
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   534
    ^ (self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   535
        numerator:((anInteger * denominator) - numerator)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   536
        denominator:denominator)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   537
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   538
    "Modified: 28.7.1997 / 19:08:53 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   539
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   540
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   541
lessFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   542
    "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
   543
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   544
    ^ (denominator * anInteger) < numerator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   545
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   546
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   547
productFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   548
    "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
   549
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   550
    ^ aFloat * numerator / denominator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   551
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   552
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   553
productFromInteger:anInteger
213
3b56a17534fd *** empty log message ***
claus
parents: 92
diff changeset
   554
    "sent when an integer does not know how to multiply the receiver, a fraction"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   555
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   556
    ^ (self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   557
        numerator:(anInteger * numerator)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   558
        denominator:denominator)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   559
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   560
    "Modified: 28.7.1997 / 19:06:22 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   561
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   562
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   563
quotientFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   564
    "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
   565
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   566
    ^ (aFloat * denominator) / numerator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   567
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   568
324
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
   569
quotientFromInteger:anInteger
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
   570
    "sent when an integer does not know how to divide by the receiver, a fraction"
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
   571
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   572
    ^ (self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   573
        numerator:(anInteger * denominator)
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   574
        denominator:numerator)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   575
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   576
    "Modified: 28.7.1997 / 19:08:46 / cg"
324
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
   577
!
290cfb34ec93 *** empty log message ***
claus
parents: 302
diff changeset
   578
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   579
sumFromFloat:aFloat
213
3b56a17534fd *** empty log message ***
claus
parents: 92
diff changeset
   580
    "sent when a float does not know how to add the receiver, a fraction"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   581
a27a279701f8 Initial revision
claus
parents:
diff changeset
   582
    ^ (aFloat * denominator + numerator) / denominator
a27a279701f8 Initial revision
claus
parents:
diff changeset
   583
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   584
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   585
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   586
    "sent when an integer does not know how to add the receiver, a fraction"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   587
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   588
    ^ (self class 
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   589
        numerator:(numerator + (anInteger * denominator))
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   590
        denominator:denominator)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   591
2792
2ae1f2e3d11f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2790
diff changeset
   592
    "Modified: 28.7.1997 / 19:08:40 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   593
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   594
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   595
!Fraction methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   596
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   597
printOn:aStream
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   598
    "append a printed representation of the receiver to the
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   599
     argument, aStream"
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   600
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   601
    aStream nextPut:$(.
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   602
    numerator printOn:aStream.
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   603
    aStream nextPut:$/.
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   604
    denominator printOn:aStream.
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
   605
    aStream nextPut:$)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   606
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   607
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   608
!Fraction methodsFor:'private'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   609
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   610
reduced
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   611
    "reduce the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   612
2790
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   613
    |gcd den|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   614
2790
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   615
    den := denominator.
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   616
    den < 0 ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   617
        numerator := numerator negated.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   618
        den := denominator := den negated.
2789
e3e8707d26b4 make certain, that denominator is positive (in #reduce)
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
   619
    ].
e3e8707d26b4 make certain, that denominator is positive (in #reduce)
Claus Gittinger <cg@exept.de>
parents: 2140
diff changeset
   620
2790
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   621
    den == 1 ifTrue:[^ numerator].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   622
    numerator == 1 ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   623
    numerator == 0 ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   624
2790
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   625
    gcd := numerator gcd:den.
495b8ea6a4cb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2789
diff changeset
   626
    (gcd ~~ 1) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   627
        numerator := numerator // gcd.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   628
        denominator := den := den // gcd.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   629
        den < 0 ifTrue:[
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   630
            numerator := numerator negated.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   631
            den := denominator := den negated.
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   632
        ].
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   633
        (den == 1) ifTrue:[^ numerator].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   634
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   635
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   636
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   637
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   638
setNumerator:num denominator:den
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   639
    "set both numerator and denominator"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   640
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   641
    numerator := num.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   642
    denominator := den
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   643
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   644
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   645
!Fraction methodsFor:'queries'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   646
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   647
isFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   648
    "return true, if the receiver is some kind of fraction;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   649
     true is returned here - the method is redefined from Object."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   650
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   651
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   652
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   653
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   654
!Fraction methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   655
4658
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   656
isLiteral
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   657
    "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
   658
     (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
   659
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   660
    ^ true
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   661
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   662
!
1a74754fbe91 moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents: 4594
diff changeset
   663
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   664
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   665
    "return true if the receiver is negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   666
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   667
    (numerator < 0) ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   668
        ^ (denominator < 0) not
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   669
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   670
    ^ (denominator < 0)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   671
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   672
5552
31b5cc144476 category changes
Claus Gittinger <cg@exept.de>
parents: 5364
diff changeset
   673
!Fraction methodsFor:'truncation & rounding'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   674
3899
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   675
fractionPart
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   676
    "extract the after-decimal fraction part."
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   677
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   678
    numerator < denominator ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   679
        ^ self
3899
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   680
    ].
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   681
    ^ super fractionPart
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   682
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   683
    "
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   684
     (3/2) fractionPart 
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   685
     (2/3) fractionPart 
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   686
     ((3/2)*(15/4)) fractionPart   
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   687
     ((2/3)*(4/15)) fractionPart   
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   688
    "
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   689
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   690
    "Modified: / 28.10.1998 / 17:15:11 / cg"
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   691
!
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   692
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   693
integerPart
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   694
    "extract the pre-decimal integer part."
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   695
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   696
    numerator < denominator ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   697
        ^ 0
3899
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   698
    ].
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   699
    ^ super integerPart
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   700
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   701
    "
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   702
     (3/2) integerPart       
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   703
     (2/3) integerPart           
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   704
     ((3/2)*(15/4)) integerPart   
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   705
     ((2/3)*(4/15)) integerPart   
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   706
    "
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   707
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   708
    "Modified: / 28.10.1998 / 17:16:10 / cg"
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   709
!
aa9b50cdfced added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents: 3631
diff changeset
   710
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   711
rounded
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   712
    "return the receiver rounded to the nearest integer as integer"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   713
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   714
    "/ mhmh - what about -(1/2)
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   715
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   716
    |t|
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   717
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   718
    self negative ifTrue:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   719
        t := self - (1/2)
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   720
    ] ifFalse:[
5364
a27f5167822c *** empty log message ***
ps
parents: 5322
diff changeset
   721
        t := self + (1/2)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   722
    ].
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   723
    ^ t truncated.
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   724
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   725
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   726
     (1/3) rounded           
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   727
     (1/3) negated rounded     
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   728
     (1/2) rounded           
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   729
     (1/2) negated rounded   
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   730
     0.5 rounded  
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   731
     -0.5 rounded 
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   732
     (2/3) rounded             
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   733
     (2/3) negated rounded     
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   734
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   735
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   736
    "Modified: 5.11.1996 / 11:32:32 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   737
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   738
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   739
truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   740
    "return the receiver truncated towards zero as Integer"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   741
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   742
    ^ numerator quo: denominator
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   743
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   744
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   745
     (3/2) truncated     
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   746
     (3/2) negated truncated  
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   747
    "
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   748
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   749
    "Modified: 5.11.1996 / 12:18:46 / cg"
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
1878
5615af5e7f47 fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   752
!Fraction class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   753
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   754
version
6063
Claus Gittinger <cg@exept.de>
parents: 5552
diff changeset
   755
    ^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.51 2001-10-02 08:15:03 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   756
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   757
Fraction initialize!