xref: /freebsd/contrib/netbsd-tests/lib/libm/t_cabsl.cxx (revision 1ec3feb64826d2a43d41e74684690985bf20e71c)
1*1ec3feb6SAlex Richardson /*-
2*1ec3feb6SAlex Richardson  * Copyright (c) 2018 The NetBSD Foundation, Inc.
3*1ec3feb6SAlex Richardson  * All rights reserved.
4*1ec3feb6SAlex Richardson  *
5*1ec3feb6SAlex Richardson  * This code is derived from software contributed to The NetBSD Foundation
6*1ec3feb6SAlex Richardson  * by Maya Rashish
7*1ec3feb6SAlex Richardson  *
8*1ec3feb6SAlex Richardson  * Redistribution and use in source and binary forms, with or without
9*1ec3feb6SAlex Richardson  * modification, are permitted provided that the following conditions
10*1ec3feb6SAlex Richardson  * are met:
11*1ec3feb6SAlex Richardson  * 1. Redistributions of source code must retain the above copyright
12*1ec3feb6SAlex Richardson  *    notice, this list of conditions and the following disclaimer.
13*1ec3feb6SAlex Richardson  * 2. Redistributions in binary form must reproduce the above copyright
14*1ec3feb6SAlex Richardson  *    notice, this list of conditions and the following disclaimer in the
15*1ec3feb6SAlex Richardson  *    documentation and/or other materials provided with the distribution.
16*1ec3feb6SAlex Richardson  *
17*1ec3feb6SAlex Richardson  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18*1ec3feb6SAlex Richardson  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19*1ec3feb6SAlex Richardson  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20*1ec3feb6SAlex Richardson  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21*1ec3feb6SAlex Richardson  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*1ec3feb6SAlex Richardson  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*1ec3feb6SAlex Richardson  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*1ec3feb6SAlex Richardson  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*1ec3feb6SAlex Richardson  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*1ec3feb6SAlex Richardson  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*1ec3feb6SAlex Richardson  * POSSIBILITY OF SUCH DAMAGE.
28*1ec3feb6SAlex Richardson  */
29*1ec3feb6SAlex Richardson 
30*1ec3feb6SAlex Richardson /*
31*1ec3feb6SAlex Richardson  * Test that C++ "cabsl" is usable. PR lib/50646
32*1ec3feb6SAlex Richardson  */
33*1ec3feb6SAlex Richardson 
34*1ec3feb6SAlex Richardson #include <atf-c++.hpp>
35*1ec3feb6SAlex Richardson #include <complex>
36*1ec3feb6SAlex Richardson 
37*1ec3feb6SAlex Richardson ATF_TEST_CASE(cabsl);
ATF_TEST_CASE_HEAD(cabsl)38*1ec3feb6SAlex Richardson ATF_TEST_CASE_HEAD(cabsl)
39*1ec3feb6SAlex Richardson {
40*1ec3feb6SAlex Richardson 	set_md_var("descr", "Check that cabsl is usable from C++");
41*1ec3feb6SAlex Richardson }
ATF_TEST_CASE_BODY(cabsl)42*1ec3feb6SAlex Richardson ATF_TEST_CASE_BODY(cabsl)
43*1ec3feb6SAlex Richardson {
44*1ec3feb6SAlex Richardson 	int sum = 0;
45*1ec3feb6SAlex Richardson 
46*1ec3feb6SAlex Richardson #ifdef __HAVE_LONG_DOUBLE
47*1ec3feb6SAlex Richardson 	std::complex<long double> cld(3.0,4.0);
48*1ec3feb6SAlex Richardson 	sum += std::abs(cld);
49*1ec3feb6SAlex Richardson #endif
50*1ec3feb6SAlex Richardson 	std::complex<double> cd(3.0,4.0);
51*1ec3feb6SAlex Richardson 	sum += std::abs(cd);
52*1ec3feb6SAlex Richardson 
53*1ec3feb6SAlex Richardson 	std::complex<float> cf(3.0,4.0);
54*1ec3feb6SAlex Richardson 	sum += std::abs(cf);
55*1ec3feb6SAlex Richardson 
56*1ec3feb6SAlex Richardson #ifdef __HAVE_LONG_DOUBLE
57*1ec3feb6SAlex Richardson 	ATF_REQUIRE_EQ(sum, 3*5);
58*1ec3feb6SAlex Richardson #else
59*1ec3feb6SAlex Richardson 	ATF_REQUIRE_EQ(sum, 2*5);
60*1ec3feb6SAlex Richardson #endif
61*1ec3feb6SAlex Richardson }
62*1ec3feb6SAlex Richardson 
ATF_INIT_TEST_CASES(tcs)63*1ec3feb6SAlex Richardson ATF_INIT_TEST_CASES(tcs)
64*1ec3feb6SAlex Richardson {
65*1ec3feb6SAlex Richardson 	ATF_ADD_TEST_CASE(tcs, cabsl);
66*1ec3feb6SAlex Richardson }
67