From 1e30d1da47f24190a4e0ceed3631fff529f171af Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 5 Dec 2016 08:25:09 -0600 Subject: [PATCH] Simplify itostr4sign - This function becomes obsolete if ftostr4sign is re-written. --- Marlin/utility.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Marlin/utility.cpp b/Marlin/utility.cpp index bc68967e9..8f06817c0 100644 --- a/Marlin/utility.cpp +++ b/Marlin/utility.cpp @@ -74,25 +74,32 @@ void safe_delay(millis_t ms) { return str; } - // Convert signed int to rj string with _123, -123, _-12, or __-1 format + // Convert signed int to rj string with 1234, _123, -123, _-12, or __-1 format char *itostr4sign(const int& x) { - int xx = abs(x), sign = 0; - if (xx >= 100) { + int xx = abs(x); + if (x >= 1000) { + conv[0] = DIGIMOD(xx, 1000); conv[1] = DIGIMOD(xx, 100); conv[2] = DIGIMOD(xx, 10); } else { - conv[0] = ' '; - if (xx >= 10) { - sign = 1; + if (xx >= 100) { + conv[0] = x < 0 ? '-' : ' '; + conv[1] = DIGIMOD(xx, 100); conv[2] = DIGIMOD(xx, 10); } else { - conv[1] = ' '; - sign = 2; + conv[0] = ' '; + if (xx >= 10) { + conv[1] = x < 0 ? '-' : ' '; + conv[2] = DIGIMOD(xx, 10); + } + else { + conv[1] = ' '; + conv[2] = x < 0 ? '-' : ' '; + } } } - conv[sign] = x < 0 ? '-' : ' '; conv[3] = DIGIMOD(xx, 1); conv[4] = '\0'; return conv;