Merge pull request #257 from OpenKNX/devel

FIX: float16ToPayload
This commit is contained in:
thelsing 2023-08-25 15:22:16 +02:00 committed by GitHub
commit 15bf1c0a9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;