billvaglienti / ProtoGen

Communications protocol generation software
MIT License
30 stars 16 forks source link

floatspecial.c lint errors #53

Closed jefffisher closed 7 years ago

jefffisher commented 7 years ago

These errors show up when running the prebuilt sources through cppcheck, and they look valid to me, although I'm not 100% positive I'm following the code.

[floatspecial.c:157]: (style) Variable 'significand' is assigned a value that is never used.
[floatspecial.c:352]: (style) Variable 'significand' is assigned a value that is never used.

If I understand this correctly, though, I believe that block of code should be changed as follows:

  if(signedExponent > bias)
  {
      // Largest possible exponent and significand without making a NaN or Inf
      signedExponent = bias;
-     significand = (uint32_t)(1 << sigbits) - 1;
+     output = (uint32_t)(1 << sigbits) - 1;
  }
billvaglienti commented 7 years ago

Fixed in 1.9.5.c. On overflow of conversion from 32 bit floats to smaller types the significand was not being set to the largest possible value. However the exponent was set correctly so the returned result would have still been within a factor of 2 of the largest possible value.