# [Pkg] The Trunk: KernelTests-nice.364.mcz

commits at source.squeak.org commits at source.squeak.org
Mon May 13 15:47:49 UTC 2019

```Nicolas Cellier uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-nice.364.mcz

==================== Summary ====================

Name: KernelTests-nice.364
Author: nice
Time: 13 May 2019, 5:47:01.649569 pm
UUID: 48139b72-ab12-d140-af26-7bce15bae277
Ancestors: KernelTests-nice.363

Integer sqrt is now correctly rounded - this is a new feature.

That's the case by construction for SmallInteger which rely on Float sqrt
but less obvious for LargePositiveInteger, so let's test it

=============== Diff against KernelTests-nice.363 ===============

+ ----- Method: LargeNegativeIntegerTest>>testSqrt (in category 'tests - mathematical functions') -----
+ testSqrt
+ 	self should: [(SmallInteger minVal - 1) sqrt] raise: DomainError!

+ ----- Method: LargePositiveIntegerTest>>assertSqrtCorrectlyRoundedForExponent: (in category 'asserting') -----
+ assertSqrtCorrectlyRoundedForExponent: exp
+ 	"Requires exp > Float precision, so that f ulp/2 is integer"
+ 	{1.5. 1.25 squared. 2.0 predecessor} do: [:sf |
+ 		| f xe xp xm |
+
+ 		f := sf timesTwoPower: exp.
+
+ 		"make two integers around the pivot"
+ 		xe := f asInteger + (f ulp asInteger / 2).
+ 		xm := xe squared - 1.
+ 		xp := xe squared + 1.
+ 		self assert: xe squared sqrt equals: xe.
+ 		self assert: xe squared sqrt isInteger.
+
+ 		"check rounding when result is near f squared"
+ 		self assert: xm sqrt equals: f.
+ 		self assert: xm sqrt isFloat.
+ 		self assert: xp sqrt equals: f successor.
+ 		self assert: xp sqrt isFloat.
+
+ 		"same in the other direction"
+ 		xe := f asInteger - (f ulp asInteger / 2).
+ 		xm := xe squared - 1.
+ 		xp := xe squared + 1.
+ 		self assert: xe squared sqrt equals: xe.
+ 		self assert: xe squared sqrt isInteger.
+
+ 		"check rounding when result is near f squared"
+ 		self assert: xm sqrt equals: f predecessor.
+ 		self assert: xm sqrt isFloat.
+ 		self assert: xp sqrt equals: f.
+ 		self assert: xp sqrt isFloat].!

+ ----- Method: LargePositiveIntegerTest>>testSqrt (in category 'tests - mathematical functions') -----
+ testSqrt
+ 	self assert: (SmallInteger maxVal + 1) sqrt equals: (SmallInteger maxVal + 1) asFloat sqrt.!