LargeInteger.st
changeset 6480 4ff7f2af25fc
parent 6359 fcb206734265
child 6665 8698bfaf34e2
equal deleted inserted replaced
6479:2a0abedfbbd3 6480:4ff7f2af25fc
   952     "
   952     "
   953 !
   953 !
   954 
   954 
   955 lowBit
   955 lowBit
   956     "return the bitIndex of the lowest bit set. The returned bitIndex
   956     "return the bitIndex of the lowest bit set. The returned bitIndex
   957      starts at 1 for the least significant bit. Returns -1 if no bit is set.
   957      starts at 1 for the least significant bit. 
       
   958      Returns 0 if no bit is set.
   958      For negative numbers, the low bit of my absolute value is returned.
   959      For negative numbers, the low bit of my absolute value is returned.
   959      Redefined here for more performance of the gcd: algorithm, which
   960      Redefined here for more performance of the gcd: algorithm, which
   960      is used when big fractions are reduced."
   961      is used when big fractions are reduced (should we write a primitive for this ?)."
   961 
   962 
   962     |sz "{ Class: SmallInteger }"
   963     |sz "{ Class: SmallInteger }"
   963      byte|
   964      byte|
   964 
   965 
   965     sz := digitByteArray size.
   966     sz := digitByteArray size.
   966     1 to:sz do:[:digitIndex |
   967     1 to:sz do:[:digitIndex |
   967 	(byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
   968         (byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
   968 	    ^ (digitIndex-1)*8 + byte lowBit
   969             ^ (digitIndex-1)*8 + byte lowBit
   969 	]
   970         ]
   970     ].
   971     ].
   971     ^ -1
   972     ^ 0 "/ should not happen
   972 
   973 
   973     "
   974     "
   974      (1 bitShift:30) lowBit  
   975      (1 bitShift:30) lowBit  
   975      (1 bitShift:30) highBit  
   976      (1 bitShift:30) highBit  
   976      (1 bitShift:31) lowBit   
   977      (1 bitShift:31) lowBit   
   982      (1 bitShift:64) lowBit 
   983      (1 bitShift:64) lowBit 
   983      (1 bitShift:64) highBit  
   984      (1 bitShift:64) highBit  
   984      (1 bitShift:1000) lowBit
   985      (1 bitShift:1000) lowBit
   985      (1 bitShift:1000) highBit
   986      (1 bitShift:1000) highBit
   986      ((1 bitShift:64)-1) lowBit
   987      ((1 bitShift:64)-1) lowBit
   987      ((1 bitShift:64)-1) highBit  
   988      ((1 bitShift:64)-1) highBit 
       
   989 
       
   990      |num|
       
   991 
       
   992      num := (1 bitShift:1000).
       
   993      Time millisecondsToRun:[
       
   994         100000 timesRepeat:[
       
   995             num lowBit
       
   996         ]
       
   997      ]
   988     "
   998     "
   989 
   999 
   990     "Modified: 14.8.1997 / 11:55:34 / cg"
  1000     "Modified: 14.8.1997 / 11:55:34 / cg"
   991 ! !
  1001 ! !
   992 
  1002 
  4396 ! !
  4406 ! !
  4397 
  4407 
  4398 !LargeInteger class methodsFor:'documentation'!
  4408 !LargeInteger class methodsFor:'documentation'!
  4399 
  4409 
  4400 version
  4410 version
  4401     ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.163 2002-01-14 10:47:02 cg Exp $'
  4411     ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.164 2002-03-28 10:49:33 cg Exp $'
  4402 ! !
  4412 ! !