Skip to content

Commit

Permalink
Merge pull request #257 from OpenKNX/devel
Browse files Browse the repository at this point in the history
FIX: float16ToPayload
  • Loading branch information
thelsing authored Aug 25, 2023
2 parents 6dda682 + fd952c8 commit 15bf1c0
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) - 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 15bf1c0

Please sign in to comment.