You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
String::String(float value, unsigned int decimalPlaces) {
init();
// The maximum number of predecimal digits for an IEEE 754
// single precision float is 39, plus space for a possible
// minus sign, a decimal point, and a null character.
// The number of postdecimal digits is given by the argument.
// The actual value that is placed in the string will be copied
// into newly-allocated memory by the assignment operator, then
// the temporary buffer can be safely freed.
char *buf = (char*)malloc(decimalPlaces + 42);
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
free(buf);
}
String::String(double value, unsigned int decimalPlaces) {
init();
// The maximum number of predecimal digits for an IEEE 754
// double precision float is 309, plus space for a possible
// minus sign, a decimal point, and a null character.
// The number of postdecimal digits is given by the argument.
// The actual value that is placed in the string will be copied
// into newly-allocated memory by the assignment operator, then
// the temporary buffer can be safely freed.
char *buf = (char*)malloc(decimalPlaces + 312);
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
}
String(1e-38, 40) // smallest normalized single
String(-3.4e38, 40) // largest single with extra precision digits
String(1e-45, 45) // smallest denormal single
String((double)4.94e-324, 327) // smallest denormal double
String((double)-1e308, 0) // Largest double
On Sun, 16 Jan 2022 at 14:18, Mitch Bradley ***@***.***> wrote:
And the output from those cases:
1e-38 0.0000000000000000000000000000000000000100
-3.4e38 -340000000000000079936057773011270910501.4801025390625000000000000000000000000000
1e-45 0.000000000000000000000000000000000000000000001
4.94e-324 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940
-1e308 -100000000000000022204460492503130808472633361816406250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
—
Reply to this email directly, view it on GitHub
<f3c7b49#commitcomment-63989476>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEDQSQZVASJVEKDPNTANR3UWM73TANCNFSM5MDHR5LQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you are subscribed to this thread.Message
ID:
<espressif/arduino-esp32/commit/f3c7b4980ded4d75af5536cb4cb9691444dbe0f4/63989476
@github.com>
8 commit comments
MitchBradley commentedon Jan 16, 2022
I have just finished testing a general solution:
MitchBradley commentedon Jan 16, 2022
It works with both very large and very small numbers, for example, given
String((double)4.94e-324, 327)
it displaysMitchBradley commentedon Jan 16, 2022
Sorry, there is supposed to be a free(buf) at the end of the double one.
MitchBradley commentedon Jan 16, 2022
I tried your version. It Stack Smashes with
String(1e308,0)
MitchBradley commentedon Jan 16, 2022
In addition to the malloc/free changes, in order to display very small numbers, my version needs to change the argument signature of dtostrf() to
and, inside dtostrf()
MitchBradley commentedon Jan 16, 2022
Here are my test cases:
MitchBradley commentedon Jan 16, 2022
And the output from those cases:
dpharris commentedon Jan 17, 2022