File tree 2 files changed +9
-2
lines changed
2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 23
23
#include " itoa.h"
24
24
#include " deprecated-avr-comp/avr/dtostrf.h"
25
25
26
+ #include < float.h>
27
+
26
28
/* ********************************************/
27
29
/* Constructors */
28
30
/* ********************************************/
@@ -111,15 +113,17 @@ String::String(unsigned long value, unsigned char base)
111
113
112
114
String::String (float value, unsigned char decimalPlaces)
113
115
{
116
+ static size_t const FLOAT_BUF_SIZE = FLT_MAX_10_EXP + FLT_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */ ;
114
117
init ();
115
- char buf[33 ];
118
+ char buf[FLOAT_BUF_SIZE ];
116
119
*this = dtostrf (value, (decimalPlaces + 2 ), decimalPlaces, buf);
117
120
}
118
121
119
122
String::String (double value, unsigned char decimalPlaces)
120
123
{
124
+ static size_t const DOUBLE_BUF_SIZE = DBL_MAX_10_EXP + DBL_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */ ;
121
125
init ();
122
- char buf[33 ];
126
+ char buf[DOUBLE_BUF_SIZE ];
123
127
*this = dtostrf (value, (decimalPlaces + 2 ), decimalPlaces, buf);
124
128
}
125
129
Original file line number Diff line number Diff line change @@ -58,6 +58,9 @@ class String
58
58
typedef void (String::*StringIfHelperType)() const ;
59
59
void StringIfHelper () const {}
60
60
61
+ static size_t const FLT_MAX_DECIMAL_PLACES = 10 ;
62
+ static size_t const DBL_MAX_DECIMAL_PLACES = FLT_MAX_DECIMAL_PLACES;
63
+
61
64
public:
62
65
// constructors
63
66
// creates a copy of the initial value.
You can’t perform that action at this time.
0 commit comments