]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/midpoint/floating.cc
1 // Copyright (C) 2019-2020 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
24 #include <testsuite_hooks.h>
29 using lim
= std::numeric_limits
<double>;
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 );
36 VERIFY( std::midpoint(lim::max(), lim::max()) == lim::max() );
42 using lim
= std::numeric_limits
<float>;
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
);
53 using lim
= std::numeric_limits
<long double>;
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 );
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
);
67 constexpr float f
= FLT_MIN
+ FLT_TRUE_MIN
;
68 static_assert( std::midpoint(f
, f
) == f
);
70 constexpr long double l
= LDBL_MIN
+ LDBL_TRUE_MIN
;
71 static_assert( std::midpoint(l
, l
) == l
);