[squeakdev] The Trunk: Kernelnice.638.mcz
commits at source.squeak.org
commits at source.squeak.org
Fri Oct 14 22:02:03 UTC 2011
Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernelnice.638.mcz
==================== Summary ====================
Name: Kernelnice.638
Author: nice
Time: 15 October 2011, 12:01:04.127 am
UUID: 83cd4ee48be1410e9663dcbd2e6f07b9
Ancestors: Kernelnice.637
Cheaper #mightBeASquare (only test expensive lowBit where necessary).
Remove powers of 2 before performing sqrtFloor on a large integer.
=============== Diff against Kernelnice.637 ===============
Item was changed:
 Method: LargePositiveInteger>>mightBeASquare (in category 'mathematical functions') 
mightBeASquare
"In base 16, a square number can end only with 0,1,4 or 9 and
 in case 0, only 0,1,4,9 can precede it,
 in case 4, only even numbers can precede it.
See http://en.wikipedia.org/wiki/Square_number
So, in hex, the last byte must be one of:
00
10
40
90
x1
e4
x9
where x is any hex digit and e is any even digit
Also, the receiver must be an aven power of two."
 lsb 
lsb := self digitAt: 1.
+ ^(lsb = 0 and: [ self lowBit odd ]) "00 (and even power of 2)"
+ or: [ lsb = 16r40 "40"
+ or: [ (lsb bitAnd: 16r7) = 1 "any1 or any9"
+ or: [ (lsb bitAnd: 16r1F) = 4 "even4"
+ or: [ (lsb bitAnd: 16r7F) = 16 ]]]] "10 or 90"!
 ^((lsb bitAnd: 7) = 1 "any1 or any9"
 or: [(lsb bitAnd: 31) = 4 "even4"
 or: [(lsb bitAnd: 127) = 16 "10 or 90"
 or: [(lsb bitAnd: 191) = 0]]]) "00 or 40"
 and: [self lowBit odd] "even power of 2"!
Item was added:
+  Method: LargePositiveInteger>>sqrtFloor (in category 'mathematical functions') 
+ sqrtFloor
+ "Return the integer part of the square root of self"
+
+  powerOfTwo 
+ (powerOfTwo := self lowBit  1 // 2) > 1
+ ifFalse: [^super sqrtFloor].
+ ^(self bitShift: 2 * powerOfTwo) sqrtFloor bitShift: powerOfTwo!
More information about the Squeakdev
mailing list
