Teensy 3.x compiler warns that 'float' constants are out of range
Created by: sarfata
With the latest version of ArduinoJson and the support for 64bits double, the compiler generates the following warnings:
In file included from lib/ArduinoJson/src/ArduinoJson/Deserialization/../Serialization/JsonWriter.hpp:17:0,
from lib/ArduinoJson/src/ArduinoJson/Deserialization/../Serialization/JsonSerializer.hpp:10,
from lib/ArduinoJson/src/ArduinoJson/Deserialization/../Serialization/JsonPrintable.hpp:15,
from lib/ArduinoJson/src/ArduinoJson/Deserialization/../JsonVariantBase.hpp:12,
from lib/ArduinoJson/src/ArduinoJson/Deserialization/../JsonVariant.hpp:16,
from lib/ArduinoJson/src/ArduinoJson/Deserialization/../JsonBuffer.hpp:15,
from lib/ArduinoJson/src/ArduinoJson/Deserialization/JsonParser.hpp:10,
from lib/ArduinoJson/src/ArduinoJson/JsonBufferBase.hpp:10,
from lib/ArduinoJson/src/ArduinoJson/DynamicJsonBuffer.hpp:10,
from lib/ArduinoJson/src/ArduinoJson.hpp:10,
from lib/ArduinoJson/src/ArduinoJson.h:10,
from src/common/signalk/SKJSONVisitor.h:33,
from src/common/signalk/SKJSONVisitor.cpp:31:
lib/ArduinoJson/src/ArduinoJson/Deserialization/../Serialization/../TypeTraits/FloatTraits.hpp:37:14: warning: floating constant exceeds range of 'float' [-Woverflow]
(e & 64 ? 1e64 : 1) * (e & 128 ? 1e128 : 1) *
^
lib/ArduinoJson/src/ArduinoJson/Deserialization/../Serialization/../TypeTraits/FloatTraits.hpp:37:14: warning: floating constant exceeds range of 'float' [-Woverflow]
lib/ArduinoJson/src/ArduinoJson/Deserialization/../Serialization/../TypeTraits/FloatTraits.hpp:38:14: warning: floating constant exceeds range of 'float' [-Woverflow]
(e & 256 ? 1e256 : 1);
^
lib/ArduinoJson/src/ArduinoJson/Deserialization/../Serialization/../TypeTraits/FloatTraits.hpp:42:12: warning: floating constant truncated to zero [-Woverflow]
(e & 64 ? 1e-64 : 1) * (e & 128 ? 1e-128 : 1) *
^
lib/ArduinoJson/src/ArduinoJson/Deserialization/../Serialization/../TypeTraits/FloatTraits.hpp:42:12: warning: floating constant truncated to zero [-Woverflow]
lib/ArduinoJson/src/ArduinoJson/Deserialization/../Serialization/../TypeTraits/FloatTraits.hpp:43:12: warning: floating constant truncated to zero [-Woverflow]
(e & 256 ? 1e-256 : 1);
^
The problem here is that Teensy 3.x micro-controllers support 64bits precision double but Teensy framework sets the -fsingle-precision-constant
compiler flag.
Besides the annoying warning messages, this is probably going to generate actual bugs since the constants are truncated to float max/min.
PR coming up to propose a fix.