Skip to content

Commit

Permalink
Least stack-usage self-contained ftostr32np()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thinkyhead committed Dec 23, 2014
1 parent e83ecec commit bdf2c94
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions Marlin/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,6 @@ char *ftostr12ns(const float &x)

// convert float to space-padded string with -_23.4_ format
char *ftostr32np(const float &x) {
<<<<<<< HEAD
long xx = abs(x * 100);
uint8_t dig;

Expand All @@ -1472,8 +1471,7 @@ char *ftostr32np(const float &x) {
dig = xx % 10;
if (dig) { // 2 decimal places
conv[5] = '0' + dig;
dig = (xx / 10) % 10;
conv[4] = '0' + dig;
conv[4] = '0' + (xx / 10) % 10;
conv[3] = '.';
}
else { // 1 or 0 decimal place
Expand All @@ -1489,18 +1487,6 @@ char *ftostr32np(const float &x) {
}
conv[6] = '\0';
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)
Expand Down

0 comments on commit bdf2c94

Please sign in to comment.