xref: /freebsd/contrib/netbsd-tests/lib/libm/t_fmod.c (revision 1ec3feb64826d2a43d41e74684690985bf20e71c)
1*1ec3feb6SAlex Richardson /* $NetBSD: t_fmod.c,v 1.4 2020/08/25 13:39:16 gson Exp $ */
257718be8SEnji Cooper 
357718be8SEnji Cooper /*-
457718be8SEnji Cooper  * Copyright (c) 2013 The NetBSD Foundation, Inc.
557718be8SEnji Cooper  * All rights reserved.
657718be8SEnji Cooper  *
757718be8SEnji Cooper  * This code is derived from software contributed to The NetBSD Foundation
857718be8SEnji Cooper  * by Joerg Sonnenberger.
957718be8SEnji Cooper  *
1057718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
1157718be8SEnji Cooper  * modification, are permitted provided that the following conditions
1257718be8SEnji Cooper  * are met:
1357718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1457718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1557718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1657718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1757718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1857718be8SEnji Cooper  *
1957718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2057718be8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2157718be8SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2257718be8SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2357718be8SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2457718be8SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2557718be8SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2657718be8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2757718be8SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2857718be8SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2957718be8SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
3057718be8SEnji Cooper  */
3157718be8SEnji Cooper 
3257718be8SEnji Cooper #include <atf-c.h>
3357718be8SEnji Cooper #include <float.h>
3457718be8SEnji Cooper #include <math.h>
3557718be8SEnji Cooper 
36640235e2SEnji Cooper #include "isqemu.h"
37640235e2SEnji Cooper 
3857718be8SEnji Cooper ATF_TC(fmod);
ATF_TC_HEAD(fmod,tc)3957718be8SEnji Cooper ATF_TC_HEAD(fmod, tc)
4057718be8SEnji Cooper {
4157718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr","Check fmod family");
4257718be8SEnji Cooper }
4357718be8SEnji Cooper 
ATF_TC_BODY(fmod,tc)4457718be8SEnji Cooper ATF_TC_BODY(fmod, tc)
4557718be8SEnji Cooper {
4610f26e7dSEnji Cooper #ifdef __NetBSD__
47640235e2SEnji Cooper 	if (isQEMU())
48640235e2SEnji Cooper 		atf_tc_expect_fail("PR misc/44767");
4910f26e7dSEnji Cooper #endif
50640235e2SEnji Cooper 
5157718be8SEnji Cooper 	ATF_CHECK(fmodf(2.0, 1.0) == 0);
5257718be8SEnji Cooper 	ATF_CHECK(fmod(2.0, 1.0) == 0);
5357718be8SEnji Cooper 	ATF_CHECK(fmodl(2.0, 1.0) == 0);
5457718be8SEnji Cooper 
5557718be8SEnji Cooper 	ATF_CHECK(fmodf(2.0, 0.5) == 0);
5657718be8SEnji Cooper 	ATF_CHECK(fmod(2.0, 0.5) == 0);
5757718be8SEnji Cooper 	ATF_CHECK(fmodl(2.0, 0.5) == 0);
5857718be8SEnji Cooper 
5957718be8SEnji Cooper 	ATF_CHECK(fabsf(fmodf(1.0, 0.1) - 0.1f) <= 55 * FLT_EPSILON);
6057718be8SEnji Cooper 	ATF_CHECK(fabs(fmod(1.0, 0.1) - 0.1) <= 55 * DBL_EPSILON);
6157718be8SEnji Cooper 	ATF_CHECK(fabsl(fmodl(1.0, 0.1L) - 0.1L) <= 55 * LDBL_EPSILON);
6257718be8SEnji Cooper }
6357718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)6457718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
6557718be8SEnji Cooper {
6657718be8SEnji Cooper 
6757718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, fmod);
6857718be8SEnji Cooper 
6957718be8SEnji Cooper 	return atf_no_error();
7057718be8SEnji Cooper }
71