diff -r 9aa286d3a644 -r 64f27ed2753f FixedPoint.st --- a/FixedPoint.st Tue Nov 26 11:06:34 2002 +0100 +++ b/FixedPoint.st Tue Nov 26 11:41:25 2002 +0100 @@ -15,10 +15,10 @@ "{ Package: 'stx:libbasic' }" Fraction subclass:#FixedPoint - instanceVariableNames:'scale' - classVariableNames:'PI_1000' - poolDictionaries:'' - category:'Magnitude-Numbers' + instanceVariableNames:'scale' + classVariableNames:'PI_1000' + poolDictionaries:'' + category:'Magnitude-Numbers' ! FixedPoint comment:' @@ -166,8 +166,8 @@ numerator:n denominator:d scale:s ^ self basicNew - setNumerator:n denominator:d scale:s; - reduced + setNumerator:n denominator:d scale:s + "/ ; reduced ! readFrom:aStringOrStream @@ -189,60 +189,6 @@ " "Modified: / 25.10.1997 / 15:30:29 / cg" -! - -readFrom:aStringOrStream onError:exceptionBlock - "return an instance of me as described on the string or stream, aStringOrStream. - If an error occurs during conversion, return the result - from evaluating exceptionBlock" - - | aStream sign integerPart fractionStream char fractionPart scale | - - aStream := aStringOrStream readStream. - - aStream peek == $- ifTrue:[ - sign := -1. - aStream next. - ] ifFalse:[ - sign := 1 - ]. - - (aStream atEnd or:[aStream peek isLetter]) ifTrue: [^ exceptionBlock value]. - - integerPart := (aStream upTo:$.) asNumber. - (aStream atEnd or: [aStream peek isLetter]) ifTrue: [ - fractionPart := 0. - scale := 1. - ] ifFalse:[ - fractionStream := ReadWriteStream on:(String new: 10). - [ - char := aStream next. - char ~~ nil and:[char isDigit] - ] whileTrue:[ - fractionStream nextPut:char - ]. - - scale := fractionStream positionStartingAt0. - fractionStream reset. - fractionPart := Number readFrom:fractionStream. - ]. - - ^ self basicNew - setNumerator:(integerPart * (10 raisedTo:scale) + fractionPart) * sign - scale:scale - - " - FixedPoint readFrom:'123.456' - FixedPoint readFrom:'-123.456' - FixedPoint readFrom:'123' - FixedPoint readFrom:'-123' - FixedPoint readFrom:'-123.abcd' onError:[47.5] - FixedPoint readFrom:'-1a.bcd' onError:[47.5] - FixedPoint readFrom:'foot' onError:['bad fixedpoint'] - " - - "Created: / 25.10.1997 / 15:28:59 / cg" - "Modified: / 25.10.1997 / 15:31:47 / cg" ! ! !FixedPoint class methodsFor:'constants'! @@ -264,6 +210,7 @@ " ! ! + !FixedPoint methodsFor:'accessing'! scale @@ -371,7 +318,7 @@ + aNumber "return the sum of the receiver and the argument, aNumber. Redefined to care for the scale if the argument is another fixPoint number. - The resulting scale will be the maximum of the receivers and the + The results scale will be the maximum of the receivers and the arguments scale." |n d| @@ -570,9 +517,9 @@ aNumber isInteger ifTrue:[ ^ self class - numerator:numerator - denominator:(denominator * aNumber) - scale:scale + numerator:numerator + denominator:(denominator * aNumber) + scale:scale ]. aNumber isFraction ifTrue:[ @@ -637,7 +584,7 @@ ! negated - "have to redefine it from Fraction" + "redefined from Fraction to preserve scale" ^ self class numerator:(numerator negated) @@ -646,7 +593,7 @@ ! reciprocal - "have to redefine it from Fraction" + "redefined from Fraction to preserve scale" numerator == 1 ifTrue:[^ denominator]. ^ self class @@ -943,6 +890,7 @@ "Modified: 12.4.1997 / 11:22:02 / cg" ! ! + !FixedPoint methodsFor:'testing'! isFixedPoint @@ -957,5 +905,5 @@ !FixedPoint class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/FixedPoint.st,v 1.21 2002-11-25 09:19:48 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/FixedPoint.st,v 1.22 2002-11-26 10:41:25 cg Exp $' ! !