From b3ba88f8196208dc40840d09ba03aa97998839b8 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 6 Jan 2019 20:48:15 -0500 Subject: [PATCH] docs by Matt K --- firmware/Makefile | 1 + firmware/util/efilib.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/firmware/Makefile b/firmware/Makefile index 86add23e05..eb67c13f6b 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -30,6 +30,7 @@ endif # C++ specific options here (added to USE_OPT). ifeq ($(USE_CPPOPT),) + # constexpr float expf_taylor_impl probably needs just c++14 but why not go with 17? USE_CPPOPT = -std=c++17 -Wno-register -fno-rtti -fno-exceptions -fno-use-cxa-atexit -Werror=write-strings -Werror=type-limits endif diff --git a/firmware/util/efilib.cpp b/firmware/util/efilib.cpp index 0aa13fcd13..b4b3edc5d0 100644 --- a/firmware/util/efilib.cpp +++ b/firmware/util/efilib.cpp @@ -318,6 +318,10 @@ float limitRateOfChange(float newValue, float oldValue, float incrLimitPerSec, f constexpr float constant_e = 2.71828f; +// 'constexpr' is a keyword that tells the compiler +// "yes, this thing, it's a 'pure function' that only depends on its inputs and has no side effects" +// like how const is a constant value, constexpr is a constant expression +// so if somewhere you used it in a way that it could determine the exact arguments to the function at compile time, it will _run_ the function at compile time, and cook in the result as a constant constexpr float expf_taylor_impl(float x, uint8_t n) { if (x < -2)