Skip to content

Commit

Permalink
Improved float16ToPayload correction
Browse files Browse the repository at this point in the history
  • Loading branch information
Waldemar Porscha committed Aug 24, 2023
1 parent 9c4e5d2 commit a5c7921
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/knx/dptconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,12 @@ void float16ToPayload(uint8_t* payload, size_t payload_length, int index, double
exponent = ceil(log2(value + 1.0) - 11.0);

short mantissa = roundf(value / (1 << exponent));
// above calculation causes mantissa overflow for values of the form 2^n, where n>11
if (mantissa >= 0x800)
{
exponent++;
mantissa = roundf(value / (1 << exponent));
}

if (wasNegative)
mantissa *= -1;
Expand Down

0 comments on commit a5c7921

Please sign in to comment.