]>
Commit | Line | Data |
---|---|---|
99dee823 | 1 | // Copyright (C) 2019-2021 Free Software Foundation, Inc. |
24387442 JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-options "-std=gnu++2a" } | |
19 | // { dg-do run { target c++2a } } | |
20 | ||
21 | #include <numeric> | |
22 | #include <limits> | |
a3c8d7fb | 23 | #include <cfloat> |
24387442 JW |
24 | #include <testsuite_hooks.h> |
25 | ||
26 | void | |
27 | test01() | |
28 | { | |
29 | using lim = std::numeric_limits<double>; | |
30 | ||
31 | VERIFY( std::midpoint(2.0, 4.0) == 3.0 ); | |
32 | VERIFY( std::midpoint(0.0, 0.4) == 0.2 ); | |
33 | VERIFY( std::midpoint(0.0, -0.0) == 0.0 ); | |
34 | VERIFY( std::midpoint(9e9, -9e9) == 0.0 ); | |
35 | ||
36 | VERIFY( std::midpoint(lim::max(), lim::max()) == lim::max() ); | |
37 | } | |
38 | ||
39 | void | |
40 | test02() | |
41 | { | |
42 | using lim = std::numeric_limits<float>; | |
43 | ||
44 | VERIFY( std::midpoint(2.0f, 4.0f) == 3.0f ); | |
45 | VERIFY( std::midpoint(0.0f, 0.4f) == 0.2f ); | |
46 | VERIFY( std::midpoint(0.0f, -0.0f) == 0.0f ); | |
47 | VERIFY( std::midpoint(9e9f, -9e9f) == 0.0f ); | |
48 | } | |
49 | ||
50 | void | |
51 | test03() | |
52 | { | |
53 | using lim = std::numeric_limits<long double>; | |
54 | ||
55 | VERIFY( std::midpoint(2.0l, 4.0l) == 3.0l ); | |
56 | VERIFY( std::midpoint(0.0l, 0.4l) == 0.2l ); | |
57 | VERIFY( std::midpoint(0.0l, -0.0l) == 0.0l ); | |
58 | VERIFY( std::midpoint(9e9l, -9e9l) == 0.0l ); | |
59 | } | |
60 | ||
a3c8d7fb JW |
61 | namespace test04 |
62 | { | |
63 | // https://gcc.gnu.org/ml/libstdc++/2019-03/msg00065.html | |
64 | constexpr double d = DBL_MIN + DBL_TRUE_MIN; | |
65 | static_assert( std::midpoint(d, d) == d ); | |
66 | ||
67 | constexpr float f = FLT_MIN + FLT_TRUE_MIN; | |
68 | static_assert( std::midpoint(f, f) == f ); | |
69 | ||
70 | constexpr long double l = LDBL_MIN + LDBL_TRUE_MIN; | |
71 | static_assert( std::midpoint(l, l) == l ); | |
72 | } | |
73 | ||
24387442 JW |
74 | int main() |
75 | { | |
76 | test01(); | |
77 | test02(); | |
78 | test03(); | |
79 | } |