8000 Keep only one implementation of `make_float()` · smartcoder00/ArduinoJson@319ecec · GitHub
[go: up one dir, main page]

Skip to content

Commit 319ecec

Browse files
committed
Keep only one implementation of make_float()
1 parent 886254c commit 319ecec

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

src/ArduinoJson/Numbers/FloatTraits.hpp

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@ struct FloatTraits<T, 8 /*64bits*/> {
2929
typedef int16_t exponent_type;
3030
static const exponent_type exponent_max = 308;
3131

32-
template <typename TExponent>
33-
static T make_float(T m, TExponent e) {
34-
auto powersOfTen =
35-
e > 0 ? positiveBinaryPowersOfTen() : negativeBinaryPowersOfTen();
36-
if (e <= 0)
37-
e = TExponent(-e);
38-
39-
for (uint8_t index = 0; e != 0; index++) {
40-
if (e & 1)
41-
m *= powersOfTen[index];
42-
e >>= 1;
43-
}
44-
return m;
45-
}
46-
4732
static pgm_ptr<T> positiveBinaryPowersOfTen() {
4833
ARDUINOJSON_DEFINE_PROGMEM_ARRAY( //
4934
uint64_t, factors,
@@ -145,21 +130,6 @@ struct FloatTraits<T, 4 /*32bits*/> {
145130
typedef int8_t exponent_type;
146131
static const exponent_type exponent_max = 38;
147132

148-
template <typename TExponent>
149-
static T make_float(T m, TExponent e) {
150-
auto powersOfTen =
151-
e > 0 ? positiveBinaryPowersOfTen() : negativeBinaryPowersOfTen();
152-
if (e <= 0)
153-
e = TExponent(-e);
154-
155-
for (uint8_t index = 0; e != 0; index++) {
156-
if (e & 1)
157-
m *= powersOfTen[index];
158-
e >>= 1;
159-
}
160-
return m;
161-
}
162-
163133
static pgm_ptr<T> positiveBinaryPowersOfTen() {
164134
ARDUINOJSON_DEFINE_PROGMEM_ARRAY(uint32_t, factors,
165135
{
@@ -252,4 +222,21 @@ struct FloatTraits<T, 4 /*32bits*/> {
252222
}
253223
};
254224

225+
template <typename TFloat, typename TExponent>
226+
inline TFloat make_float(TFloat m, TExponent e) {
227+
using traits = FloatTraits<TFloat>;
228+
229+
auto powersOfTen = e > 0 ? traits::positiveBinaryPowersOfTen()
230+
: traits::negativeBinaryPowersOfTen();
231+
if (e <= 0)
232+
e = TExponent(-e);
233+
234+
for (uint8_t index = 0; e != 0; index++) {
235+
if (e & 1)
236+
m *= powersOfTen[index];
237+
e >>= 1;
238+
}
239+
return m;
240+
}
241+
255242
ARDUINOJSON_END_PRIVATE_NAMESPACE

src/ArduinoJson/Numbers/parseNumber.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ inline bool parseNumber(const char* s, VariantData& result) {
137137
return false;
138138

139139
JsonFloat final_result =
140-
traits::make_float(static_cast<JsonFloat>(mantissa), exponent);
140+
make_float(static_cast<JsonFloat>(mantissa), exponent);
141141

142142
result.setFloat(is_negative ? -final_result : final_result);
143143
return true;

0 commit comments

Comments
 (0)
0