1*0a6a1f1dSLionel Sambuc /* $NetBSD: t_atan.c,v 1.15 2014/03/17 11:08:11 martin Exp $ */
211be35a1SLionel Sambuc
311be35a1SLionel Sambuc /*-
411be35a1SLionel Sambuc * Copyright (c) 2011 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc * All rights reserved.
611be35a1SLionel Sambuc *
711be35a1SLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation
811be35a1SLionel Sambuc * by Jukka Ruohonen.
911be35a1SLionel Sambuc *
1011be35a1SLionel Sambuc * Redistribution and use in source and binary forms, with or without
1111be35a1SLionel Sambuc * modification, are permitted provided that the following conditions
1211be35a1SLionel Sambuc * are met:
1311be35a1SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
1411be35a1SLionel Sambuc * notice, this list of conditions and the following disclaimer.
1511be35a1SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
1611be35a1SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
1711be35a1SLionel Sambuc * documentation and/or other materials provided with the distribution.
1811be35a1SLionel Sambuc *
1911be35a1SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2011be35a1SLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2111be35a1SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2211be35a1SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2311be35a1SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2411be35a1SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2511be35a1SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2611be35a1SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2711be35a1SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2811be35a1SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2911be35a1SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
3011be35a1SLionel Sambuc */
3111be35a1SLionel Sambuc
3211be35a1SLionel Sambuc #include <atf-c.h>
3311be35a1SLionel Sambuc #include <math.h>
34*0a6a1f1dSLionel Sambuc #include "t_libm.h"
3511be35a1SLionel Sambuc
3611be35a1SLionel Sambuc static const struct {
3711be35a1SLionel Sambuc double x;
3811be35a1SLionel Sambuc double y;
3911be35a1SLionel Sambuc } values[] = {
40*0a6a1f1dSLionel Sambuc #ifndef __vax__
41*0a6a1f1dSLionel Sambuc /* vax has no +/- INF */
42*0a6a1f1dSLionel Sambuc { T_LIBM_MINUS_INF, -M_PI / 2 },
43*0a6a1f1dSLionel Sambuc { T_LIBM_PLUS_INF, M_PI / 2 },
44*0a6a1f1dSLionel Sambuc #endif
4511be35a1SLionel Sambuc { -100, -1.560796660108231, },
4611be35a1SLionel Sambuc { -10, -1.471127674303735, },
4711be35a1SLionel Sambuc { -1, -M_PI / 4, },
4811be35a1SLionel Sambuc { -0.1, -0.09966865249116204, },
4911be35a1SLionel Sambuc { 0.1, 0.09966865249116204, },
5011be35a1SLionel Sambuc { 1, M_PI / 4, },
5111be35a1SLionel Sambuc { 10, 1.471127674303735, },
5211be35a1SLionel Sambuc { 100, 1.560796660108231, },
5311be35a1SLionel Sambuc };
5411be35a1SLionel Sambuc
5511be35a1SLionel Sambuc /*
5611be35a1SLionel Sambuc * atan(3)
5711be35a1SLionel Sambuc */
58*0a6a1f1dSLionel Sambuc ATF_LIBM_TEST(atan_nan, "Test atan/atanf(NaN) == NaN")
5911be35a1SLionel Sambuc {
60*0a6a1f1dSLionel Sambuc #ifdef T_LIBM_NAN
61*0a6a1f1dSLionel Sambuc T_LIBM_CHECK_NAN(0, atan, T_LIBM_NAN);
62*0a6a1f1dSLionel Sambuc T_LIBM_CHECK_NAN(0, atanf, T_LIBM_NAN);
63*0a6a1f1dSLionel Sambuc #else
64*0a6a1f1dSLionel Sambuc atf_tc_skip("no NaN on this machine");
6511be35a1SLionel Sambuc #endif
6611be35a1SLionel Sambuc }
6711be35a1SLionel Sambuc
68*0a6a1f1dSLionel Sambuc ATF_LIBM_TEST(atan_inrange, "Test atan/atanf(x) for some values")
6911be35a1SLionel Sambuc {
70*0a6a1f1dSLionel Sambuc unsigned int i;
7111be35a1SLionel Sambuc
7211be35a1SLionel Sambuc for (i = 0; i < __arraycount(values); i++) {
73*0a6a1f1dSLionel Sambuc T_LIBM_CHECK(i, atan, values[i].x, values[i].y, 1.0e-15);
74*0a6a1f1dSLionel Sambuc T_LIBM_CHECK(i, atanf, values[i].x, values[i].y, 1.0e-7);
7511be35a1SLionel Sambuc }
7611be35a1SLionel Sambuc }
7711be35a1SLionel Sambuc
78*0a6a1f1dSLionel Sambuc ATF_LIBM_TEST(atan_zero_neg, "Test atan/atanf(-0.0) == -0.0")
7911be35a1SLionel Sambuc {
80*0a6a1f1dSLionel Sambuc
81*0a6a1f1dSLionel Sambuc T_LIBM_CHECK_MINUS_ZERO(0, atan, -0.0);
82*0a6a1f1dSLionel Sambuc T_LIBM_CHECK_MINUS_ZERO(0, atanf, -0.0);
8311be35a1SLionel Sambuc }
8411be35a1SLionel Sambuc
85*0a6a1f1dSLionel Sambuc ATF_LIBM_TEST(atan_zero_pos, "Test atan/atanf(+0.0) == +0.0")
8611be35a1SLionel Sambuc {
8711be35a1SLionel Sambuc
88*0a6a1f1dSLionel Sambuc T_LIBM_CHECK_PLUS_ZERO(0, atan, +0.0);
89*0a6a1f1dSLionel Sambuc T_LIBM_CHECK_PLUS_ZERO(0, atanf, +0.0);
9011be35a1SLionel Sambuc }
9111be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)9211be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
9311be35a1SLionel Sambuc {
9411be35a1SLionel Sambuc
9511be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, atan_nan);
9611be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, atan_inrange);
9711be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, atan_zero_neg);
9811be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, atan_zero_pos);
9911be35a1SLionel Sambuc
10011be35a1SLionel Sambuc return atf_no_error();
10111be35a1SLionel Sambuc }
102