Skip to content

Commit

Permalink
Remove unneeded casts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AZero13 committed Nov 17, 2022
1 parent 23b1fba commit d2a27f9
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions include/boost/math/cstdfloat/cstdfloat_iostream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@
eval_floor(t, t);
eval_convert_to(&expon, t);

if(-expon > std::numeric_limits<float_type>::max_exponent10 - 3)
if(expon < -std::numeric_limits<float_type>::max_exponent10 + 3)
{
int e = -expon / 2;

Expand Down Expand Up @@ -502,7 +502,7 @@
eval_floor(digit, t);
eval_convert_to(&cdigit, digit);

result += static_cast<char>('0' + cdigit);
result += '0' + cdigit;

eval_subtract(t, digit);
eval_multiply(t, ten);
Expand All @@ -518,15 +518,14 @@
if((cdigit == 5) && (t == 0))
{
// Use simple bankers rounding.

if((static_cast<int>(*result.rbegin() - '0') & 1) != 0)
if(((*result.rbegin() - '0') & 1) != 0)
{
round_string_up_at(result, static_cast<int>(result.size() - 1U), expon);
}
}
else if(cdigit >= 5)
{
round_string_up_at(result, static_cast<int>(result.size() - 1), expon);
round_string_up_at(result, static_cast<int>(result.size() - 1U), expon);
}
}
}
Expand Down Expand Up @@ -569,9 +568,9 @@
{
value = 0;

if((p == static_cast<const char*>(0U)) || (*p == static_cast<char>(0)))
if((p == nullptr) || (*p == '\0'))
{
return;
return false;
}

bool is_neg = false;
Expand All @@ -584,11 +583,11 @@

constexpr int max_digits = std::numeric_limits<float_type>::max_digits10 + 1;

if(*p == static_cast<char>('+'))
if(*p == '+')
{
++p;
}
else if(*p == static_cast<char>('-'))
else if(*p == '-')
{
is_neg = true;
++p;
Expand Down Expand Up @@ -632,24 +631,20 @@
++digits_seen;
}

if(*p == static_cast<char>('.'))
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<int>(*p - '0'));
++p;
--expon;

if(++digits_seen > max_digits)
{
break;
}
++digits_seen;
}

while(std::isdigit(*p))
Expand All @@ -659,15 +654,15 @@
}

// Parse the exponent.
if((*p == static_cast<char>('e')) || (*p == static_cast<char>('E')))
if((*p == 'e') || (*p == 'E'))
{
++p;

if(*p == static_cast<char>('+'))
if(*p == '+')
{
++p;
}
else if(*p == static_cast<char>('-'))
else if(*p == '-')
{
is_neg_expon = true;
++p;
Expand All @@ -678,7 +673,7 @@
while(std::isdigit(*p))
{
e2 *= 10;
e2 += (*p - '0');
e2 += static_cast<int>(*p - '0');
++p;
}

Expand Down Expand Up @@ -718,7 +713,7 @@
value = -value;
}

return (*p == static_cast<char>(0));
return (*p == '\0');
}
} } } } // boost::math::cstdfloat::detail

Expand Down

0 comments on commit d2a27f9

Please sign in to comment.