Module Name: src Committed By: martin Date: Tue Aug 29 11:58:26 UTC 2017
Modified Files: src/lib/libm [netbsd-8]: Makefile src/tests/lib/libm [netbsd-8]: t_fe_round.c Log Message: Pull up the following, requested by he in ticket #217: lib/libm/Makefile 1.197-1.201 tests/lib/libm/t_fe_round.c 1.7 Ensure nexttowardf() is included on all IEEE targets. Add rintl() for aarch64 and mips, and nexttoward() for m68k. Add a test which verifies that nextafter() and nexttoward() are present in the implementation. To generate a diff of this commit: cvs rdiff -u -r1.191.2.1 -r1.191.2.2 src/lib/libm/Makefile cvs rdiff -u -r1.2.8.1 -r1.2.8.2 src/tests/lib/libm/t_fe_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/lib/libm/Makefile diff -u src/lib/libm/Makefile:1.191.2.1 src/lib/libm/Makefile:1.191.2.2 --- src/lib/libm/Makefile:1.191.2.1 Tue Aug 29 11:45:18 2017 +++ src/lib/libm/Makefile Tue Aug 29 11:58:26 2017 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.191.2.1 2017/08/29 11:45:18 martin Exp $ +# $NetBSD: Makefile,v 1.191.2.2 2017/08/29 11:58:26 martin Exp $ # # @(#)Makefile 5.1beta 93/09/24 # @@ -60,6 +60,7 @@ ARCH_SRCS+= s_fma.S s_fmaf.S s_fmax.S s_ .if ${MKSOFTFLOAT} == "no" COMMON_SRCS+= fenv.c .endif +COMMON_SRCS+= s_rintl.c COMMON_SRCS+= e_sqrtl.c COMMON_SRCS+= s_fma.c s_fmaf.c s_fmal.c @@ -74,7 +75,7 @@ COPTS+= -mfloat-ieee -mieee-with-inexact .if ${MKSOFTFLOAT} == "no" COMMON_SRCS+= fenv.c .endif -COMMON_SRCS+= s_nexttowardf.c s_rintl.c +COMMON_SRCS+= s_rintl.c .for f in fenv.c lrint.S lrintf.S s_fabsf.S s_fma.S s_fmaf.S COPTS.$f += -mfpu=vfp .endfor @@ -90,7 +91,7 @@ COMMON_SRCS += fenv.c .elif (${LIBC_MACHINE_ARCH} == "hppa") .PATH.c: ${.CURDIR}/arch/hppa -COMMON_SRCS+= fenv.c s_nexttowardf.c s_rintl.c +COMMON_SRCS+= fenv.c s_rintl.c .elif (${LIBC_MACHINE_ARCH} == "sparc") .PATH: ${.CURDIR}/arch/sparc @@ -100,7 +101,7 @@ COMMON_SRCS+= s_fma.c s_fmaf.c s_fmal.c .elif (${LIBC_MACHINE_ARCH} == "sparc64") .PATH: ${.CURDIR}/arch/sparc64 COMMON_SRCS+= fenv.c -COMMON_SRCS+= s_nexttowardf.c s_rintl.c +COMMON_SRCS+= s_rintl.c .ifndef _COMPAT_M32_MK_ COMMON_SRCS+= s_nexttoward.c .endif @@ -114,7 +115,7 @@ COMMON_SRCS+= s_fma.c s_fmaf.c s_fmal.c .endif .PATH: ${.CURDIR}/arch/i387 -COMMON_SRCS+= fenv.c s_nexttoward.c s_nexttowardf.c s_rintl.c +COMMON_SRCS+= fenv.c s_nexttoward.c s_rintl.c COMMON_SRCS+= s_fma.c s_fmaf.c s_fmal.c ARCH_SRCS = e_acos.S e_asin.S e_atan2.S e_exp.S e_expf.S e_fmod.S e_log.S \ @@ -153,7 +154,7 @@ ARCH_SRCS = e_acos.S e_asin.S e_atanh.S e_log10.S e_remainder.S e_scalb.S e_sinh.S e_sqrt.S s_atan.S \ s_ceil.S s_copysign.S s_cos.S s_expm1.S s_finite.S s_floor.S \ s_log1p.S s_logb.S s_rint.S s_scalbn.S s_sin.S s_tan.S s_tanh.S -COMMON_SRCS += fenv.c s_rintl.c +COMMON_SRCS += fenv.c s_nexttoward.c s_rintl.c .endif .endif # end of m68k @@ -193,6 +194,7 @@ COMMON_SRCS += fenv.c .if ${MKSOFTFLOAT} == "no" COMMON_SRCS += fenv.c .endif +COMMON_SRCS+= s_rintl.c .elif (${LIBC_MACHINE_CPU} == "sh3") .PATH: ${.CURDIR}/arch/sh3 @@ -267,7 +269,7 @@ COMMON_SRCS+= b_exp.c b_log.c b_tgamma.c s_lround.c s_lroundf.c s_lroundl.c \ s_log1pf.c s_logb.c s_logbf.c s_logbl.c \ s_matherr.c s_modff.c s_modfl.c s_nearbyint.c s_nextafter.c s_nextafterl.c \ - s_nextafterf.c s_remquo.c s_remquof.c s_rint.c s_rintf.c \ + s_nextafterf.c s_nexttowardf.c s_remquo.c s_remquof.c s_rint.c s_rintf.c \ s_round.c s_roundf.c s_roundl.c s_scalbn.c \ s_scalbnf.c s_scalbnl.c s_signgam.c s_significand.c s_significandf.c s_sin.c \ s_sinf.c s_tan.c s_tanf.c s_tanh.c s_tanhf.c s_tgammaf.c \ Index: src/tests/lib/libm/t_fe_round.c diff -u src/tests/lib/libm/t_fe_round.c:1.2.8.1 src/tests/lib/libm/t_fe_round.c:1.2.8.2 --- src/tests/lib/libm/t_fe_round.c:1.2.8.1 Tue Aug 29 11:45:18 2017 +++ src/tests/lib/libm/t_fe_round.c Tue Aug 29 11:58:26 2017 @@ -122,11 +122,74 @@ ATF_TC_BODY(fe_nearbyint, tc) } } +static const struct { + double input; + double toward; + double expected; +} values2[] = { + { 10.0, 11.0, 10.0 }, + { -5.0, -6.0, -5.0 }, +}; + +ATF_TC(fe_nextafter); +ATF_TC_HEAD(fe_nextafter, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checking IEEE 754 rounding using nextafter()"); +} + +ATF_TC_BODY(fe_nextafter, tc) +{ + double received; + int res; + + for (unsigned int i = 0; i < __arraycount(values2); i++) { + received = nextafter(values2[i].input, values2[i].toward); + if (values2[i].input < values2[i].toward) { + res = (received > values2[i].input); + } else { + res = (received < values2[i].input); + } + ATF_CHECK_MSG( + res && (fabs(received - values2[i].expected) < EPSILON), + "nextafter() rounding wrong, difference too large\n" + "input: %f (index %d): got %f, expected %f, res %d\n", + values2[i].input, i, received, values2[i].expected, res); + } +} + +ATF_TC(fe_nexttoward); +ATF_TC_HEAD(fe_nexttoward, tc) +{ + atf_tc_set_md_var(tc, "descr", "Checking IEEE 754 rounding using nexttoward()"); +} + +ATF_TC_BODY(fe_nexttoward, tc) +{ + double received; + int res; + + for (unsigned int i = 0; i < __arraycount(values2); i++) { + received = nexttoward(values2[i].input, values2[i].toward); + if (values2[i].input < values2[i].toward) { + res = (received > values2[i].input); + } else { + res = (received < values2[i].input); + } + ATF_CHECK_MSG( + res && (fabs(received - values2[i].expected) < EPSILON), + "nexttoward() rounding wrong, difference too large\n" + "input: %f (index %d): got %f, expected %f, res %d\n", + values2[i].input, i, received, values2[i].expected, res); + } +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, fe_round); ATF_TP_ADD_TC(tp, fe_nearbyint); + ATF_TP_ADD_TC(tp, fe_nextafter); + ATF_TP_ADD_TC(tp, fe_nexttoward); return atf_no_error(); } @@ -139,7 +202,6 @@ ATF_TC_HEAD(t_nofe_round, tc) "dummy test case - no fenv.h support"); } - ATF_TC_BODY(t_nofe_round, tc) { atf_tc_skip("no fenv.h support on this architecture"); @@ -158,11 +220,38 @@ ATF_TC_BODY(t_nofe_nearbyint, tc) atf_tc_skip("no fenv.h support on this architecture"); } +ATF_TC(t_nofe_nextafter); + +ATF_TC_HEAD(t_nofe_nextafter, tc) +{ + atf_tc_set_md_var(tc, "descr", + "dummy test case - no fenv.h support"); +} + +ATF_TC_BODY(t_nofe_nextafter, tc) +{ + atf_tc_skip("no fenv.h support on this architecture"); +} + +ATF_TC(t_nofe_nexttoward); + +ATF_TC_HEAD(t_nofe_nexttoward, tc) +{ + atf_tc_set_md_var(tc, "descr", + "dummy test case - no fenv.h support"); +} + +ATF_TC_BODY(t_nofe_nexttoward, tc) +{ + atf_tc_skip("no fenv.h support on this architecture"); +} ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, t_nofe_round); ATF_TP_ADD_TC(tp, t_nofe_nearbyint); + ATF_TP_ADD_TC(tp, t_nofe_nextafter); + ATF_TP_ADD_TC(tp, t_nofe_nexttoward); return atf_no_error(); }