'From Squeak3.10beta of 22 July 2007 [latest update: #7159] on 18 June 2008 at 2:43:15 am'!
"Change Set: Fraction-sqrtTruncated-Test-M7099
Date: 18 June 2008
Author: nice
(x sqrtTrunctaed) is better than (x sqrt truncated) if these conditions are met:
- computation is fast
- result is not subject to rounding errors (Float inexact arithmetic)
These tests might fail if sqrtTruncated and sqrtRounded are implemented naively using self asFloat sqrt"!
!FractionTest methodsFor: 'tests - arithmetic' stamp: 'nice 6/18/2008 02:40'!
testSqrtRounded
"Test some exact squares"
| x |
x := 1 bitShift: 53.
-511 to: 511 do: [:i |
| y |
y := (x + (i/1024)) squared.
self assert: y sqrtRounded = x].
512 to: 1024+511 do: [:i |
| y |
y := (x + (i/1024)) squared.
self assert: y sqrtRounded = (x+1)].! !
!FractionTest methodsFor: 'tests - arithmetic' stamp: 'nice 6/18/2008 02:40'!
testSqrtTruncated
"Test some exact squares"
| x |
x := 1 bitShift: 53.
0 to: 1023 do: [:i |
| y |
y := (x + (i/1024)) squared.
self assert: y sqrtTruncated = x].! !
!FractionTest reorganize!
('tests - printing' testFractionPrinting)
('tests - sinuses' testDegreeCos testDegreeSin)
('tests - arithmetic' testSqrtRounded testSqrtTruncated)
!