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 Kernel-nice.1232 ===============
Item was removed:
- ----- Method: LargePositiveInteger>>sqrt2 (in category 'mathematical functions') -----
- "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
- [self mightBeASquare ifFalse: ["we know for sure no exact solution exists,
- just answer the cheap float approximation without wasting time."
- "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"