Least stack-usage self-contained ftostr32np()
This is the optimal code for a self-contained formatter, although the original code is crafty in being smaller and simpler, and can be evaluated as using the original output as a scratch pad for state, making the final formatter more straightforward. While this code is longer, all code-paths are minimal.
This commit is contained in:
parent
d1f21d1189
commit
10e1b6ef8b
|
@ -1498,7 +1498,6 @@ char *ftostr12ns(const float &x)
|
||||||
|
|
||||||
// convert float to space-padded string with -_23.4_ format
|
// convert float to space-padded string with -_23.4_ format
|
||||||
char *ftostr32np(const float &x) {
|
char *ftostr32np(const float &x) {
|
||||||
<<<<<<< HEAD
|
|
||||||
long xx = abs(x * 100);
|
long xx = abs(x * 100);
|
||||||
uint8_t dig;
|
uint8_t dig;
|
||||||
|
|
||||||
|
@ -1525,8 +1524,7 @@ char *ftostr32np(const float &x) {
|
||||||
dig = xx % 10;
|
dig = xx % 10;
|
||||||
if (dig) { // 2 decimal places
|
if (dig) { // 2 decimal places
|
||||||
conv[5] = '0' + dig;
|
conv[5] = '0' + dig;
|
||||||
dig = (xx / 10) % 10;
|
conv[4] = '0' + (xx / 10) % 10;
|
||||||
conv[4] = '0' + dig;
|
|
||||||
conv[3] = '.';
|
conv[3] = '.';
|
||||||
}
|
}
|
||||||
else { // 1 or 0 decimal place
|
else { // 1 or 0 decimal place
|
||||||
|
@ -1542,18 +1540,6 @@ char *ftostr32np(const float &x) {
|
||||||
}
|
}
|
||||||
conv[6] = '\0';
|
conv[6] = '\0';
|
||||||
return conv;
|
return conv;
|
||||||
=======
|
|
||||||
char *c = ftostr32(x);
|
|
||||||
if (c[0] == '0' || c[0] == '-') {
|
|
||||||
if (c[0] == '0') c[0] = ' ';
|
|
||||||
if (c[1] == '0') c[1] = ' ';
|
|
||||||
}
|
|
||||||
if (c[5] == '0') {
|
|
||||||
c[5] = ' ';
|
|
||||||
if (c[4] == '0') c[4] = c[3] = ' ';
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
>>>>>>> Patch to make Z look more like X and Y on UltraLCD
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *itostr31(const int &xx)
|
char *itostr31(const int &xx)
|
||||||
|
|
Loading…
Reference in a new issue