Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress warnings caused by use of -Wswitch_default on GCC #651

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions include/boost/multiprecision/cpp_bin_float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ class cpp_bin_float
m_sign = (f < 0);
m_exponent = exponent_infinity;
return *this;
default:
break;
}
if (f < 0)
{
Expand Down Expand Up @@ -494,6 +496,8 @@ class cpp_bin_float
m_sign = eval_get_sign(f) < 0;
m_exponent = exponent_infinity;
return *this;
default:
break;
}
if (eval_get_sign(f) < 0)
{
Expand Down Expand Up @@ -805,6 +809,8 @@ inline void do_eval_add(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Mi
case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
res = a;
return; // result is still a NaN.
default:
break;
}
switch (b.exponent())
{
Expand All @@ -819,6 +825,8 @@ inline void do_eval_add(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Mi
case BinFloat3::exponent_nan:
res = b;
return; // result is a NaN.
default:
break;
}

static_assert((std::numeric_limits<exponent_type>::max)() - cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count > cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent, "Exponent range check failed");
Expand Down Expand Up @@ -878,6 +886,8 @@ inline void do_eval_subtract(BinFloat1& res, const BinFloat2& a, const BinFloat3
case BinFloat2::exponent_nan:
res = a;
return; // result is still a NaN.
default:
break;
}
switch (b.exponent())
{
Expand All @@ -892,6 +902,8 @@ inline void do_eval_subtract(BinFloat1& res, const BinFloat2& a, const BinFloat3
case BinFloat3::exponent_nan:
res = b;
return; // result is still a NaN.
default:
break;
}

bool s = a.sign();
Expand Down Expand Up @@ -1043,6 +1055,8 @@ inline void eval_multiply(cpp_bin_float<Digits, DigitBase, Allocator, Exponent,
case cpp_bin_float<Digits, DigitBase, Allocator2, Exponent2, MinE2, MaxE2>::exponent_nan:
res = a;
return;
default:
break;
}
if (b.exponent() > cpp_bin_float<Digits, DigitBase, Allocator3, Exponent3, MinE3, MaxE3>::max_exponent)
{
Expand Down Expand Up @@ -1119,6 +1133,8 @@ inline typename std::enable_if<boost::multiprecision::detail::is_unsigned<U>::va
case cpp_bin_float<Digits, DigitBase, Allocator2, Exponent2, MinE2, MaxE2>::exponent_nan:
res = a;
return;
default:
break;
}

typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::double_rep_type dt;
Expand Down Expand Up @@ -1183,6 +1199,8 @@ inline void eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Mi
case cpp_bin_float<Digits, DigitBase, Allocator3, Exponent3, MinE3, MaxE3>::exponent_nan:
res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
return;
default:
break;
}
bool s = u.sign() != v.sign();
res = u;
Expand All @@ -1197,6 +1215,8 @@ inline void eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Mi
case cpp_bin_float<Digits, DigitBase, Allocator3, Exponent3, MinE3, MaxE3>::exponent_nan:
res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
return;
default:
break;
}
bool s = u.sign() != v.sign();
res = u;
Expand All @@ -1206,6 +1226,8 @@ inline void eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Mi
case cpp_bin_float<Digits, DigitBase, Allocator2, Exponent2, MinE2, MaxE2>::exponent_nan:
res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
return;
default:
break;
}
switch (v.exponent())
{
Expand All @@ -1224,6 +1246,8 @@ inline void eval_divide(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Mi
case cpp_bin_float<Digits, DigitBase, Allocator3, Exponent3, MinE3, MaxE3>::exponent_nan:
res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
return;
default:
break;
}

// We can scale u and v so that both are integers, then perform integer
Expand Down Expand Up @@ -1368,6 +1392,8 @@ inline typename std::enable_if<boost::multiprecision::detail::is_unsigned<U>::va
case cpp_bin_float<Digits, DigitBase, Allocator2, Exponent2, MinE2, MaxE2>::exponent_nan:
res = std::numeric_limits<number<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> > >::quiet_NaN().backend();
return;
default:
break;
}
if (v == 0)
{
Expand Down Expand Up @@ -1514,6 +1540,8 @@ inline void convert_to_signed_int(I* res, const cpp_bin_float<Digits, DigitBase,
if (arg.sign())
*res = -*res;
return;
default:
break;
}
using shift_type = typename std::conditional<sizeof(typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type) < sizeof(int), int, typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type>::type;
typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::rep_type man(arg.bits());
Expand Down Expand Up @@ -1589,6 +1617,8 @@ inline void convert_to_unsigned_int(I* res, const cpp_bin_float<Digits, DigitBas
case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
*res = max_val;
return;
default:
break;
}
typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::rep_type man(arg.bits());
using shift_type = typename std::conditional<sizeof(typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type) < sizeof(int), int, typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type>::type;
Expand Down Expand Up @@ -1669,6 +1699,8 @@ inline typename std::enable_if<std::is_floating_point<Float>::value>::type eval_
if (original_arg.sign())
*res = -*res;
return;
default:
break;
}
//
// Check for super large exponent that must be converted to infinity:
Expand Down Expand Up @@ -1740,6 +1772,8 @@ inline void eval_frexp(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Min
*e = 0;
res = arg;
return;
default:
break;
}
res = arg;
*e = arg.exponent() + 1;
Expand Down Expand Up @@ -1768,6 +1802,8 @@ inline void eval_ldexp(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Min
case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
res = arg;
return;
default:
break;
}
if ((e > 0) && (cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::max_exponent - e < arg.exponent()))
{
Expand Down Expand Up @@ -1853,6 +1889,8 @@ inline int eval_fpclassify(const cpp_bin_float<Digits, DigitBase, Allocator, Exp
return FP_INFINITE;
case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
return FP_NAN;
default:
break;
}
return FP_NORMAL;
}
Expand Down Expand Up @@ -1880,6 +1918,8 @@ inline void eval_sqrt(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE
else
res = arg;
return;
default:
break;
}
if (arg.sign())
{
Expand Down Expand Up @@ -1921,6 +1961,8 @@ inline void eval_floor(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, Min
case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_infinity:
res = arg;
return;
default:
break;
}
using shift_type = typename std::conditional<sizeof(typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type) < sizeof(int), int, typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type>::type;
shift_type shift =
Expand Down Expand Up @@ -1969,6 +2011,8 @@ inline void eval_ceil(cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE
case cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_nan:
res = arg;
return;
default:
break;
}
using shift_type = typename std::conditional<sizeof(typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type) < sizeof(int), int, typename cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::exponent_type>::type;
shift_type shift = (shift_type)cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE>::bit_count - arg.exponent() - 1;
Expand Down
2 changes: 2 additions & 0 deletions include/boost/multiprecision/cpp_bin_float/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@
case exponent_infinity:
s = sign() ? "-inf" : f & std::ios_base::showpos ? "+inf" : "inf";
break;
default:
break;

Check warning on line 691 in include/boost/multiprecision/cpp_bin_float/io.hpp

View check run for this annotation

Codecov / codecov/patch

include/boost/multiprecision/cpp_bin_float/io.hpp#L690-L691

Added lines #L690 - L691 were not covered by tests
}
}
return s;
Expand Down
22 changes: 22 additions & 0 deletions include/boost/multiprecision/detail/default_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,8 @@ inline BOOST_MP_CXX14_CONSTEXPR void eval_fmod(T& result, const T& a, const T& b
result = std::numeric_limits<number<T> >::quiet_NaN().backend();
errno = EDOM;
return;
default:
break;
}
switch (eval_fpclassify(b))
{
Expand All @@ -1286,6 +1288,8 @@ inline BOOST_MP_CXX14_CONSTEXPR void eval_fmod(T& result, const T& a, const T& b
result = std::numeric_limits<number<T> >::quiet_NaN().backend();
errno = EDOM;
return;
default:
break;
}
T n;
eval_divide(result, a, b);
Expand Down Expand Up @@ -1411,6 +1415,8 @@ inline BOOST_MP_CXX14_CONSTEXPR void eval_fdim(T& result, const T& a, const T& b
case FP_INFINITE:
result = zero;
return;
default:
break;
}
switch (eval_fpclassify(a))
{
Expand All @@ -1420,6 +1426,8 @@ inline BOOST_MP_CXX14_CONSTEXPR void eval_fdim(T& result, const T& a, const T& b
case FP_INFINITE:
result = a;
return;
default:
break;
}
if (eval_gt(a, b))
{
Expand All @@ -1442,6 +1450,8 @@ inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::d
case FP_INFINITE:
result = zero;
return;
default:
break;
}
switch (eval_fpclassify(a))
{
Expand All @@ -1451,6 +1461,8 @@ inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::d
case FP_INFINITE:
result = a;
return;
default:
break;
}
if (eval_gt(a, canonical_b))
{
Expand All @@ -1473,6 +1485,8 @@ inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::d
case FP_INFINITE:
result = zero;
return;
default:
break;
}
switch (BOOST_MP_FPCLASSIFY(a))
{
Expand All @@ -1482,6 +1496,8 @@ inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::d
case FP_INFINITE:
result = std::numeric_limits<number<T> >::infinity().backend();
return;
default:
break;
}
if (eval_gt(canonical_a, b))
{
Expand All @@ -1504,6 +1520,8 @@ inline BOOST_MP_CXX14_CONSTEXPR void eval_trunc(T& result, const T& a)
case FP_INFINITE:
result = a;
return;
default:
break;
}
if (eval_get_sign(a) < 0)
eval_ceil(result, a);
Expand Down Expand Up @@ -1920,6 +1938,8 @@ inline BOOST_MP_CXX14_CONSTEXPR typename B::exponent_type eval_ilogb(const B& va
return (std::numeric_limits<typename B::exponent_type>::max)();
case FP_ZERO:
return (std::numeric_limits<typename B::exponent_type>::min)();
default:
break;
}
B result;
eval_frexp(result, val, &e);
Expand All @@ -1945,6 +1965,8 @@ inline BOOST_MP_CXX14_CONSTEXPR void eval_logb(B& result, const B& val)
if (eval_signbit(val))
result.negate();
return;
default:
break;
}
using max_t = typename std::conditional<std::is_same<std::intmax_t, long>::value, long long, std::intmax_t>::type;
result = static_cast<max_t>(eval_ilogb(val));
Expand Down
4 changes: 4 additions & 0 deletions include/boost/multiprecision/detail/functions/pow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ inline void pow_imp(T& result, const T& t, const U& p, const std::integral_const
eval_multiply(result, t, t);
eval_multiply(result, result);
return;
default:
break;
}

// This will store the result.
Expand Down Expand Up @@ -392,6 +394,8 @@ void eval_log(T& result, const T& arg)
result.negate();
errno = ERANGE;
return;
default:
break;
}
if (s)
{
Expand Down
6 changes: 6 additions & 0 deletions include/boost/multiprecision/detail/functions/trig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ inline void eval_acos(T& result, const T& x)
result = get_constant_pi<T>();
eval_ldexp(result, result, -1); // divide by two.
return;
default:
break;
}

T xx;
Expand Down Expand Up @@ -986,6 +988,8 @@ void eval_atan2(T& result, const T& y, const T& x)
}
return;
}
default:
break;
}

switch (eval_fpclassify(x))
Expand All @@ -1009,6 +1013,8 @@ void eval_atan2(T& result, const T& y, const T& x)
if (eval_get_sign(y) < 0)
result.negate();
return;
default:
break;
}

T xx;
Expand Down