xref: /freebsd/contrib/netbsd-tests/lib/libc/gen/t_isnan.c (revision 8f0ea33f2bbf3a6aa80235f0a02fa5f2780c2b17)
1*068ebf32SEnji Cooper /* $NetBSD: t_isnan.c,v 1.5 2014/11/04 00:20:19 justin Exp $ */
257718be8SEnji Cooper 
357718be8SEnji Cooper /*
457718be8SEnji Cooper  * This file is in the Public Domain.
557718be8SEnji Cooper  *
657718be8SEnji Cooper  * The nan test is blatently copied by Simon Burge from the infinity
757718be8SEnji Cooper  * test by Ben Harris.
857718be8SEnji Cooper  */
957718be8SEnji Cooper 
1057718be8SEnji Cooper #include <sys/param.h>
1157718be8SEnji Cooper 
1257718be8SEnji Cooper #include <atf-c.h>
1357718be8SEnji Cooper 
1457718be8SEnji Cooper #include <math.h>
1557718be8SEnji Cooper #include <string.h>
1657718be8SEnji Cooper 
1757718be8SEnji Cooper ATF_TC(isnan_basic);
ATF_TC_HEAD(isnan_basic,tc)1857718be8SEnji Cooper ATF_TC_HEAD(isnan_basic, tc)
1957718be8SEnji Cooper {
2057718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Verify that isnan(3) works");
2157718be8SEnji Cooper }
2257718be8SEnji Cooper 
ATF_TC_BODY(isnan_basic,tc)2357718be8SEnji Cooper ATF_TC_BODY(isnan_basic, tc)
2457718be8SEnji Cooper {
2557718be8SEnji Cooper #if defined(__m68k__)
2657718be8SEnji Cooper 	atf_tc_skip("Test not applicable on " MACHINE_ARCH);
2757718be8SEnji Cooper #endif
2857718be8SEnji Cooper 
2957718be8SEnji Cooper #ifdef NAN
3057718be8SEnji Cooper 	/* NAN is meant to be a (float)NaN. */
3157718be8SEnji Cooper 	ATF_CHECK(isnan(NAN) != 0);
3257718be8SEnji Cooper 	ATF_CHECK(isnan((double)NAN) != 0);
3357718be8SEnji Cooper #else
3457718be8SEnji Cooper 	atf_tc_skip("Test not applicable");
3557718be8SEnji Cooper #endif
3657718be8SEnji Cooper }
3757718be8SEnji Cooper 
3857718be8SEnji Cooper ATF_TC(isinf_basic);
ATF_TC_HEAD(isinf_basic,tc)3957718be8SEnji Cooper ATF_TC_HEAD(isinf_basic, tc)
4057718be8SEnji Cooper {
4157718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Verify that isinf(3) works");
4257718be8SEnji Cooper }
4357718be8SEnji Cooper 
ATF_TC_BODY(isinf_basic,tc)4457718be8SEnji Cooper ATF_TC_BODY(isinf_basic, tc)
4557718be8SEnji Cooper {
4657718be8SEnji Cooper #if defined(__m68k__)
4757718be8SEnji Cooper 	atf_tc_skip("Test not applicable on " MACHINE_ARCH);
4857718be8SEnji Cooper #endif
4957718be8SEnji Cooper 
5057718be8SEnji Cooper 	/* HUGE_VAL is meant to be an infinity. */
5157718be8SEnji Cooper 	ATF_CHECK(isinf(HUGE_VAL) != 0);
5257718be8SEnji Cooper 
5357718be8SEnji Cooper 	/* HUGE_VALF is the float analog of HUGE_VAL. */
5457718be8SEnji Cooper 	ATF_CHECK(isinf(HUGE_VALF) != 0);
5557718be8SEnji Cooper 
5657718be8SEnji Cooper 	/* HUGE_VALL is the long double analog of HUGE_VAL. */
5757718be8SEnji Cooper 	ATF_CHECK(isinf(HUGE_VALL) != 0);
5857718be8SEnji Cooper }
5957718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)6057718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
6157718be8SEnji Cooper {
6257718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, isnan_basic);
6357718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, isinf_basic);
6457718be8SEnji Cooper 
6557718be8SEnji Cooper 	return atf_no_error();
6657718be8SEnji Cooper }
67