-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Increase buffer size for converting floats + doubles to String's #5369
base: master
Are you sure you want to change the base?
Conversation
@@ -108,14 +110,14 @@ String::String(unsigned long value, unsigned char base) | |||
String::String(float value, unsigned char decimalPlaces) | |||
{ | |||
init(); | |||
char buf[33]; | |||
char buf[FLT_MAX_10_EXP + 4 + decimalPlaces]; // +4, one for: 10, -, ., \0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean with "10" there? I can understand how -, . and \0 are added to the number of digits that FLT_MAX_10_EXP represents, but not what 10 means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 as in ascii 10, being a LineFeed perhaps ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On AVR DBL_MAX_10_EXP
is 38
and Serial.println(String(-DBL_MAX));
prints out -340282350000000000000000000000000000000.00
.
Which is 43
characters in length, then you need an extra byte for the \0
, which brings us to 44
.
44 - 38 - 2 = 4
. Maybe, I was thinking the extra character was for the 1's
digit ...
Partially moved to arduino/ArduinoCore-sam#32 |
❌ Build failed. |
|
Port of arduino/ArduinoCore-samd#163
Troublesome sketch: