ArithmeticValue.st
changeset 24956 dc04e2668278
parent 24861 68e1f568f097
child 24963 3f40782dfac4
equal deleted inserted replaced
24955:383d5baf43e1 24956:dc04e2668278
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1993 by Claus Gittinger
     2  COPYRIGHT (c) 1993 by Claus Gittinger
     5 	      All Rights Reserved
     3 	      All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
   518      Abstract subclasses must redefine this again."
   516      Abstract subclasses must redefine this again."
   519 
   517 
   520     ^ self == ArithmeticValue
   518     ^ self == ArithmeticValue
   521 ! !
   519 ! !
   522 
   520 
   523 
       
   524 !ArithmeticValue methodsFor:'arithmetic'!
   521 !ArithmeticValue methodsFor:'arithmetic'!
   525 
   522 
   526 * something
   523 * something
   527     "return the product of the receiver and the argument."
   524     "return the product of the receiver and the argument."
   528 
   525 
  1830     "use the addition chaining algorithm,
  1827     "use the addition chaining algorithm,
  1831      which is much faster for big exponents"
  1828      which is much faster for big exponents"
  1832 
  1829 
  1833     result := 1.
  1830     result := 1.
  1834     t := self.
  1831     t := self.
  1835     exp < 0 ifTrue:[
  1832     (e := exp) < 0 ifTrue:[
  1836         e := exp negated.
  1833         e := exp negated.
  1837     ] ifFalse:[
       
  1838         e := exp.
       
  1839     ].
  1834     ].
  1840 
  1835 
  1841     [e ~~ 0] whileTrue:[
  1836     [e ~~ 0] whileTrue:[
  1842         [(e bitAnd:1) == 0] whileTrue:[
  1837         [(e bitAnd:1) == 0] whileTrue:[
  1843             e := e bitShift:-1.
  1838             e := e bitShift:-1.
  1852     ].
  1847     ].
  1853 
  1848 
  1854     ^ result
  1849     ^ result
  1855 
  1850 
  1856     "
  1851     "
  1857      (2.0 raisedToInteger:216)
       
  1858      (2 raisedToInteger:216)
  1852      (2 raisedToInteger:216)
       
  1853      (2.0 raisedToInteger:216)  
       
  1854      (2.0 asLongFloat) raisedToInteger:216
       
  1855      (2.0 asShortFloat) raisedToInteger:216
       
  1856      (2.0 asQDouble) raisedToInteger:216
       
  1857 
  1859      (2 raisedTo:216)
  1858      (2 raisedTo:216)
  1860             -> 105312291668557186697918027683670432318895095400549111254310977536
  1859             -> 105312291668557186697918027683670432318895095400549111254310977536
       
  1860      (2.0 raisedToInteger:216) asInteger - (2 raisedToInteger:216) 
       
  1861      (2.0 raisedToInteger:400) asInteger - (2 raisedToInteger:400) 
       
  1862      (2.0 raisedToInteger:500) asInteger - (2 raisedToInteger:500)  
       
  1863      (2.0 raisedToInteger:1000) asInteger - (2 raisedToInteger:1000)  
  1861 
  1864 
  1862      (2 raisedToInteger:216) asFloat
  1865      (2 raisedToInteger:216) asFloat
  1863      (2 raisedTo:216) asFloat
  1866      (2 raisedTo:216) asFloat
  1864             -> 1.05312E+65
  1867             -> 1.05312E+65
  1865 
  1868 
  1981     "return receiver * receiver"
  1984     "return receiver * receiver"
  1982 
  1985 
  1983     ^ self * self
  1986     ^ self * self
  1984 ! !
  1987 ! !
  1985 
  1988 
  1986 
       
  1987 !ArithmeticValue methodsFor:'queries'!
  1989 !ArithmeticValue methodsFor:'queries'!
  1988 
  1990 
  1989 respondsToArithmetic
  1991 respondsToArithmetic
  1990     "return true, if the receiver responds to arithmetic messages"
  1992     "return true, if the receiver responds to arithmetic messages"
  1991 
  1993