FixedPoint.st
changeset 2140 5e2def558185
parent 1898 883a1046ca9a
child 2538 6bbfd3558458
equal deleted inserted replaced
2139:54ab2e1f4d93 2140:5e2def558185
   205 
   205 
   206 scale
   206 scale
   207     "Return the number of places of significance that is carried by the receiver."
   207     "Return the number of places of significance that is carried by the receiver."
   208 
   208 
   209     ^ scale
   209     ^ scale
   210 !
       
   211 
       
   212 withScale:newScale
       
   213     "Return a copy of the receiver, with newScale number of post-decimal
       
   214      digits"
       
   215 
       
   216     ^ self class
       
   217         numerator:numerator
       
   218         denominator:denominator
       
   219         scale:newScale
       
   220 
       
   221     "
       
   222      (Fixed fromString:'12345.12345') withScale:2 
       
   223 
       
   224      ((Fixed fromString:'0.33333333')
       
   225       + 
       
   226       (Fixed fromString:'0.33333333')
       
   227      ) withScale:2   
       
   228     "
       
   229 ! !
   210 ! !
   230 
   211 
   231 !FixedPoint methodsFor:'arithmetic'!
   212 !FixedPoint methodsFor:'arithmetic'!
   232 
   213 
   233 * aNumber
   214 * aNumber
   560 ! !
   541 ! !
   561 
   542 
   562 !FixedPoint methodsFor:'coercing & converting'!
   543 !FixedPoint methodsFor:'coercing & converting'!
   563 
   544 
   564 asFixedPoint
   545 asFixedPoint
   565     "return the receiver as a fixedPoint number"
   546     "return the receiver as a fixedPoint number - thats the receiver itself"
   566 
   547 
   567     ^ self
   548     ^ self
   568 
   549 
       
   550     "Modified: 10.1.1997 / 19:53:14 / cg"
       
   551 !
       
   552 
       
   553 asFixedPoint:newScale
       
   554     "Return a copy of the receiver, with newScale number of post-decimal
       
   555      digits"
       
   556 
       
   557     ^ self class
       
   558         numerator:numerator
       
   559         denominator:denominator
       
   560         scale:newScale
       
   561 
       
   562     "
       
   563      (FixedPoint fromString:'12345.12345') asFixedPoint:2 
       
   564 
       
   565      ((FixedPoint fromString:'0.33333333')
       
   566       + 
       
   567       (FixedPoint fromString:'0.33333333')
       
   568      ) asFixedPoint:2   
       
   569     "
       
   570 
       
   571     "Modified: 10.1.1997 / 19:52:25 / cg"
   569 !
   572 !
   570 
   573 
   571 asFraction
   574 asFraction
   572     "return the receiver as a fraction"
   575     "return the receiver as a fraction"
   573 
   576 
   607      1.0 + (FixedPoint fromString:'1.001')      
   610      1.0 + (FixedPoint fromString:'1.001')      
   608      (1/2) + (FixedPoint fromString:'1.001')    
   611      (1/2) + (FixedPoint fromString:'1.001')    
   609      1.0 asShortFloat + (FixedPoint fromString:'1.001')
   612      1.0 asShortFloat + (FixedPoint fromString:'1.001')
   610      1 asLargeInteger + (FixedPoint fromString:'1.001')
   613      1 asLargeInteger + (FixedPoint fromString:'1.001')
   611     "
   614     "
       
   615 !
       
   616 
       
   617 withScale:newScale
       
   618     "Return a copy of the receiver, with newScale number of post-decimal
       
   619      digits"
       
   620 
       
   621     ^ self asFixedPoint:newScale
       
   622 
       
   623     "
       
   624      (FixedPoint fromString:'12345.12345') withScale:2 
       
   625 
       
   626      ((FixedPoint fromString:'0.33333333')
       
   627       + 
       
   628       (FixedPoint fromString:'0.33333333')
       
   629      ) withScale:2   
       
   630     "
       
   631 
       
   632     "Modified: 10.1.1997 / 19:52:54 / cg"
   612 ! !
   633 ! !
   613 
   634 
   614 !FixedPoint methodsFor:'double dispatching'!
   635 !FixedPoint methodsFor:'double dispatching'!
   615 
   636 
   616 differenceFromInteger:anInteger
   637 differenceFromInteger:anInteger
   821 ! !
   842 ! !
   822 
   843 
   823 !FixedPoint class methodsFor:'documentation'!
   844 !FixedPoint class methodsFor:'documentation'!
   824 
   845 
   825 version
   846 version
   826     ^ '$Header: /cvs/stx/stx/libbasic/FixedPoint.st,v 1.5 1996-11-05 19:45:04 cg Exp $'
   847     ^ '$Header: /cvs/stx/stx/libbasic/FixedPoint.st,v 1.6 1997-01-10 18:55:31 cg Exp $'
   827 ! !
   848 ! !