approx.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
class TEST_MATH{NTP < $REAL{NTP} }
class TEST_MATH{NTP < $REAL{NTP} } is
-- This class carries out tests on the floating point approximate
-- number class NTP. Note that it is not portable for simplicity in building
-- a local library.
-- Version 1.0 Oct 97. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 3 Oct 97 kh Original
include TEST ;
basic(
name : STR
) is
-- This routine is the one which contains all of the tests in sections
-- as indicated by comments throughout the test.
class_name(name) ; -- always done first!
-- First obtain and test approximate constants.
zero : NTP := NTP::create(0.0) ;
test("zero constant",zero.str(3),(0.0).str(3)) ;
one : NTP := NTP::create(1.0) ;
test("one constant",one.str(3),(1.0).str(3)) ;
-- test of creating -0.0 which is expected to fail!
unchecked_test("NTP::create(-0.0)",(NTP::create(-0.0)).str(3),(-0.0).str(3)) ;
-- now produce minus zero by 'calculation' -- which should work!
nzero : NTP := -zero ;
test("negative zero",nzero.str(3),(-0.0).str(3)) ;
-- now produce/test plus/minus infinity!
inf : NTP := NTP::create(1.0/0.0) ;
test("1.0/0.0",inf.str,"Inf") ;
ninf : NTP := NTP::create(-1.0/0.0) ;
test("-1.0/0.0",ninf.str,"-Inf") ;
-- finally the Not-a-Number variants!
test("0.0/0.0 with variables",(zero/zero).str,"NaN") ;
nan : FLT := FLT::zero/FLT::zero ;
test("0.0/0.0",nan.str,"NaN") ;
nan2 : FLTD := FLTD::zero/FLTD::zero ;
test("0.0/0.0",nan2.str,"NaN") ;
-- the following test may produce a core dump!!!!!!!
test("0.0/0.0 with constants. May dump core",(0.0/0.0).str,"NaN") ;
-- now for some equality testing!
test("1 = 1",(one = one).str,true.str) ;
test("-0 = 0",(zero = nzero).str,true.str) ;
test("Inf = Inf",(inf = inf).str,true.str) ;
test("-Inf = -Inf",(ninf = ninf).str,true.str) ;
test("Inf = -Inf",(inf = ninf).str,false.str) ;
-- NOTE this test should fail!!!
test("NaN = NaN",(nan = nan).str,false.str) ;
-- some inequality tests
test("1 /= 1",(one /= one).str,false.str) ;
test("-0 /= 0",(zero /= nzero).str,false.str) ;
test("Inf /= Inf",(inf /= inf).str,false.str) ;
test("-Inf /= -Inf",(ninf /= ninf).str,false.str) ;
test("Inf /= -Inf",(inf /= ninf).str,true.str) ;
test("NaN /= NaN",(nan /= nan).str,true.str) ;
-- IEEE 754 number classification tests -- MAY dump core!
test("0.0.is_nan. May dump core",zero.is_nan.str,false.str) ;
test("-0.0.is_nan. May dump core",nzero.is_nan.str,false.str) ;
test("NaN.is_nan. May dump core",nan.is_nan.str,true.str) ;
test("Inf.is_nan. May dump core",inf.is_nan.str,false.str) ;
test("-Inf.is_nan. May dump core",ninf.is_nan.str,false.str) ;
-- test of simple mathematical operations.
test("sqrt(0.0)",zero.sqrt.str(3),(0.0).str(3)) ;
test("sqrt(-0.0)",(-zero).sqrt.str(3),(-0.0).str(3)) ;
-- test("sqrt(-1.0)",(-one).sqrt.str,"NaN") ; --Fails pre-condition!
-- The following tests are optional dependent upon the optional
-- inclusions in the class NTP!!
-- unchecked_test("log(0.0)",zero.log.str,"-Inf") ;
-- unchecked_test("log(-0.0)",(-zero).log.str,"NaN") ;
-- unchecked_test("log(-1.0)",(-one).log.str,"NaN") ;
finish
end ;
end ; -- TEST_MATH{NTP}
class TEST_FLT
class TEST_FLT is
-- This class is provided tp test the library implementation of single
-- precision approximate numbers.
-- Version 1.0 Oct 97. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 3 Oct 97 kh Original
main is
TEST_MATH{FLT}::basic("FLT")
end ;
end ; -- TEST_FLT
class TEST_FLTD
class TEST_FLTD is
-- This class is provided to test the library implementation of double
-- precision approximate numbers.
-- Version 1.0 Oct 97. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 3 Oct 97 kh Original
main is
TEST_MATH{FLTD}::basic("FLTD")
end ;
end; -- MAIN