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