t_fmod.c revision 282836
118334Speter/* $NetBSD: t_fmod.c,v 1.2 2014/02/27 17:26:02 joerg Exp $ */
290075Sobrien
3169689Skan/*-
418334Speter * Copyright (c) 2013 The NetBSD Foundation, Inc.
518334Speter * All rights reserved.
6132718Skan *
718334Speter * This code is derived from software contributed to The NetBSD Foundation
8132718Skan * by Joerg Sonnenberger.
918334Speter *
1018334Speter * Redistribution and use in source and binary forms, with or without
1118334Speter * modification, are permitted provided that the following conditions
1218334Speter * are met:
13132718Skan * 1. Redistributions of source code must retain the above copyright
1418334Speter *    notice, this list of conditions and the following disclaimer.
1518334Speter * 2. Redistributions in binary form must reproduce the above copyright
1618334Speter *    notice, this list of conditions and the following disclaimer in the
1718334Speter *    documentation and/or other materials provided with the distribution.
1818334Speter *
19132718Skan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20169689Skan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21169689Skan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2218334Speter * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2318334Speter * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2418334Speter * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2518334Speter * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2650397Sobrien * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2750397Sobrien * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28132718Skan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29132718Skan * POSSIBILITY OF SUCH DAMAGE.
3018334Speter */
3118334Speter
3290075Sobrien#include <atf-c.h>
3390075Sobrien#include <float.h>
3418334Speter#include <math.h>
3518334Speter
3650397SobrienATF_TC(fmod);
3750397SobrienATF_TC_HEAD(fmod, tc)
3890075Sobrien{
3990075Sobrien	atf_tc_set_md_var(tc, "descr","Check fmod family");
4018334Speter}
41132718Skan
42132718SkanATF_TC_BODY(fmod, tc)
4318334Speter{
44132718Skan	ATF_CHECK(fmodf(2.0, 1.0) == 0);
45132718Skan	ATF_CHECK(fmod(2.0, 1.0) == 0);
46132718Skan#if !defined(__FreeBSD__) || LDBL_PREC != 53
47132718Skan	ATF_CHECK(fmodl(2.0, 1.0) == 0);
48132718Skan#endif
49132718Skan
5018334Speter	ATF_CHECK(fmodf(2.0, 0.5) == 0);
51132718Skan	ATF_CHECK(fmod(2.0, 0.5) == 0);
52132718Skan#if !defined(__FreeBSD__) || LDBL_PREC != 53
5350397Sobrien	ATF_CHECK(fmodl(2.0, 0.5) == 0);
5490075Sobrien#endif
5590075Sobrien
5618334Speter	ATF_CHECK(fabsf(fmodf(1.0, 0.1) - 0.1f) <= 55 * FLT_EPSILON);
5790075Sobrien	ATF_CHECK(fabs(fmod(1.0, 0.1) - 0.1) <= 55 * DBL_EPSILON);
5818334Speter#if !defined(__FreeBSD__) || LDBL_PREC != 53
5990075Sobrien	ATF_CHECK(fabsl(fmodl(1.0, 0.1L) - 0.1L) <= 55 * LDBL_EPSILON);
6090075Sobrien#endif
6190075Sobrien}
6290075Sobrien
6390075SobrienATF_TP_ADD_TCS(tp)
6490075Sobrien{
6590075Sobrien
6690075Sobrien	ATF_TP_ADD_TC(tp, fmod);
6790075Sobrien
6890075Sobrien	return atf_no_error();
6990075Sobrien}
7090075Sobrien