]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/midpoint/floating.cc
1 // Copyright (C) 2019-2024 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-do run { target c++20 } }
23 #include <testsuite_hooks.h>
28 using lim
= std::numeric_limits
<double>;
30 VERIFY( std::midpoint(2.0, 4.0) == 3.0 );
31 VERIFY( std::midpoint(0.0, 0.4) == 0.2 );
32 VERIFY( std::midpoint(0.0, -0.0) == 0.0 );
33 VERIFY( std::midpoint(9e9
, -9e9
) == 0.0 );
35 VERIFY( std::midpoint(lim::max(), lim::max()) == lim::max() );
41 using lim
= std::numeric_limits
<float>;
43 VERIFY( std::midpoint(2.0f
, 4.0f
) == 3.0f
);
44 VERIFY( std::midpoint(0.0f
, 0.4f
) == 0.2f
);
45 VERIFY( std::midpoint(0.0f
, -0.0f
) == 0.0f
);
46 VERIFY( std::midpoint(9e9f
, -9e9f
) == 0.0f
);
52 using lim
= std::numeric_limits
<long double>;
54 VERIFY( std::midpoint(2.0l, 4.0l) == 3.0l );
55 VERIFY( std::midpoint(0.0l, 0.4l) == 0.2l );
56 VERIFY( std::midpoint(0.0l, -0.0l) == 0.0l );
57 VERIFY( std::midpoint(9e9l
, -9e9l
) == 0.0l );
62 // https://gcc.gnu.org/ml/libstdc++/2019-03/msg00065.html
63 constexpr double d
= DBL_MIN
+ DBL_TRUE_MIN
;
64 static_assert( std::midpoint(d
, d
) == d
);
66 constexpr float f
= FLT_MIN
+ FLT_TRUE_MIN
;
67 static_assert( std::midpoint(f
, f
) == f
);
69 constexpr long double l
= LDBL_MIN
+ LDBL_TRUE_MIN
;
70 static_assert( std::midpoint(l
, l
) == l
);