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

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

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

Name: Kernel-nice.317
Author: nice
Time: 2 December 2009, 5:38:45 am
UUID: 07b501b4-4f30-564e-9645-1322d5aafa09
Ancestors: Kernel-nice.316

A faster successor/predecessor implementation thanks to suggestions of Paolo Bonzini and the help of #ulp (unit of least precision - that is the least significant bit of a Float).
It works well with default IEEE754 rounding mode (round to nearest even). Don't know about alternate modes, but we don't use them right now.

=============== Diff against Kernel-nice.316 ===============

Item was changed:
  ----- Method: Float>>predecessor (in category 'truncation and round off') -----
  predecessor
+ | ulp |
- | mantissa biasedExponent |
  self isFinite ifFalse: [
  (self isNaN or: [self negative]) ifTrue: [^self].
  ^Float fmax].
  self = 0.0 ifTrue: [^Float fmin negated].
+ ulp := self ulp.
+ ^self - (0.5 * ulp) = self
+ ifTrue: [self - ulp]
+ ifFalse: [self - (0.5 * ulp)]!
- mantissa := self significandAsInteger.
- (mantissa isPowerOfTwo and: [self positive]) ifTrue: [mantissa := mantissa bitShift: 1].
- biasedExponent := self exponent - mantissa highBit + 1.
- ^self sign * (mantissa - self sign) asFloat timesTwoPower: biasedExponent!

Item was added:
+ ----- Method: Float>>ulp (in category 'truncation and round off') -----
+ ulp
+ "Answer the unit of least precision of self (the power of two corresponding to last bit of mantissa)"
+
+ | exponent |
+ self isFinite ifFalse: [
+ self isNaN ifTrue: [^self].
+ ^Float infinity].
+ self = 0.0 ifTrue: [^Float fmin].
+ exponent := self exponent.
+ ^exponent < self class emin
+ ifTrue: [Float fminDenormalized]
+   ifFalse: [Float epsilon timesTwoPower: exponent]!

Item was changed:
  ----- Method: Float>>successor (in category 'truncation and round off') -----
  successor
+ | ulp |
- | mantissa biasedExponent |
  self isFinite ifFalse: [
  (self isNaN or: [self positive]) ifTrue: [^self].
  ^Float fmax negated].
  self = 0.0 ifTrue: [^Float fmin].
+ ulp := self ulp.
+ ^self + (0.5 * ulp) = self
+ ifTrue: [self + ulp]
+ ifFalse: [self + (0.5 * ulp)]!
- mantissa := self significandAsInteger.
- (mantissa isPowerOfTwo and: [self negative]) ifTrue: [mantissa := mantissa bitShift: 1].
- biasedExponent := self exponent - mantissa highBit + 1.
- ^self sign * (mantissa + self sign) asFloat timesTwoPower: biasedExponent!