🔨 small refactoring to improve branch coverage
The branch coverage reported by lcov is weird. The code before and after has the same Godbolt assembler, but the code with the lambda has a better branch coverage.
This commit is contained in:
parent
c8bfdfd961
commit
ed6a0686df
2 changed files with 34 additions and 30 deletions
|
@ -408,22 +408,24 @@ class binary_reader
|
||||||
// half-precision floating-point numbers in the C language
|
// half-precision floating-point numbers in the C language
|
||||||
// is shown in Fig. 3.
|
// is shown in Fig. 3.
|
||||||
const int half = (byte1 << 8) + byte2;
|
const int half = (byte1 << 8) + byte2;
|
||||||
|
const double val = [&half]
|
||||||
|
{
|
||||||
const int exp = (half >> 10) & 0x1F;
|
const int exp = (half >> 10) & 0x1F;
|
||||||
const int mant = half & 0x3FF;
|
const int mant = half & 0x3FF;
|
||||||
double val;
|
assert(0 <= exp and exp <= 32);
|
||||||
if (exp == 0)
|
assert(0 <= mant and mant <= 1024);
|
||||||
|
switch (exp)
|
||||||
{
|
{
|
||||||
val = std::ldexp(mant, -24);
|
case 0:
|
||||||
}
|
return std::ldexp(mant, -24);
|
||||||
else if (exp != 31)
|
case 31:
|
||||||
{
|
return (mant == 0)
|
||||||
val = std::ldexp(mant + 1024, exp - 25);
|
? std::numeric_limits<double>::infinity()
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
val = (mant == 0) ? std::numeric_limits<double>::infinity()
|
|
||||||
: std::numeric_limits<double>::quiet_NaN();
|
: std::numeric_limits<double>::quiet_NaN();
|
||||||
|
default:
|
||||||
|
return std::ldexp(mant + 1024, exp - 25);
|
||||||
}
|
}
|
||||||
|
}();
|
||||||
return sax->number_float((half & 0x8000) != 0
|
return sax->number_float((half & 0x8000) != 0
|
||||||
? static_cast<number_float_t>(-val)
|
? static_cast<number_float_t>(-val)
|
||||||
: static_cast<number_float_t>(val), "");
|
: static_cast<number_float_t>(val), "");
|
||||||
|
|
|
@ -6041,22 +6041,24 @@ class binary_reader
|
||||||
// half-precision floating-point numbers in the C language
|
// half-precision floating-point numbers in the C language
|
||||||
// is shown in Fig. 3.
|
// is shown in Fig. 3.
|
||||||
const int half = (byte1 << 8) + byte2;
|
const int half = (byte1 << 8) + byte2;
|
||||||
|
const double val = [&half]
|
||||||
|
{
|
||||||
const int exp = (half >> 10) & 0x1F;
|
const int exp = (half >> 10) & 0x1F;
|
||||||
|
assert(0 <= exp and exp <= 32);
|
||||||
const int mant = half & 0x3FF;
|
const int mant = half & 0x3FF;
|
||||||
double val;
|
assert(0 <= mant and mant <= 1024);
|
||||||
if (exp == 0)
|
switch (exp)
|
||||||
{
|
{
|
||||||
val = std::ldexp(mant, -24);
|
case 0:
|
||||||
}
|
return std::ldexp(mant, -24);
|
||||||
else if (exp != 31)
|
case 31:
|
||||||
{
|
return (mant == 0)
|
||||||
val = std::ldexp(mant + 1024, exp - 25);
|
? std::numeric_limits<double>::infinity()
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
val = (mant == 0) ? std::numeric_limits<double>::infinity()
|
|
||||||
: std::numeric_limits<double>::quiet_NaN();
|
: std::numeric_limits<double>::quiet_NaN();
|
||||||
|
default:
|
||||||
|
return std::ldexp(mant + 1024, exp - 25);
|
||||||
}
|
}
|
||||||
|
}();
|
||||||
return sax->number_float((half & 0x8000) != 0
|
return sax->number_float((half & 0x8000) != 0
|
||||||
? static_cast<number_float_t>(-val)
|
? static_cast<number_float_t>(-val)
|
||||||
: static_cast<number_float_t>(val), "");
|
: static_cast<number_float_t>(val), "");
|
||||||
|
|
Loading…
Reference in a new issue