Module Name: src Committed By: jruoho Date: Fri Apr 8 06:49:21 UTC 2011
Modified Files: src/distrib/sets/lists/tests: mi src/tests/lib/libm: Makefile Added Files: src/tests/lib/libm: t_round.c Removed Files: src/tests/lib/libm: t_libm.c Log Message: Move the round(3) checks from 't_libm' to their own 't_round' for consistency. Add -Wfloat-equal and fix comparisons. To generate a diff of this commit: cvs rdiff -u -r1.299 -r1.300 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libm/Makefile cvs rdiff -u -r1.1 -r0 src/tests/lib/libm/t_libm.c cvs rdiff -u -r0 -r1.1 src/tests/lib/libm/t_round.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.299 src/distrib/sets/lists/tests/mi:1.300 --- src/distrib/sets/lists/tests/mi:1.299 Thu Apr 7 17:38:02 2011 +++ src/distrib/sets/lists/tests/mi Fri Apr 8 06:49:20 2011 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.299 2011/04/07 17:38:02 jruoho Exp $ +# $NetBSD: mi,v 1.300 2011/04/08 06:49:20 jruoho Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -459,7 +459,8 @@ ./usr/libdata/debug/usr/tests/lib/libm tests-lib-debug ./usr/libdata/debug/usr/tests/lib/libm/t_ceil.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libm/t_floor.debug tests-lib-debug debug,atf -./usr/libdata/debug/usr/tests/lib/libm/t_libm.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libm/t_libm.debug tests-obsolete obsolete +./usr/libdata/debug/usr/tests/lib/libm/t_round.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libm/t_tanh.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libobjc tests-lib-debug ./usr/libdata/debug/usr/tests/lib/libobjc/t_threads.debug tests-lib-debug debug,atf @@ -1942,7 +1943,8 @@ ./usr/tests/lib/libm/Atffile tests-lib-tests atf ./usr/tests/lib/libm/t_ceil tests-lib-tests atf ./usr/tests/lib/libm/t_floor tests-lib-tests atf -./usr/tests/lib/libm/t_libm tests-lib-tests atf +./usr/tests/lib/libm/t_libm tests-obsolete obsolete +./usr/tests/lib/libm/t_round tests-lib-tests atf ./usr/tests/lib/libm/t_tanh tests-lib-tests atf ./usr/tests/lib/libobjc tests-lib-tests atf ./usr/tests/lib/libobjc/Atffile tests-lib-tests atf Index: src/tests/lib/libm/Makefile diff -u src/tests/lib/libm/Makefile:1.3 src/tests/lib/libm/Makefile:1.4 --- src/tests/lib/libm/Makefile:1.3 Wed Apr 6 09:35:49 2011 +++ src/tests/lib/libm/Makefile Fri Apr 8 06:49:21 2011 @@ -1,11 +1,12 @@ -# $NetBSD: Makefile,v 1.3 2011/04/06 09:35:49 jruoho Exp $ +# $NetBSD: Makefile,v 1.4 2011/04/08 06:49:21 jruoho Exp $ .include <bsd.own.mk> TESTSDIR= ${TESTSBASE}/lib/libm -TESTS_C+= t_ceil t_floor t_libm t_tanh +TESTS_C+= t_ceil t_floor t_round t_tanh LDADD+=-lm +COPTS+= -Wfloat-equal .include <bsd.test.mk> Added files: Index: src/tests/lib/libm/t_round.c diff -u /dev/null src/tests/lib/libm/t_round.c:1.1 --- /dev/null Fri Apr 8 06:49:21 2011 +++ src/tests/lib/libm/t_round.c Fri Apr 8 06:49:21 2011 @@ -0,0 +1,46 @@ +/* $NetBSD: t_round.c,v 1.1 2011/04/08 06:49:21 jruoho Exp $ */ + +#include <atf-c.h> +#include <math.h> + +/* + * This tests for a bug in the initial implementation where + * precision was lost in an internal substraction, leading to + * rounding into the wrong direction. + */ + +/* 0.5 - EPSILON */ +#define VAL 0x0.7ffffffffffffcp0 +#define VALF 0x0.7fffff8p0 + +ATF_TC(round_dir); +ATF_TC_HEAD(round_dir, tc) +{ + atf_tc_set_md_var(tc, "descr","Check for rounding in wrong direction"); +} + +ATF_TC_BODY(round_dir, tc) +{ + double a = VAL, b, c; + float af = VALF, bf, cf; + + b = round(a); + bf = roundf(af); + + ATF_REQUIRE(fabs(b) < 1.0e-40); + ATF_REQUIRE(fabsf(bf) < 1.0e-40); + + c = round(-a); + cf = roundf(-af); + + ATF_REQUIRE(fabs(c) < 1.0e-40); + ATF_REQUIRE(fabsf(cf) < 1.0e-40); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, round_dir); + + return atf_no_error(); +}