From 6e35cb002fd99b813be086ae47e914fe38257186 Mon Sep 17 00:00:00 2001 From: Julien Lecoeur Date: Mon, 7 Aug 2017 15:11:49 +0200 Subject: [PATCH] PX4IO interface protocol: Fix rounding error Issue: This conversion test failed with gcc 7.1.1 and clang 4.0.1: ``` ERROR [tests] conversion fail: input: -0.8188, intermediate: -8187, result: -0.8187 conv FAILED Command 'tests' failed, returned -1 ``` Fix: explicit rounding --- src/modules/px4iofirmware/protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/px4iofirmware/protocol.h b/src/modules/px4iofirmware/protocol.h index a787a9cc17..f1d0bccbba 100644 --- a/src/modules/px4iofirmware/protocol.h +++ b/src/modules/px4iofirmware/protocol.h @@ -74,7 +74,7 @@ #define SIGNED_TO_REG(_signed) ((uint16_t)(_signed)) #define REG_TO_FLOAT(_reg) ((float)REG_TO_SIGNED(_reg) / 10000.0f) -#define FLOAT_TO_REG(_float) SIGNED_TO_REG((int16_t)((_float) * 10000.0f)) +#define FLOAT_TO_REG(_float) SIGNED_TO_REG((int16_t)floorf((_float + 0.00005f) * 10000.0f)) #define PX4IO_PROTOCOL_VERSION 4