The Trunk: Kernel-nice.1377.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.1377.mcz

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

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

Name: Kernel-nice.1377
Author: nice
Time: 4 March 2021, 10:10:29.295967 pm
UUID: ddcc60af-76a7-4d50-b5e3-ebf4ff39eb07
Ancestors: Kernel-nice.1376

Fix log2 implementation to make it robust in the neighbourhood of 1.0.

Let aFloat isPowerOfTwo answer true if its value is a power of two. There is no obvious reason nor documentation why it should be false, and the implementation is neat.

Introduce isDenormal to test if a Float is denormalized. A denormalized Float is one with minimal exponent, and significand part gradually loosing significant bits (a.k.a. gradual underflow).

I.O.W, denormals loose precision.
If we would define:

Float>>precision
        ^(self exponent - Float emin min: 0) + self class precision
       
Then, we would have
Float fminNormalized precision = Float precision.
Float fminNormalized predecessor = (Float precision - 1).
Float fminDenormalized precision = 1.

=============== Diff against Kernel-nice.1376 ===============

Item was added:
+ ----- Method: Float>>isDenormal (in category 'testing') -----
+ isDenormal
+ "Return true if the receiver is a denormal."
+
+ ^ self exponent < self class emin and: [self isZero not]!

Item was changed:
  ----- Method: Float>>isPowerOfTwo (in category 'testing') -----
  isPowerOfTwo
+ "Return true if the receiver is an integral power of two."
+ ^self significand = 1.0!
- "Return true if the receiver is an integral power of two.
- Floats never return true here."
- ^false!

Item was changed:
  ----- Method: Float>>log2 (in category 'mathematical functions') -----
  log2
  "Answer the base 2 logarithm of the receiver.
  Arrange to answer exact result in case of exact power of 2."
 
+ |  s  |
+ s := self significand.
+ ^s > 1.3333333333333333
+ ifTrue: [(0.5 * s) ln / Ln2 + (1 + self exponent)]
+ ifFalse: [s ln / Ln2 + self exponent]!
- ^ self significand ln / Ln2 + self exponent!