|
|
@ -31,6 +31,8 @@ char conv[8] = { 0 }; |
|
|
|
#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) |
|
|
|
|
|
|
|
// Convert a full-range unsigned 8bit int to a percentage
|
|
|
|
const char* ui8tostr4pctrj(const uint8_t i) { |
|
|
@ -166,7 +168,7 @@ const char* i16tostr4signrj(const int16_t i) { |
|
|
|
|
|
|
|
// Convert unsigned float to string with 1.23 format
|
|
|
|
const char* ftostr12ns(const float &f) { |
|
|
|
const long i = ((f < 0 ? -f : f) * 1000 + 5) / 10; |
|
|
|
const long i = UINTFLOAT(f, 2); |
|
|
|
conv[3] = DIGIMOD(i, 100); |
|
|
|
conv[4] = '.'; |
|
|
|
conv[5] = DIGIMOD(i, 10); |
|
|
@ -176,7 +178,7 @@ const char* ftostr12ns(const float &f) { |
|
|
|
|
|
|
|
// Convert unsigned float to string with 12.3 format
|
|
|
|
const char* ftostr31ns(const float &f) { |
|
|
|
const long i = ((f < 0 ? -f : f) * 100 + 5) / 10; |
|
|
|
const long i = UINTFLOAT(f, 1); |
|
|
|
conv[3] = DIGIMOD(i, 100); |
|
|
|
conv[4] = DIGIMOD(i, 10); |
|
|
|
conv[5] = '.'; |
|
|
@ -186,7 +188,7 @@ const char* ftostr31ns(const float &f) { |
|
|
|
|
|
|
|
// Convert unsigned float to string with 123.4 format
|
|
|
|
const char* ftostr41ns(const float &f) { |
|
|
|
const long i = ((f < 0 ? -f : f) * 100 + 5) / 10; |
|
|
|
const long i = UINTFLOAT(f, 1); |
|
|
|
conv[2] = DIGIMOD(i, 1000); |
|
|
|
conv[3] = DIGIMOD(i, 100); |
|
|
|
conv[4] = DIGIMOD(i, 10); |
|
|
@ -198,7 +200,7 @@ const char* ftostr41ns(const float &f) { |
|
|
|
// Convert signed float to fixed-length string with 12.34 / _2.34 / -2.34 or -23.45 / 123.45 format
|
|
|
|
const char* ftostr42_52(const float &f) { |
|
|
|
if (f <= -10 || f >= 100) return ftostr52(f); // -23.45 / 123.45
|
|
|
|
long i = (f * 1000 + (f < 0 ? -5: 5)) / 10; |
|
|
|
long i = INTFLOAT(f, 2); |
|
|
|
conv[2] = (f >= 0 && f < 10) ? ' ' : MINUSOR(i, DIGIMOD(i, 1000)); |
|
|
|
conv[3] = DIGIMOD(i, 100); |
|
|
|
conv[4] = '.'; |
|
|
@ -209,7 +211,7 @@ const char* ftostr42_52(const float &f) { |
|
|
|
|
|
|
|
// Convert signed float to fixed-length string with 023.45 / -23.45 format
|
|
|
|
const char* ftostr52(const float &f) { |
|
|
|
long i = (f * 1000 + (f < 0 ? -5: 5)) / 10; |
|
|
|
long i = INTFLOAT(f, 2); |
|
|
|
conv[1] = MINUSOR(i, DIGIMOD(i, 10000)); |
|
|
|
conv[2] = DIGIMOD(i, 1000); |
|
|
|
conv[3] = DIGIMOD(i, 100); |
|
|
@ -222,7 +224,7 @@ const char* ftostr52(const float &f) { |
|
|
|
// Convert signed float to fixed-length string with 12.345 / _2.345 / -2.345 or -23.45 / 123.45 format
|
|
|
|
const char* ftostr53_63(const float &f) { |
|
|
|
if (f <= -10 || f >= 100) return ftostr63(f); // -23.456 / 123.456
|
|
|
|
long i = (f * 10000 + (f < 0 ? -5: 5)) / 10; |
|
|
|
long i = INTFLOAT(f, 3); |
|
|
|
conv[1] = (f >= 0 && f < 10) ? ' ' : MINUSOR(i, DIGIMOD(i, 10000)); |
|
|
|
conv[2] = DIGIMOD(i, 1000); |
|
|
|
conv[3] = '.'; |
|
|
@ -234,7 +236,7 @@ const char* ftostr53_63(const float &f) { |
|
|
|
|
|
|
|
// Convert signed float to fixed-length string with 023.456 / -23.456 format
|
|
|
|
const char* ftostr63(const float &f) { |
|
|
|
long i = (f * 10000 + (f < 0 ? -5: 5)) / 10; |
|
|
|
long i = INTFLOAT(f, 3); |
|
|
|
conv[0] = MINUSOR(i, DIGIMOD(i, 100000)); |
|
|
|
conv[1] = DIGIMOD(i, 10000); |
|
|
|
conv[2] = DIGIMOD(i, 1000); |
|
|
@ -249,7 +251,7 @@ const char* ftostr63(const float &f) { |
|
|
|
|
|
|
|
// Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
|
|
|
|
const char* ftostr4sign(const float &f) { |
|
|
|
const int i = (f * 100 + (f < 0 ? -5: 5)) / 10; |
|
|
|
const int i = INTFLOAT(f, 1); |
|
|
|
if (!WITHIN(i, -99, 999)) return i16tostr4signrj((int)f); |
|
|
|
const bool neg = i < 0; |
|
|
|
const int ii = neg ? -i : i; |
|
|
@ -262,9 +264,20 @@ const char* ftostr63(const float &f) { |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
// Convert float to fixed-length string with +12.3 / -12.3 format
|
|
|
|
const char* ftostr31sign(const float &f) { |
|
|
|
int i = INTFLOAT(f, 1); |
|
|
|
conv[2] = MINUSOR(i, '+'); |
|
|
|
conv[3] = DIGIMOD(i, 100); |
|
|
|
conv[4] = DIGIMOD(i, 10); |
|
|
|
conv[5] = '.'; |
|
|
|
conv[6] = DIGIMOD(i, 1); |
|
|
|
return &conv[2]; |
|
|
|
} |
|
|
|
|
|
|
|
// Convert float to fixed-length string with +123.4 / -123.4 format
|
|
|
|
const char* ftostr41sign(const float &f) { |
|
|
|
int i = (f * 100 + (f < 0 ? -5: 5)) / 10; |
|
|
|
int i = INTFLOAT(f, 1); |
|
|
|
conv[1] = MINUSOR(i, '+'); |
|
|
|
conv[2] = DIGIMOD(i, 1000); |
|
|
|
conv[3] = DIGIMOD(i, 100); |
|
|
@ -276,7 +289,7 @@ const char* ftostr41sign(const float &f) { |
|
|
|
|
|
|
|
// Convert signed float to string (6 digit) with -1.234 / _0.000 / +1.234 format
|
|
|
|
const char* ftostr43sign(const float &f, char plus/*=' '*/) { |
|
|
|
long i = (f * 10000 + (f < 0 ? -5: 5)) / 10; |
|
|
|
long i = INTFLOAT(f, 3); |
|
|
|
conv[1] = i ? MINUSOR(i, plus) : ' '; |
|
|
|
conv[2] = DIGIMOD(i, 1000); |
|
|
|
conv[3] = '.'; |
|
|
@ -288,7 +301,7 @@ const char* ftostr43sign(const float &f, char plus/*=' '*/) { |
|
|
|
|
|
|
|
// Convert signed float to string (5 digit) with -1.2345 / _0.0000 / +1.2345 format
|
|
|
|
const char* ftostr54sign(const float &f, char plus/*=' '*/) { |
|
|
|
long i = (f * 100000 + (f < 0 ? -5: 5)) / 10; |
|
|
|
long i = INTFLOAT(f, 4); |
|
|
|
conv[0] = i ? MINUSOR(i, plus) : ' '; |
|
|
|
conv[1] = DIGIMOD(i, 10000); |
|
|
|
conv[2] = '.'; |
|
|
@ -301,13 +314,13 @@ const char* ftostr54sign(const float &f, char plus/*=' '*/) { |
|
|
|
|
|
|
|
// Convert unsigned float to rj string with 12345 format
|
|
|
|
const char* ftostr5rj(const float &f) { |
|
|
|
const long i = ((f < 0 ? -f : f) * 10 + 5) / 10; |
|
|
|
const long i = UINTFLOAT(f, 0); |
|
|
|
return ui16tostr5rj(i); |
|
|
|
} |
|
|
|
|
|
|
|
// Convert signed float to string with +1234.5 format
|
|
|
|
const char* ftostr51sign(const float &f) { |
|
|
|
long i = (f * 100 + (f < 0 ? -5: 5)) / 10; |
|
|
|
long i = INTFLOAT(f, 1); |
|
|
|
conv[0] = MINUSOR(i, '+'); |
|
|
|
conv[1] = DIGIMOD(i, 10000); |
|
|
|
conv[2] = DIGIMOD(i, 1000); |
|
|
@ -320,7 +333,7 @@ const char* ftostr51sign(const float &f) { |
|
|
|
|
|
|
|
// Convert signed float to string with +123.45 format
|
|
|
|
const char* ftostr52sign(const float &f) { |
|
|
|
long i = (f * 1000 + (f < 0 ? -5: 5)) / 10; |
|
|
|
long i = INTFLOAT(f, 2); |
|
|
|
conv[0] = MINUSOR(i, '+'); |
|
|
|
conv[1] = DIGIMOD(i, 10000); |
|
|
|
conv[2] = DIGIMOD(i, 1000); |
|
|
@ -333,7 +346,7 @@ const char* ftostr52sign(const float &f) { |
|
|
|
|
|
|
|
// Convert signed float to string with +12.345 format
|
|
|
|
const char* ftostr53sign(const float &f) { |
|
|
|
long i = (f * 10000 + (f < 0 ? -5: 5)) / 10; |
|
|
|
long i = INTFLOAT(f, 3); |
|
|
|
conv[0] = MINUSOR(i, '+'); |
|
|
|
conv[1] = DIGIMOD(i, 10000); |
|
|
|
conv[2] = DIGIMOD(i, 1000); |
|
|
@ -346,7 +359,7 @@ const char* ftostr53sign(const float &f) { |
|
|
|
|
|
|
|
// Convert unsigned float to string with ____4.5, __34.5, _234.5, 1234.5 format
|
|
|
|
const char* ftostr51rj(const float &f) { |
|
|
|
const long i = ((f < 0 ? -f : f) * 100 + 5) / 10; |
|
|
|
const long i = UINTFLOAT(f, 1); |
|
|
|
conv[0] = ' '; |
|
|
|
conv[1] = RJDIGIT(i, 10000); |
|
|
|
conv[2] = RJDIGIT(i, 1000); |
|
|
@ -359,7 +372,7 @@ const char* ftostr51rj(const float &f) { |
|
|
|
|
|
|
|
// Convert signed float to space-padded string with -_23.4_ format
|
|
|
|
const char* ftostr52sp(const float &f) { |
|
|
|
long i = (f * 1000 + (f < 0 ? -5: 5)) / 10; |
|
|
|
long i = INTFLOAT(f, 2); |
|
|
|
uint8_t dig; |
|
|
|
conv[0] = MINUSOR(i, ' '); |
|
|
|
conv[1] = RJDIGIT(i, 10000); |
|
|
|