The Trunk: Kernel-nice.1233.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Kernel-nice.1233.mcz

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

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

Name: Kernel-nice.1233
Author: nice
Time: 13 May 2019, 6:32:30.507955 pm
UUID: 8ba1a42b-88c8-1641-8a1a-bea810163ec2
Ancestors: Kernel-nice.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 Kernel-nice.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!