[squeak-dev] The Trunk: Kernel-nice.316.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Dec 2 16:34:49 UTC 2009


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

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

Name: Kernel-nice.316
Author: nice
Time: 2 December 2009, 5:34:34 am
UUID: b108354a-6b8e-8b48-8c9c-fc6c8b47b84c
Ancestors: Kernel-ar.315

Add the ANSI float characterization methods every other Smalltalk has but Squeak.
Also add #predecessor and #successor.
These changes are already in Pharo.

=============== Diff against Kernel-ar.315 ===============

Item was added:
+ ----- Method: Float>>predecessor (in category 'truncation and round off') -----
+ predecessor
+ 	| mantissa biasedExponent |
+ 	self isFinite ifFalse: [
+ 		(self isNaN or: [self negative]) ifTrue: [^self].
+ 		^Float fmax].
+ 	self = 0.0 ifTrue: [^Float fmin negated].
+ 	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 class>>emin (in category 'constants') -----
+ emin
+ 	"Answer exponent of minimal normalized representable value"
+ 	
+ 	^-1022!

Item was added:
+ ----- Method: Float class>>fmax (in category 'constants') -----
+ fmax
+ 	"Answer the maximum finite floating point value representable."
+ 	
+ 	^MaxVal!

Item was added:
+ ----- Method: Float class>>emax (in category 'constants') -----
+ emax
+ 	"Answer exponent of maximal representable value"
+ 	
+ 	^1023!

Item was added:
+ ----- Method: Float class>>precision (in category 'constants') -----
+ precision
+ 	"Answer the apparent precision of the floating point representation.
+ 	That is the maximum number of radix-based digits (bits if radix=2) representable in floating point without round off error.
+ 	Technically, 52 bits are stored in the representation, and normalized numbers have an implied leading 1 that does not need to be stored.
+ 	Note that denormalized floating point numbers don't have the implied leading 1, and thus gradually loose precision.
+ 	This format conforms IEEE 754 double precision standard."
+ 	
+ 	^53!

Item was added:
+ ----- Method: Float class>>fminDenormalized (in category 'constants') -----
+ fminDenormalized
+ 	"Answer the minimum denormalized value representable."
+ 	
+ 	^1.0 timesTwoPower: MinValLogBase2!

Item was added:
+ ----- Method: Float class>>fminNormalized (in category 'constants') -----
+ fminNormalized
+ 	"Answer the minimum normalized value representable."
+ 	
+ 	^1.0 timesTwoPower: -1022!

Item was added:
+ ----- Method: Float>>successor (in category 'truncation and round off') -----
+ successor
+ 	| mantissa biasedExponent |
+ 	self isFinite ifFalse: [
+ 		(self isNaN or: [self positive]) ifTrue: [^self].
+ 		^Float fmax negated].
+ 	self = 0.0 ifTrue: [^Float fmin].
+ 	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!

Item was changed:
  ----- Method: Float>>truncated (in category 'truncation and round off') -----
  truncated
  	"Answer with a SmallInteger equal to the value of the receiver without 
  	its fractional part. The primitive fails if the truncated value cannot be 
  	represented as a SmallInteger. In that case, the code below will compute 
  	a LargeInteger truncated value.
  	Essential. See Object documentation whatIsAPrimitive. "
  
  	<primitive: 51>
+ 	self isFinite ifFalse: [self error: 'Cannot truncate this number'].
- 	(self isInfinite or: [self isNaN]) ifTrue: [self error: 'Cannot truncate this number'].
  
  	self abs < 2.0e16
  		ifTrue: ["Fastest way when it may not be an integer"
- 				"^ (self quo: 1073741823.0) * 1073741823 + (self rem: 1073741823.0) truncated"
  				| di df q r |
+ 				di := 1 + (SmallInteger maxVal bitShift: -1).
- 				di := (SmallInteger maxVal bitShift: -1)+1.
  				df := di asFloat.
  				q := self quo: df.
  				r := self - (q asFloat * df).
+ 				^q * di + r truncated]
- 				^q*di+r truncated]
  		ifFalse: [^ self asTrueFraction.  "Extract all bits of the mantissa and shift if necess"]
  
  		
  
  		!

Item was added:
+ ----- Method: Float class>>radix (in category 'constants') -----
+ radix
+ 	"Answer the radix used for internal floating point representation."
+ 	
+ 	^2!

Item was added:
+ ----- Method: Float class>>epsilon (in category 'constants') -----
+ epsilon
+ 	"Answer difference between 1.0 and previous representable value"
+ 	
+ 	^1.0 timesTwoPower: 1 - self precision!

Item was added:
+ ----- Method: Float class>>denormalized (in category 'constants') -----
+ denormalized
+ 	"Answer whether implementation supports denormalized numbers (also known as gradual underflow)."
+ 	
+ 	^true!

Item was added:
+ ----- Method: Float class>>fmin (in category 'constants') -----
+ fmin
+ 	"Answer minimum positive representable value."
+ 	
+ 	^self denormalized
+ 		ifTrue: [self fminDenormalized]
+ 		ifFalse: [self fminNormalized]!




More information about the Squeak-dev mailing list