47 -36, -33, -31, -29, -26, -24, -21, -19,
48 -17, -14, -12, -9, -7, -4, -2, 0,
49 3, 5, 8, 10, 12, 15, 17, 20,
50 22, 24, 27, 29, 32, 34, 36, 39
88 int16_t
ftoa_engine(
float val,
char *buf, uint8_t precision, uint8_t maxDecimals)
93 uint8_t *valbits = (uint8_t*)&val;
99 uint32_t frac =
x.u & 0x007fffffUL;
101 if (precision>7) precision=7;
104 if (valbits[3] & (1<<7)) flags =
FTOA_MINUS;
else flags = 0;
105 uint8_t exp = valbits[3]<<1;
106 if(valbits[2] & (1<<7)) exp++;
109 if(exp==0 && frac==0) {
112 for(i=0; i<=precision; i++) {
123 if (exp != 0) frac |= (1UL<<23);
125 uint8_t idx = exp>>3;
131 int64_t prod = (int64_t)frac * (int64_t)
factorTable[idx];
139 prod >>= (15-(exp & 7));
142 uint8_t hadNonzeroDigit = 0;
143 uint8_t outputIdx = 0;
144 int64_t decimal = 100000000000000ull;
149 while ((prod -= decimal) >= 0)
159 if (hadNonzeroDigit)
break;
171 if(maxDecimals != 0) {
172 int8_t beforeDP = exp10+1;
173 if (beforeDP < 1) beforeDP = 1;
181 maxDecimals = maxDecimals+beforeDP-1;
182 if (precision > maxDecimals)
183 precision = maxDecimals;
195 buf[outputIdx] = digit;
199 for(hadNonzeroDigit=outputIdx; hadNonzeroDigit>0; hadNonzeroDigit--)
200 buf[hadNonzeroDigit] =
'9';
203 }
while (outputIdx<precision);
208 if (prod - (decimal >> 1) >= 0) {
212 while(outputIdx != 0) {
213 if(++buf[outputIdx] ==
'0' + 10) {
215 buf[outputIdx] =
'1';
220 buf[outputIdx--] =
'0';
int16_t ftoa_engine(float val, char *buf, uint8_t precision, uint8_t maxDecimals)
static const uint32_t factorTable[32]
Common definitions and utility routines for the ArduPilot libraries.
static const int8_t exponentTable[32]