Closed danieltr3s closed 3 years ago
+1 for this fix
Was this tested by anyone?
Was this tested by anyone?
I tried it with small hack in Marlin 2.0.7.2 firmware. builds fine, in places where it was broken, now seems to print floats ok.
Is there a simple skecth wich shows the problem and the solution?
If it can help, it is used since a while in STM32 core. Note that is is also used by String class: https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/59227d1ecab7e931a390119c20655f1c4147a668/STM32F1/cores/maple/WString.cpp#L114
You can use this sketch to test:
void setup() {
bool validate = true;
char sout[256] = "";
Serial.begin(9600);
while (!Serial);
Serial.println(dtostrf(1.23, 7, 2, sout));
if (strcmp(sout, " 1.23") != 0) {
validate = false;
}
Serial.println(dtostrf(1.899, 2, 2, sout));
if (strcmp(sout, "1.90") != 0) {
validate = false;
}
Serial.println(dtostrf(-123456.78910, 127, 6, sout));
if (strcmp(sout,
" -123456.789100"
) != 0) {
validate = false;
}
Serial.println(dtostrf(-123456.78910, 128, 6, sout));
if (strcmp(sout,
"-123456.789100 "
) != 0) {
validate = false;
}
if (validate) {
Serial.println("SUCCESS");
} else {
Serial.println("FAILED");
}
}
void loop() {
}
I have tested it and it seems to work, so I will merge this.
this also solves #620.
Fix suggested by @HamidSaffari in issue https://github.com/rogerclarkmelbourne/Arduino_STM32/issues/620 .