From 5fe29338536a77c270ae8e742f418e0be14130fd Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Tue, 15 Nov 2022 12:35:20 -0500 Subject: [PATCH] Remove unneeded casts Most of these casts are redundant, and automatically dealt with by either the C++/C standard, or operations done onto said numbers, such as & 1 operation making casts to int pointless. --- .../math/cstdfloat/cstdfloat_iostream.hpp | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/include/boost/math/cstdfloat/cstdfloat_iostream.hpp b/include/boost/math/cstdfloat/cstdfloat_iostream.hpp index c01c236f71..646f6d9043 100644 --- a/include/boost/math/cstdfloat/cstdfloat_iostream.hpp +++ b/include/boost/math/cstdfloat/cstdfloat_iostream.hpp @@ -448,7 +448,7 @@ eval_floor(t, t); eval_convert_to(&expon, t); - if(-expon > std::numeric_limits::max_exponent10 - 3) + if(expon < -std::numeric_limits::max_exponent10 + 3) { int e = -expon / 2; @@ -518,15 +518,14 @@ if((cdigit == 5) && (t == 0)) { // Use simple bankers rounding. - - if((static_cast(*result.rbegin() - '0') & 1) != 0) + if(((*result.rbegin() - '0') & 1) != 0) { round_string_up_at(result, static_cast(result.size() - 1U), expon); } } else if(cdigit >= 5) { - round_string_up_at(result, static_cast(result.size() - 1), expon); + round_string_up_at(result, static_cast(result.size() - 1U), expon); } } } @@ -569,9 +568,9 @@ { value = 0; - if((p == static_cast(0U)) || (*p == static_cast(0))) + if((p == nullptr) || (*p == '\0')) { - return; + return false; } bool is_neg = false; @@ -584,11 +583,11 @@ constexpr int max_digits = std::numeric_limits::max_digits10 + 1; - if(*p == static_cast('+')) + if(*p == '+') { ++p; } - else if(*p == static_cast('-')) + else if(*p == '-') { is_neg = true; ++p; @@ -632,24 +631,20 @@ ++digits_seen; } - if(*p == static_cast('.')) + if(*p == '.') { // Grab everything after the point, stop when we've seen // enough digits, even if there are actually more available. ++p; - while(std::isdigit(*p)) + while(std::isdigit(*p) && digits_seen <= max_digits) { eval_multiply(value, ten); eval_add(value, static_cast(*p - '0')); ++p; --expon; - - if(++digits_seen > max_digits) - { - break; - } + ++digits_seen; } while(std::isdigit(*p)) @@ -659,15 +654,15 @@ } // Parse the exponent. - if((*p == static_cast('e')) || (*p == static_cast('E'))) + if((*p == 'e') || (*p == 'E')) { ++p; - if(*p == static_cast('+')) + if(*p == '+') { ++p; } - else if(*p == static_cast('-')) + else if(*p == '-') { is_neg_expon = true; ++p; @@ -678,7 +673,7 @@ while(std::isdigit(*p)) { e2 *= 10; - e2 += (*p - '0'); + e2 += static_cast(*p - '0'); ++p; } @@ -718,7 +713,7 @@ value = -value; } - return (*p == static_cast(0)); + return (*p == '\0'); } } } } } // boost::math::cstdfloat::detail