From 7c4097bd528ad2a0f5ff4e7bdad888ccd690b528 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 14 Jul 2020 20:39:02 +0200 Subject: [PATCH] CODING_CONVENTIONS.md: add a note about float Floating point math should be avoided in the embedded space. --- CODING_CONVENTIONS.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CODING_CONVENTIONS.md b/CODING_CONVENTIONS.md index 95f002f339..5c4c69c0d4 100644 --- a/CODING_CONVENTIONS.md +++ b/CODING_CONVENTIONS.md @@ -7,6 +7,15 @@ * Avoid dynamic memory allocation (malloc/free, new, etc.)! It will break real-time guarantees, increase code complexity, and make it more likely to use more memory than available. +* Avoid the use of floating point arithmetic. Not every MCU has a FPU and software + floating point libraries cause unnecessary overhead. + Instead use fixed-point integers and transform equations so that they stay within + the range of integer math. + An easy way to ensure this is by multiplying by a constant factor, ideally a power + of two - this is a simple shift operation. + Take care that intermediate values do not exceed the range of the data type you are using. + When writing drivers, do not convert the measurement data into float, but instead + choose an appropriate integer format / SI prefix. * Please obey the Linux coding style as described in https://www.kernel.org/doc/Documentation/process/coding-style.rst with the following modifications and additions: