Przeglądaj źródła

Set `ARDUINOJSON_USE_DOUBLE` to `0` by default on 8-bit architectures

Benoit Blanchon 1 rok temu
rodzic
commit
0278e94fce
3 zmienionych plików z 12 dodań i 7 usunięć
  1. 1 0
      CHANGELOG.md
  2. 1 1
      extras/conf_test/avr.cpp
  3. 10 6
      src/ArduinoJson/Configuration.hpp

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@ HEAD
 * Store 64-bit numbers (`double` and `long long`) in an additional slot
 * Reduce the slot size (see table below)
 * Improve message when user forgets third arg of `serializeJson()` et al.
+* Set `ARDUINOJSON_USE_DOUBLE` to `0` by default on 8-bit architectures
 
 | Architecture | before   | after    |
 |--------------|----------|----------|

+ 1 - 1
extras/conf_test/avr.cpp

@@ -8,7 +8,7 @@ static_assert(ARDUINOJSON_SLOT_ID_SIZE == 1, "ARDUINOJSON_SLOT_ID_SIZE");
 
 static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
 
-static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
+static_assert(ARDUINOJSON_USE_DOUBLE == 0, "ARDUINOJSON_USE_DOUBLE");
 
 static_assert(sizeof(ArduinoJson::detail::VariantData) == 6,
               "sizeof(VariantData)");

+ 10 - 6
src/ArduinoJson/Configuration.hpp

@@ -56,12 +56,6 @@
 #  endif
 #endif
 
-// Store floating-point values with float (0) or double (1)
-// https://arduinojson.org/v7/config/use_double/
-#ifndef ARDUINOJSON_USE_DOUBLE
-#  define ARDUINOJSON_USE_DOUBLE 1
-#endif
-
 // Pointer size: a heuristic to set sensible defaults
 #ifndef ARDUINOJSON_SIZEOF_POINTER
 #  if defined(__SIZEOF_POINTER__)
@@ -73,6 +67,16 @@
 #  endif
 #endif
 
+// Store floating-point values with float (0) or double (1)
+// https://arduinojson.org/v7/config/use_double/
+#ifndef ARDUINOJSON_USE_DOUBLE
+#  if ARDUINOJSON_SIZEOF_POINTER >= 4  // 32 & 64 bits systems
+#    define ARDUINOJSON_USE_DOUBLE 1
+#  else
+#    define ARDUINOJSON_USE_DOUBLE 0
+#  endif
+#endif
+
 // Store integral values with long (0) or long long (1)
 // https://arduinojson.org/v7/config/use_long_long/
 #ifndef ARDUINOJSON_USE_LONG_LONG