[squeak-dev] The Trunk: Kernel-nice.843.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Mar 21 17:29:45 UTC 2014


Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.843.mcz

==================== Summary ====================

Name: Kernel-nice.843
Author: nice
Time: 21 March 2014, 6:28:55.456 pm
UUID: 28ea5418-9be7-964b-b0c1-fde1bf8528a3
Ancestors: Kernel-nice.842

Correct the bug I introduced for large integer sqrtFloor.

If receiver was of the form 2^2n*u
we did answer 2^n *E(sqrt(u))

But sqrt(u) = E(sqrt(u)) + residue
where 0<=residue<1
And result is rather
	E(2^n*sqrt(u))
	= E( 2^n*(E(sqrt(u)) + residue))
	= 2^n*E(sqrt(u)) + E(2^n*residue)

As 2^n * residue can be big (superior to 1), we miss the correct value by default.

If we want to correct this, an approximation of residue is (u-E(sqrt(u))^2) / 2 E(sqrt(u))
This is more or less like super Newton-Raphson inner loop...
It would be possible to duplicate super work, but I feel like it's adding too much complexity for small reward, so I prefer to remove offending code for now

=============== Diff against Kernel-nice.842 ===============

Item was removed:
- ----- 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 Squeak-dev mailing list