t_atan.c revision 272458
1/* $NetBSD: t_atan.c,v 1.15 2014/03/17 11:08:11 martin Exp $ */ 2 3/*- 4 * Copyright (c) 2011 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jukka Ruohonen. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <atf-c.h> 33#include <math.h> 34#include "t_libm.h" 35 36static const struct { 37 double x; 38 double y; 39} values[] = { 40#ifndef __vax__ 41 /* vax has no +/- INF */ 42 { T_LIBM_MINUS_INF, -M_PI / 2 }, 43 { T_LIBM_PLUS_INF, M_PI / 2 }, 44#endif 45 { -100, -1.560796660108231, }, 46 { -10, -1.471127674303735, }, 47 { -1, -M_PI / 4, }, 48 { -0.1, -0.09966865249116204, }, 49 { 0.1, 0.09966865249116204, }, 50 { 1, M_PI / 4, }, 51 { 10, 1.471127674303735, }, 52 { 100, 1.560796660108231, }, 53}; 54 55/* 56 * atan(3) 57 */ 58ATF_LIBM_TEST(atan_nan, "Test atan/atanf(NaN) == NaN") 59{ 60#ifdef T_LIBM_NAN 61 T_LIBM_CHECK_NAN(0, atan, T_LIBM_NAN); 62 T_LIBM_CHECK_NAN(0, atanf, T_LIBM_NAN); 63#else 64 atf_tc_skip("no NaN on this machine"); 65#endif 66} 67 68ATF_LIBM_TEST(atan_inrange, "Test atan/atanf(x) for some values") 69{ 70 unsigned int i; 71 72 for (i = 0; i < __arraycount(values); i++) { 73 T_LIBM_CHECK(i, atan, values[i].x, values[i].y, 1.0e-15); 74 T_LIBM_CHECK(i, atanf, values[i].x, values[i].y, 1.0e-7); 75 } 76} 77 78ATF_LIBM_TEST(atan_zero_neg, "Test atan/atanf(-0.0) == -0.0") 79{ 80 81 T_LIBM_CHECK_MINUS_ZERO(0, atan, -0.0); 82 T_LIBM_CHECK_MINUS_ZERO(0, atanf, -0.0); 83} 84 85ATF_LIBM_TEST(atan_zero_pos, "Test atan/atanf(+0.0) == +0.0") 86{ 87 88 T_LIBM_CHECK_PLUS_ZERO(0, atan, +0.0); 89 T_LIBM_CHECK_PLUS_ZERO(0, atanf, +0.0); 90} 91 92ATF_TP_ADD_TCS(tp) 93{ 94 95 ATF_TP_ADD_TC(tp, atan_nan); 96 ATF_TP_ADD_TC(tp, atan_inrange); 97 ATF_TP_ADD_TC(tp, atan_zero_neg); 98 ATF_TP_ADD_TC(tp, atan_zero_pos); 99 100 return atf_no_error(); 101} 102