mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-06 14:56:51 +08:00
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
This commit is contained in:
committed by
Daniel Agar
parent
02cee07469
commit
6e35cb002f
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user