LimitedPrecisionReal.st
changeset 2141 bba0027204fd
parent 1893 c66af5c46272
child 2388 df5e0eb88999
equal deleted inserted replaced
2140:5e2def558185 2141:bba0027204fd
   145 
   145 
   146     ^ (self - ((self / aNumber) floor * aNumber)) floor asInteger
   146     ^ (self - ((self / aNumber) floor * aNumber)) floor asInteger
   147 ! !
   147 ! !
   148 
   148 
   149 !LimitedPrecisionReal methodsFor:'coercion and converting'!
   149 !LimitedPrecisionReal methodsFor:'coercion and converting'!
       
   150 
       
   151 asFixedPoint
       
   152     "return the receiver as fixedPoint number.
       
   153      Q: what should the scale be here ?"
       
   154 
       
   155     ^ self asFraction asFixedPoint
       
   156 
       
   157     "
       
   158      0.3 asFixedPoint
       
   159      0.5 asFixedPoint
       
   160      (1/5) asFloat asFixedPoint 
       
   161      (1/3) asFloat asFixedPoint 
       
   162      (2/3) asFloat asFixedPoint 
       
   163      (1/8) asFloat asFixedPoint
       
   164      3.14159 asFixedPoint
       
   165     "
       
   166 
       
   167     "Modified: 10.1.1997 / 19:59:56 / cg"
       
   168 !
       
   169 
       
   170 asFixedPoint:scale
       
   171     "return the receiver as fixedPoint number with the given
       
   172      number of post-decimal-digits."
       
   173 
       
   174     ^ self asFraction asFixedPoint:scale
       
   175 
       
   176     "
       
   177      0.3 asFixedPoint:3     
       
   178      0.5 asFixedPoint:3     
       
   179      (1/5) asFloat asFixedPoint:1  
       
   180      (1/8) asFloat asFixedPoint:1  
       
   181      3.14159 asFixedPoint:2       
       
   182      3.14159 asFixedPoint:3       
       
   183      (3.14159 asFixedPoint:2) asFixedPoint:5  
       
   184     "
       
   185 
       
   186     "Modified: 10.1.1997 / 19:59:42 / cg"
       
   187 !
   150 
   188 
   151 asFraction
   189 asFraction
   152     "return a corresponding fraction
   190     "return a corresponding fraction
   153      - notice, that 'aFract asFloat asFraction' does not always return
   191      - notice, that 'aFract asFloat asFraction' does not always return
   154      a good fraction ... due to rounding errors when converting to float"
   192      a good fraction ... due to rounding errors when converting to float"
   399 ! !
   437 ! !
   400 
   438 
   401 !LimitedPrecisionReal class methodsFor:'documentation'!
   439 !LimitedPrecisionReal class methodsFor:'documentation'!
   402 
   440 
   403 version
   441 version
   404     ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.17 1996-11-05 18:38:50 cg Exp $'
   442     ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.18 1997-01-10 19:01:23 cg Exp $'
   405 ! !
   443 ! !