Skip to content

Commit db1b6a0

Browse files
committed
use FLT_MAX_10_EXP and DBL_MAX_10_EXP instead of hardcoded values
1 parent 1a6a417 commit db1b6a0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cores/arduino/WString.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#include "WString.h"
23+
#include <float.h>
2324

2425
/*********************************************/
2526
/* Static Member Initialisation */
@@ -114,7 +115,7 @@ String::String(unsigned long value, unsigned char base)
114115

115116
String::String(float value, unsigned char decimalPlaces)
116117
{
117-
static size_t const FLOAT_BUF_SIZE = 38 + FLT_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */;
118+
static size_t const FLOAT_BUF_SIZE = FLT_MAX_10_EXP + FLT_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */;
118119
init();
119120
char buf[FLOAT_BUF_SIZE];
120121
decimalPlaces = decimalPlaces < FLT_MAX_DECIMAL_PLACES ? decimalPlaces : FLT_MAX_DECIMAL_PLACES;
@@ -123,7 +124,7 @@ String::String(float value, unsigned char decimalPlaces)
123124

124125
String::String(double value, unsigned char decimalPlaces)
125126
{
126-
static size_t const DOUBLE_BUF_SIZE = 38 + DBL_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */;
127+
static size_t const DOUBLE_BUF_SIZE = DBL_MAX_10_EXP + DBL_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */;
127128
init();
128129
char buf[DOUBLE_BUF_SIZE];
129130
decimalPlaces = decimalPlaces < DBL_MAX_DECIMAL_PLACES ? decimalPlaces : DBL_MAX_DECIMAL_PLACES;

0 commit comments

Comments
 (0)