[Pkg] The Trunk: Kernelnice.1233.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon May 13 16:33:34 UTC 2019
Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernelnice.1233.mcz
==================== Summary ====================
Name: Kernelnice.1233
Author: nice
Time: 13 May 2019, 6:32:30.507955 pm
UUID: 8ba1a42b88c816418a1abea810163ec2
Ancestors: Kernelnice.1232
Oups fix creeping of sqrt2, it was only for bench purpose.
Sorry for multiple commits.
I rely too much on (alt shift i) to ignore methods, but sometimes I miss one.
It would be cool to have a way to hide the ignored methods before committing.
=============== Diff against Kernelnice.1232 ===============
Item was removed:
  Method: LargePositiveInteger>>sqrt2 (in category 'mathematical functions') 
 sqrt2
 "Answer the square root of the receiver.
 If the square root is exact, answer an Integer, else answer a Float approximation.
 Handle some tricky case of Float overflow or inaccuracy"

  selfAsFloat floatResult integerResult 
 selfAsFloat := self asFloat.
 floatResult := selfAsFloat sqrt.
 floatResult isFinite
 ifTrue:
 [self mightBeASquare ifFalse: ["we know for sure no exact solution exists,
 just answer the cheap float approximation without wasting time."
 ^floatResult].
 "Answer integerResult in case of perfect square"
 integerResult := floatResult truncated.
 integerResult squared = self ifTrue: [^integerResult]].

 "In this case, maybe it failed because we are such a big integer that the Float method becomes
 inexact, even if we are a whole square number. So, try the slower but more general method"
 selfAsFloat >= Float maxExactInteger asFloat squared
 ifTrue: [
 integerResult := self sqrtFloor.
 integerResult squared = self ifTrue: [
 ^integerResult ].

 "Nothing else can be done. No exact answer means answer must be a Float.
 Answer the best we have which is the rounded sqrt."
 integerResult := (self bitShift: 2) sqrtFloor.
 ^((integerResult bitShift: 1) + (self bitAnd: 1)) asFloat].

 "We need an approximate result"
 ^floatResult!
More information about the Packages
mailing list