Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» numtostr use functions
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and Andy-Big committed Jul 15, 2023
1 parent d240386 commit e4ea414
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Marlin/src/libs/numtostr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,25 @@
#include "../inc/MarlinConfigPre.h"
#include "../core/utility.h"

char conv[9] = { 0 };
constexpr char DIGIT(const uint8_t n) { return '0' + n; }

template <typename T1, typename T2>
constexpr char DIGIMOD(const T1 n, const T2 f) { return DIGIT((n / f) % 10); }

template <typename T1, typename T2>
constexpr char RJDIGIT(const T1 n, const T2 f) { return (n >= f ? DIGIMOD(n, f) : ' '); }

template <typename T>
constexpr char MINUSOR(T &n, const char alt) { return (n >= 0) ? alt : (n = -n) ? '-' : '-'; }

#define DIGIT(n) ('0' + (n))
#define DIGIMOD(n, f) DIGIT(((n)/(f)) % 10)
#define RJDIGIT(n, f) ((n) >= (f) ? DIGIMOD(n, f) : ' ')
#define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-'))
#define INTFLOAT(V,N) (((V) * 10 * pow(10, N) + ((V) < 0 ? -5: 5)) / 10) // pow10?
#define UINTFLOAT(V,N) INTFLOAT((V) < 0 ? -(V) : (V), N)
constexpr long INTFLOAT(const float V, const int N) {
return long((V * 10.0f * pow(10.0f, N) + (V < 0.0f ? -5.0f : 5.0f)) / 10.0f);
}
constexpr long UINTFLOAT(const float V, const int N) {
return INTFLOAT(V < 0.0f ? -V : V, N);
}

char conv[9] = { 0 };

// Format uint8_t (0-100) as rj string with 123% / _12% / __1% format
const char* pcttostrpctrj(const uint8_t i) {
Expand Down

0 comments on commit e4ea414

Please sign in to comment.