Nicolas Cellier uploaded a new version of KernelTests to project The Trunk: http://source.squeak.org/trunk/KernelTests-nice.422.mcz
==================== Summary ====================
Name: KernelTests-nice.422 Author: nice Time: 26 April 2022, 1:03:31.73252 pm UUID: e963a1d7-702a-904d-8b40-8dbf96032f0d Ancestors: KernelTests-nice.421
Complex tests associated with that suggestion: complex arithmetic should detect case of overflow in intermediate computations and fallback to securedely scaled operations if it's the case.
=============== Diff against KernelTests-nice.421 ===============
Item was changed: ----- Method: ComplexTest>>testDivision1 (in category 'tests') ----- testDivision1 "self run: #testDivision1" "self debug: #testDivision1" | c1 c2 quotient | c1 := 2.0e252 + 3.0e70 i. c2 := c1. quotient := c1 / c2. - self deny: (quotient - 1) isZero. + "This used to fail when / was not protected against floating point overflow in intermediate computations + but it should now work correctly if divideSecureBy: is correctly used as fallback case" + self assert: (quotient - 1) isZero - "This test fails due to the wonders of floating point arithmetic. - Please have a look at Complex>>divideSecureBy: and #divideFastAndSecureBy: - how this can be avoided." !
Item was added: + ----- Method: ComplexTest>>testMultiplyDoesNotOverflow (in category 'tests') ----- + testMultiplyDoesNotOverflow + + | c1 c2 product smallProduct scale | + c1 := (1 + 1 i) sqrt * Float fmax sqrt. + product := c1 squared. + self assert: product real isFinite. + self assert: product imaginary isFinite. + self assert: (product real - Float fmax) / Float fmax ulp < 3. + self assert: (product imaginary - Float fmax) / Float fmax ulp < 3. + + "a more tricky case" + c1 := 1.0 + 0.25 i. + c2 := 1.125+ 0.5 i. + smallProduct := c1 * c2. + "check that we will not overflow in precondition" + self assert: smallProduct real abs <= 1. + self assert: smallProduct imaginary abs <= 1. + "now retry with a large scale" + scale := Float fmax. + product := c1 * scale * c2. + self assert: product real isFinite. + self assert: product imaginary isFinite. + self assert: (scale * smallProduct real - product real) / (scale * smallProduct real) ulp < 3. + self assert: (scale * smallProduct imaginary - product imaginary) / (scale * smallProduct imaginary) ulp < 3.!
Item was added: + ----- Method: ComplexTest>>testReciprocalDoesNotOverflow (in category 'tests') ----- + testReciprocalDoesNotOverflow + "Note: intermediate overflow might cause the answer to be zero in careless implementation" + + | c scale cScaled cScaledInv expected | + c := (1 + 1i). + scale := Float fmax. + cScaled := c * scale. + cScaledInv := cScaled reciprocal. + expected := c reciprocal real / scale + (c reciprocal imaginary / scale) i. + self assert: (expected real- cScaledInv real) abs / expected real ulp < 3. + self assert: (expected imaginary - cScaledInv imaginary) abs / expected imaginary ulp < 3.!
packages@lists.squeakfoundation.org