|
@@ -29,6 +29,8 @@ struct FloatTraits<T, 8 /*64bits*/> {
|
|
|
typedef int16_t exponent_type;
|
|
typedef int16_t exponent_type;
|
|
|
static const exponent_type exponent_max = 308;
|
|
static const exponent_type exponent_max = 308;
|
|
|
|
|
|
|
|
|
|
+ static const size_t binaryPowersOfTen = 9;
|
|
|
|
|
+
|
|
|
static pgm_ptr<T> positiveBinaryPowersOfTen() {
|
|
static pgm_ptr<T> positiveBinaryPowersOfTen() {
|
|
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY( //
|
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY( //
|
|
|
uint64_t, factors,
|
|
uint64_t, factors,
|
|
@@ -113,6 +115,8 @@ struct FloatTraits<T, 4 /*32bits*/> {
|
|
|
typedef int8_t exponent_type;
|
|
typedef int8_t exponent_type;
|
|
|
static const exponent_type exponent_max = 38;
|
|
static const exponent_type exponent_max = 38;
|
|
|
|
|
|
|
|
|
|
+ static const size_t binaryPowersOfTen = 6;
|
|
|
|
|
+
|
|
|
static pgm_ptr<T> positiveBinaryPowersOfTen() {
|
|
static pgm_ptr<T> positiveBinaryPowersOfTen() {
|
|
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(uint32_t, factors,
|
|
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(uint32_t, factors,
|
|
|
{
|
|
{
|
|
@@ -198,10 +202,14 @@ inline TFloat make_float(TFloat m, TExponent e) {
|
|
|
|
|
|
|
|
auto powersOfTen = e > 0 ? traits::positiveBinaryPowersOfTen()
|
|
auto powersOfTen = e > 0 ? traits::positiveBinaryPowersOfTen()
|
|
|
: traits::negativeBinaryPowersOfTen();
|
|
: traits::negativeBinaryPowersOfTen();
|
|
|
|
|
+ auto count = traits::binaryPowersOfTen;
|
|
|
|
|
+
|
|
|
if (e <= 0)
|
|
if (e <= 0)
|
|
|
e = TExponent(-e);
|
|
e = TExponent(-e);
|
|
|
|
|
|
|
|
for (uint8_t index = 0; e != 0; index++) {
|
|
for (uint8_t index = 0; e != 0; index++) {
|
|
|
|
|
+ if (index >= count)
|
|
|
|
|
+ return traits::nan();
|
|
|
if (e & 1)
|
|
if (e & 1)
|
|
|
m *= powersOfTen[index];
|
|
m *= powersOfTen[index];
|
|
|
e >>= 1;
|
|
e >>= 1;
|