[squeakdev] The Inbox: KernelTestsnice.422.mcz
commits at source.squeak.org
commits at source.squeak.org
Tue Apr 26 11:03:34 UTC 2022
Nicolas Cellier uploaded a new version of KernelTests to project The Inbox:
http://source.squeak.org/inbox/KernelTestsnice.422.mcz
==================== Summary ====================
Name: KernelTestsnice.422
Author: nice
Time: 26 April 2022, 1:03:31.73252 pm
UUID: e963a1d7702a904d8b408dbf96032f0d
Ancestors: KernelTestsnice.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 KernelTestsnice.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.!
More information about the Squeakdev
mailing list
