Nicolas Cellier uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-nice.219.mcz ==================== Summary ==================== Name: KernelTests-nice.219 Author: nice Time: 16 May 2012, 9:24:45.781 pm UUID: 45b90705-6f5f-4f0c-add8-6783781f3822 Ancestors: KernelTests-nice.218 Add a test to demonstrate that despite being internally represented in base 2, a Float cannot compute floorLog: 2 exactly if it only rely on inexact log: implementation. Indeed, an error on math functions values up to 3 ulp is compliant with IEEE 754 floating point standard. =============== Diff against KernelTests-nice.218 =============== Item was changed: + ----- Method: FloatTest>>testArCosh (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testArCosh (in category 'test - mathematical functions') ----- testArCosh self assert: 1.0 arCosh = 0.0. self deny: Float infinity arCosh isFinite. self assert: (2.5 arCosh cosh closeTo: 2.5).! Item was changed: + ----- Method: FloatTest>>testArSinh (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testArSinh (in category 'test - mathematical functions') ----- testArSinh self assert: 0.0 arSinh = 0.0. self assert: Float negativeZero arSinh = 0.0. self assert: Float negativeZero arSinh sign = -1. self deny: Float infinity arSinh isFinite. self assert: (0.5 arSinh negated closeTo: 0.5 negated arSinh). self assert: (0.5 arSinh sinh closeTo: 0.5). self assert: (-2.5 arSinh sinh closeTo: -2.5).! Item was changed: + ----- Method: FloatTest>>testArTanh (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testArTanh (in category 'test - mathematical functions') ----- testArTanh self assert: 0.0 arTanh = 0.0. self assert: Float negativeZero arTanh = 0.0. self assert: Float negativeZero arTanh sign = -1. self deny: 1 arTanh isFinite. self assert: (0.5 arTanh negated closeTo: 0.5 negated arTanh). self assert: (0.5 arTanh tanh closeTo: 0.5). self assert: (-0.5 arTanh tanh closeTo: -0.5).! Item was changed: + ----- Method: FloatTest>>testCosh (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testCosh (in category 'test - mathematical functions') ----- testCosh self assert: (0.0 cosh closeTo: 1). self deny: Float infinity cosh isFinite. self assert: (2.0 cosh squared - 2.0 sinh squared closeTo: 1). self assert: (2.0 cosh closeTo: 2.0 negated cosh).! Item was changed: + ----- Method: FloatTest>>testDegreeCos (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testDegreeCos (in category 'test - mathematical functions') ----- testDegreeCos self shouldnt: [ 45.0 degreeCos] raise: Error. "Following tests use approximate equality, because cosine are generally evaluated using inexact Floating point arithmetic" self assert: (45.0 degreeCos squared - 0.5) abs <= Float epsilon. self assert: (60.0 degreeCos - 0.5) abs <= Float epsilon. self assert: (120.0 degreeCos + 0.5) abs <= Float epsilon. -360.0 to: 360.0 do: [:i | self assert: (i degreeCos closeTo: i degreesToRadians cos)]. "Following tests use strict equality which is a requested property of degreeCos" -10.0 to: 10.0 do: [:k | self assert: (k*360 + 90) degreeCos = 0. self assert: (k*360 - 90) degreeCos = 0. self assert: (k*360 + 180) degreeCos + 1 = 0. self assert: (k*360) degreeCos - 1 = 0.].! Item was changed: + ----- Method: FloatTest>>testDegreeCosForExceptionalValues (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testDegreeCosForExceptionalValues (in category 'test - mathematical functions') ----- testDegreeCosForExceptionalValues self assert: Float nan degreeCos isNaN. self assert: Float infinity degreeCos isNaN. self assert: Float infinity negated degreeCos isNaN.! Item was changed: + ----- Method: FloatTest>>testDegreeSin (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testDegreeSin (in category 'test - mathematical functions') ----- testDegreeSin self shouldnt: [ 45.0 degreeSin] raise: Error. "Following tests use approximate equality, because sine are generally evaluated using inexact Floating point arithmetic" self assert: (45.0 degreeSin squared - 0.5) abs <= Float epsilon. self assert: (30.0 degreeSin - 0.5) abs <= Float epsilon. self assert: (-30.0 degreeSin + 0.5) abs <= Float epsilon. -360.0 to: 360.0 do: [:i | self assert: (i degreeSin closeTo: i degreesToRadians sin)]. "Following tests use strict equality which is a requested property of degreeSin" -10.0 to: 10.0 do: [:k | self assert: (k*360 + 90) degreeSin - 1 = 0. self assert: (k*360 - 90) degreeSin + 1= 0. self assert: (k*360 + 180) degreeSin = 0. self assert: (k*360) degreeSin = 0.].! Item was changed: + ----- Method: FloatTest>>testDegreeSinForExceptionalValues (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testDegreeSinForExceptionalValues (in category 'test - mathematical functions') ----- testDegreeSinForExceptionalValues self assert: Float nan degreeSin isNaN. self assert: Float infinity degreeSin isNaN. self assert: Float infinity negated degreeSin isNaN.! Item was added: + ----- Method: FloatTest>>testFloorLog2 (in category 'tests - mathematical functions') ----- + testFloorLog2 + "Float internal representation of Float being in base 2, we expect (aFloat floorLog: 2) to be exact." + + | aBitLess aBitMore | + aBitMore := 1 + Float epsilon. + aBitLess := 1 - Float epsilon. + Float emin + 1 to: Float emax - 1 do: [:exp | + | exactPowerOfTwo | + exactPowerOfTwo := 1.0 timesTwoPower: exp. + self assert: (exactPowerOfTwo floorLog: 2) equals: exp. + self assert: (exactPowerOfTwo * aBitMore floorLog: 2) equals: exp. + self assert: (exactPowerOfTwo * aBitLess floorLog: 2) equals: exp - 1].! Item was changed: + ----- Method: FloatTest>>testSinh (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testSinh (in category 'test - mathematical functions') ----- testSinh self assert: 0.0 sinh = 0.0. self assert: Float negativeZero sinh = 0.0. self assert: Float negativeZero sinh sign = -1. self deny: Float infinity sinh isFinite. self assert: (2.0 cosh squared - 2.0 sinh squared closeTo: 1). self assert: (2.0 sinh negated closeTo: 2.0 negated sinh).! Item was changed: + ----- Method: FloatTest>>testTanh (in category 'tests - mathematical functions') ----- - ----- Method: FloatTest>>testTanh (in category 'test - mathematical functions') ----- testTanh self assert: 0.0 tanh = 0.0. self assert: Float negativeZero tanh = 0.0. self assert: Float negativeZero tanh sign = -1. self assert: (Float infinity tanh closeTo: 1). self assert: (2.0 cosh squared - 2.0 sinh squared closeTo: 1). self assert: (2.0 tanh negated closeTo: 2.0 negated tanh).! |
Free forum by Nabble | Edit this page |