mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2025-01-31 14:12:52 +00:00
🧑💻 numtostr use functions
This commit is contained in:
parent
bc385122e9
commit
32be4065ef
1 changed files with 18 additions and 7 deletions
|
@ -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; }
|
||||
|
||||
#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)
|
||||
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) ? '-' : '-'; }
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue