1*640235e2SEnji Cooper /* $NetBSD: t_hypot.c,v 1.1 2016/01/24 20:26:47 gson Exp $ */ 2*640235e2SEnji Cooper 3*640235e2SEnji Cooper /*- 4*640235e2SEnji Cooper * Copyright (c) 2016 The NetBSD Foundation, Inc. 5*640235e2SEnji Cooper * All rights reserved. 6*640235e2SEnji Cooper * 7*640235e2SEnji Cooper * Redistribution and use in source and binary forms, with or without 8*640235e2SEnji Cooper * modification, are permitted provided that the following conditions 9*640235e2SEnji Cooper * are met: 10*640235e2SEnji Cooper * 1. Redistributions of source code must retain the above copyright 11*640235e2SEnji Cooper * notice, this list of conditions and the following disclaimer. 12*640235e2SEnji Cooper * 2. Redistributions in binary form must reproduce the above copyright 13*640235e2SEnji Cooper * notice, this list of conditions and the following disclaimer in the 14*640235e2SEnji Cooper * documentation and/or other materials provided with the distribution. 15*640235e2SEnji Cooper * 16*640235e2SEnji Cooper * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17*640235e2SEnji Cooper * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18*640235e2SEnji Cooper * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19*640235e2SEnji Cooper * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20*640235e2SEnji Cooper * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21*640235e2SEnji Cooper * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22*640235e2SEnji Cooper * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23*640235e2SEnji Cooper * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24*640235e2SEnji Cooper * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25*640235e2SEnji Cooper * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26*640235e2SEnji Cooper * POSSIBILITY OF SUCH DAMAGE. 27*640235e2SEnji Cooper */ 28*640235e2SEnji Cooper 29*640235e2SEnji Cooper #include <atf-c.h> 30*640235e2SEnji Cooper #include <math.h> 31*640235e2SEnji Cooper 32*640235e2SEnji Cooper ATF_TC(hypot_integer); 33*640235e2SEnji Cooper ATF_TC_HEAD(hypot_integer, tc) 34*640235e2SEnji Cooper { 35*640235e2SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test hypot with integer args"); 36*640235e2SEnji Cooper } 37*640235e2SEnji Cooper 38*640235e2SEnji Cooper ATF_TC_BODY(hypot_integer, tc) 39*640235e2SEnji Cooper { 40*640235e2SEnji Cooper /* volatile so hypotf() won't be evaluated at compile time */ 41*640235e2SEnji Cooper volatile double a = 5; 42*640235e2SEnji Cooper volatile double b = 12; 43*640235e2SEnji Cooper ATF_CHECK(hypot(a, b) == 13.0); 44*640235e2SEnji Cooper } 45*640235e2SEnji Cooper 46*640235e2SEnji Cooper ATF_TC(hypotf_integer); 47*640235e2SEnji Cooper ATF_TC_HEAD(hypotf_integer, tc) 48*640235e2SEnji Cooper { 49*640235e2SEnji Cooper atf_tc_set_md_var(tc, "descr", "Test hypotf with integer args"); 50*640235e2SEnji Cooper } 51*640235e2SEnji Cooper 52*640235e2SEnji Cooper ATF_TC_BODY(hypotf_integer, tc) 53*640235e2SEnji Cooper { 54*640235e2SEnji Cooper volatile float a = 5; 55*640235e2SEnji Cooper volatile float b = 12; 56*640235e2SEnji Cooper ATF_CHECK(hypotf(a, b) == 13.0f); 57*640235e2SEnji Cooper } 58*640235e2SEnji Cooper 59*640235e2SEnji Cooper ATF_TC(pr50698); 60*640235e2SEnji Cooper ATF_TC_HEAD(pr50698, tc) 61*640235e2SEnji Cooper { 62*640235e2SEnji Cooper atf_tc_set_md_var(tc, "descr", "Check for the bug of PR 50698"); 63*640235e2SEnji Cooper } 64*640235e2SEnji Cooper 65*640235e2SEnji Cooper ATF_TC_BODY(pr50698, tc) 66*640235e2SEnji Cooper { 67*640235e2SEnji Cooper volatile float a = 1e-18f; 68*640235e2SEnji Cooper float val = hypotf(a, a); 69*640235e2SEnji Cooper ATF_CHECK(!isinf(val)); 70*640235e2SEnji Cooper ATF_CHECK(!isnan(val)); 71*640235e2SEnji Cooper } 72*640235e2SEnji Cooper 73*640235e2SEnji Cooper ATF_TP_ADD_TCS(tp) 74*640235e2SEnji Cooper { 75*640235e2SEnji Cooper 76*640235e2SEnji Cooper ATF_TP_ADD_TC(tp, hypot_integer); 77*640235e2SEnji Cooper ATF_TP_ADD_TC(tp, hypotf_integer); 78*640235e2SEnji Cooper ATF_TP_ADD_TC(tp, pr50698); 79*640235e2SEnji Cooper 80*640235e2SEnji Cooper return atf_no_error(); 81*640235e2SEnji Cooper } 82