From 67cb716e664f5b6f86a338a8b04728811bd5c84d 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 | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/include/boost/math/cstdfloat/cstdfloat_iostream.hpp b/include/boost/math/cstdfloat/cstdfloat_iostream.hpp index c01c236f71..8942d3ab8e 100644 --- a/include/boost/math/cstdfloat/cstdfloat_iostream.hpp +++ b/include/boost/math/cstdfloat/cstdfloat_iostream.hpp @@ -96,7 +96,7 @@ // So we have to use dynamic memory allocation for the output // string buffer. - char* my_buffer2 = static_cast(0U); + char* my_buffer2 = nullptr; #ifndef BOOST_NO_EXCEPTIONS try @@ -265,18 +265,18 @@ else if(!fixed || (my_exp >= 0)) { // Pad out the end with zero's if we need to. + auto chars = str.size(); - int chars = static_cast(str.size()); - chars = digits - chars; - - if(scientific) + if(digits >= chars) { - ++chars; - } + chars = digits - chars; - if(chars > 0) - { - str.append(static_cast(chars), '0'); + if(scientific) + { + ++chars; + } + + str.append(chars, '0'); } } @@ -442,7 +442,7 @@ if(isneg) { x = -x; } float_type t; - float_type ten = 10; + constexpr float_type ten = 10; eval_log10(t, x); eval_floor(t, t); @@ -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,7 +631,7 @@ ++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. @@ -659,15 +658,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; @@ -684,10 +683,12 @@ if(is_neg_expon) { - e2 = -e2; + expon -= e2; + } + else + { + expon += e2; } - - expon += e2; } if(expon) @@ -718,7 +719,7 @@ value = -value; } - return (*p == static_cast(0)); + return (*p == '\0'); } } } } } // boost::math::cstdfloat::detail