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