[Pkg] The Trunk: Kernel-eem.1335.mcz
commits at source.squeak.org
commits at source.squeak.org
Tue Jul 21 19:33:45 UTC 2020
Eliot Miranda uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-eem.1335.mcz
==================== Summary ====================
Name: Kernel-eem.1335
Author: eem
Time: 21 July 2020, 12:33:42.401688 pm
UUID: 829e7c17-0cb2-4269-a6ca-d85bef9ecc2a
Ancestors: Kernel-mt.1334
Support for FloatArray; add 64-bit duals of the 32-bit float converters, so along side Float>>asIEEE32BitWord & Float class>>fromIEEE32Bit: we have Float>>asIEEE64BitWord & Float class>>fromIEEE64Bit:.
=============== Diff against Kernel-mt.1334 ===============
Item was added:
+ ----- Method: Float class>>fromIEEE64Bit: (in category 'instance creation') -----
+ fromIEEE64Bit: anInteger
+ "Convert the given 64 bit word (which is supposed to be a positive 64-bit value) from
+ a 64 bit IEEE floating point representation into an actual Squeak float object (being
+ 64 bits wide). Should only be used for conversion in FloatArrays or likewise objects."
+ | value |
+ value := self basicNew: 2.
+ value
+ basicAt: 1 put: (anInteger bitShift: -32);
+ basicAt: 2 put: (anInteger bitAnd: 16rFFFFFFFF).
+ ^value isFinite
+ ifTrue: [value * 1.0] "reduce to SmallFloat64 if possible"
+ ifFalse: [value]!
Item was changed:
----- Method: Float>>asIEEE32BitWord (in category 'converting') -----
asIEEE32BitWord
"Convert the receiver into a 32 bit Integer value representing the same number in IEEE 32 bit format.
+ Used for conversion in FloatArrays."
- Used for conversion in FloatArrays only."
+ | word1 word2 sign mantissa exponent truncatedBits mask roundToUpper |
- | word1 word2 sign mantissa exponent destWord truncatedBits mask roundToUpper |
"skip fast positive and nnegative zero"
self = 0.0 ifTrue: [^self basicAt: 1].
"retrieve 64 bits of IEEE 754 double"
word1 := self basicAt: 1.
word2 := self basicAt: 2.
"prepare sign exponent and mantissa of 32 bits float"
sign := word1 bitAnd: 16r80000000.
exponent := ((word1 bitShift: -20) bitAnd: 16r7FF) - 1023 + 127.
mantissa := (word2 bitShift: -29) + ((word1 bitAnd: 16rFFFFF) bitShift: 3).
truncatedBits := (word2 bitAnd: 16r1FFFFFFF).
"We must now honour default IEEE rounding mode (round to nearest even)"
"we are below gradual underflow, even if rounded to upper mantissa"
+ exponent < -24 ifTrue: [^sign]. "this can be negative zero"
- exponent < -24 ifTrue: [^sign "this can be negative zero"].
"BEWARE: rounding occurs on less than 23bits when gradual underflow"
exponent <= 0
ifTrue:
[mask := 1 bitShift: exponent negated.
mantissa := mantissa bitOr: 16r800000.
roundToUpper := (mantissa bitAnd: mask) isZero not
and: [truncatedBits isZero not
or: [(mantissa bitAnd: mask - 1) isZero not
or: [(mantissa bitAnd: mask*2) isZero not]]].
mantissa := mantissa bitShift: exponent - 1.
"exponent := exponent + 1"]
ifFalse:
[roundToUpper := (truncatedBits bitAnd: 16r10000000) isZero not
and: [(mantissa bitAnd: 16r1) isZero not
+ or: [(truncatedBits bitAnd: 16r0FFFFFFF) isZero not]]].
- or: [(truncatedBits bitAnd: 16r0FFFFFFF) isZero not]]
- ].
"adjust mantissa and exponent due to IEEE rounding mode"
+ roundToUpper ifTrue:
+ [mantissa := mantissa + 1.
+ mantissa > 16r7FFFFF ifTrue:
+ [mantissa := 0.
+ exponent := exponent+1]].
- roundToUpper
- ifTrue:
- [mantissa := mantissa + 1.
- mantissa > 16r7FFFFF
- ifTrue:
- [mantissa := 0.
- exponent := exponent+1]].
+ exponent > 254 ifTrue: "Overflow"
+ [exponent := 255.
- exponent > 254 ifTrue: ["Overflow"
- exponent := 255.
self isNaN
ifTrue: [mantissa isZero
ifTrue: ["BEWARE: do not convert a NaN to infinity due to truncatedBits"
mantissa := 1]]
ifFalse: [mantissa := 0]].
"Encode the word"
+ ^(sign bitOr: ((exponent max: 0) bitShift: 23)) bitOr: mantissa!
- destWord := (sign bitOr: ((exponent max: 0) bitShift: 23)) bitOr: mantissa.
- ^ destWord!
Item was added:
+ ----- Method: Float>>asIEEE64BitWord (in category 'converting') -----
+ asIEEE64BitWord
+ "Convert the receiver into a 64 bit Integer value representing the same number in IEEE 64 bit format.
+ Used for conversion in FloatArrays."
+
+ ^((self basicAt: 1) bitShift: 32) + (self basicAt: 2)!
More information about the Packages
mailing list