Nicolas Cellier uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-nice.226.mcz ==================== Summary ==================== Name: KernelTests-nice.226 Author: nice Time: 7 June 2012, 1:12:48.044 am UUID: d84ccfc2-ae1e-4e9e-b3e1-3382f15c40c0 Ancestors: KernelTests-nice.225 Document #significand, #exponent and #significandAsInteger with some tests. Note that I don't expect an implied leading one in case of exceptional values. Reclassify a few miss-classified Float tests =============== Diff against KernelTests-nice.225 =============== Item was changed: + ----- Method: FloatTest>>testArcTan (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testArcTan (in category 'testing') ----- testArcTan self assert: ((100 arcTan: 100) closeTo: Float pi / 4). self assert: ((-100 arcTan: 100) closeTo: Float pi / -4). self assert: ((100 arcTan: -100) closeTo: Float pi * 3 / 4). self assert: ((-100 arcTan: -100) closeTo: Float pi * -3 / 4). self assert: ((0 arcTan: 100) closeTo: 0). self assert: ((0 arcTan: -100) closeTo: Float pi). self assert: ((100 arcTan: 0) closeTo: Float pi / 2). self assert: ((-100 arcTan: 0) closeTo: Float pi / -2). self assert: ((Float negativeZero arcTan: 100) closeTo: 0). self assert: ((Float negativeZero arcTan: -100) closeTo: Float pi * -1). self assert: (0 arcTan: 0) = 0. self assert: (Float negativeZero arcTan: 0) = 0. self assert: ((0 arcTan: Float negativeZero) closeTo: Float pi). self assert: ((Float negativeZero arcTan: Float negativeZero) closeTo: Float pi negated). ! Item was changed: + ----- Method: FloatTest>>testReciprocal (in category 'testing - arithmetic') ----- - ----- Method: FloatTest>>testReciprocal (in category 'NaN behavior') ----- testReciprocal self assert: 1.0 reciprocal = 1.0; assert: 2.0 reciprocal = 0.5; assert: -1.0 reciprocal = -1.0; assert: -2.0 reciprocal = -0.5. self should: [ 0.0 reciprocal ] raise: ZeroDivide! Item was added: + ----- Method: FloatTest>>testSignificandAndExponent (in category 'characterization') ----- + testSignificandAndExponent + | denormals exceptionals normals | + + normals := {Float pi. Float pi * 100.0. Float pi/ -100.0. Float fmax. Float fminNormalized}. + denormals := {0.0. Float negativeZero. Float fminNormalized predecessor. Float fmin negated}. + exceptionals := {Float nan. Float infinity. Float infinity negated.}. + + normals , denormals , exceptionals do: [:aFloat | + "Any Float can be decomposed into its significand and exponent, and the significand holds the sign" + aFloat isNaN + ifTrue: [self assert: (aFloat significand timesTwoPower: aFloat exponent) isNaN] + ifFalse: [self + assert: (aFloat significand timesTwoPower: aFloat exponent) + equals: aFloat]]. + + normals , denormals do: [:aFloat | + "The significand magnitude is in interval [1.0,2.0( " + aFloat = 0.0 + ifTrue: [self assert: aFloat significand equals: 0] + ifFalse: [self + assert: aFloat significand abs >= 1.0; + assert: aFloat significand abs < 2.0]]! Item was added: + ----- Method: FloatTest>>testSignificandAsInteger (in category 'characterization') ----- + testSignificandAsInteger + | mantissaBits denormalPowersOfTwo denormals exceptionals normalPowersOfTwo normals | + "There are 52 bits used for representing the mantissa (plus an eventual leading 1, see below)" + mantissaBits := Float precision - 1. + + normals := {Float pi. Float pi * 100.0. Float pi/ -100.0. Float fmax. Float fminNormalized}. + denormals := {0.0. Float negativeZero. Float fminNormalized predecessor. Float fmin negated}. + exceptionals := {Float nan. Float infinity. Float infinity negated.}. + normalPowersOfTwo := (-10 to: 10) collect: [:i | 1.0 timesTwoPower: i]. + denormalPowersOfTwo := (Float emin - mantissaBits to: Float emin - 1) collect: [:i | 1.0 timesTwoPower: i]. + + normals do: [:aNormalFloat | + "Assume the mantissa is written in least 52 bits of hex format, with an implied 1 on position 53" + self + assert: (((Integer readFrom: aNormalFloat hex base: 16) bitAnd: 1<<mantissaBits-1) bitOr: 1<<mantissaBits) + equals: aNormalFloat significandAsInteger]. + + denormals , exceptionals do: [:aDenormalOrExceptionalFloat | + "For every other Float, zero, denormal or exceptional, no implied leading one" + self + assert: ((Integer readFrom: aDenormalOrExceptionalFloat hex base: 16) bitAnd: 1<<mantissaBits-1) + equals: aDenormalOrExceptionalFloat significandAsInteger]. + + normalPowersOfTwo do: [:aNormalPowerOfTwoFloat | + "The significand of a power of two is a power of two, with high bit of expected precision" + self assert: aNormalPowerOfTwoFloat significandAsInteger isPowerOfTwo. + self assert: aNormalPowerOfTwoFloat significandAsInteger highBit equals: Float precision. + self assert: aNormalPowerOfTwoFloat successor significandAsInteger equals: aNormalPowerOfTwoFloat significandAsInteger + 1. + "The last one is not true for fminNormalized" + aNormalPowerOfTwoFloat = Float fminNormalized or: [ + self assert: aNormalPowerOfTwoFloat predecessor significandAsInteger equals: aNormalPowerOfTwoFloat significandAsInteger * 2 - 1]]. + + denormalPowersOfTwo do: [:aDenormalPowerOfTwoFloat | + "The significand of a denormal power of two is a power of two, just with less bits" + self assert: aDenormalPowerOfTwoFloat significandAsInteger isPowerOfTwo. + self assert: aDenormalPowerOfTwoFloat significandAsInteger highBit equals: Float precision + aDenormalPowerOfTwoFloat exponent - Float emin. + aDenormalPowerOfTwoFloat successor = Float fminNormalized or: [ + self assert: aDenormalPowerOfTwoFloat successor significandAsInteger equals: aDenormalPowerOfTwoFloat significandAsInteger + 1]. + self assert: aDenormalPowerOfTwoFloat predecessor significandAsInteger equals: aDenormalPowerOfTwoFloat significandAsInteger - 1.]. + + "Well known value for a few extremal cases" + self assert: Float fmax significandAsInteger equals: 1 << Float precision - 1. + self assert: Float fmin significandAsInteger equals: 1. + self assert: 0.0 significandAsInteger equals: 0. + self assert: Float infinity significandAsInteger equals: 0. + self assert: Float nan significandAsInteger > 0! Item was removed: - ----- Method: FloatTest>>testZeroSignificandAsInteger (in category 'zero behavior') ----- - testZeroSignificandAsInteger - "This is about http://bugs.squeak.org/view.php?id=6990" - - self assert: 0.0 significandAsInteger = 0! |
Free forum by Nabble | Edit this page |