1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-13 11:29:58 +03:00

removed some double promotions that sneaked in, as well as replaced fabs() with float-only fabsf() version. trashed doubles from _atof(). Considering trashing that whole function for KEIL builds.

git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@439 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
timecop@gmail.com 2013-10-13 16:19:46 +00:00
parent 30ded7ff04
commit ca7d7e32f6
3 changed files with 18 additions and 17 deletions

View file

@ -258,7 +258,7 @@ char *itoa(int i, char *a, int r)
static float _atof(const char *p) static float _atof(const char *p)
{ {
int frac = 0; int frac = 0;
double sign, value, scale; float sign, value, scale;
// Skip leading white space, if any. // Skip leading white space, if any.
while (white_space(*p) ) { while (white_space(*p) ) {
@ -266,9 +266,9 @@ static float _atof(const char *p)
} }
// Get sign, if any. // Get sign, if any.
sign = 1.0; sign = 1.0f;
if (*p == '-') { if (*p == '-') {
sign = -1.0; sign = -1.0f;
p += 1; p += 1;
} else if (*p == '+') { } else if (*p == '+') {
@ -276,26 +276,26 @@ static float _atof(const char *p)
} }
// Get digits before decimal point or exponent, if any. // Get digits before decimal point or exponent, if any.
value = 0.0; value = 0.0f;
while (valid_digit(*p)) { while (valid_digit(*p)) {
value = value * 10.0 + (*p - '0'); value = value * 10.0f + (*p - '0');
p += 1; p += 1;
} }
// Get digits after decimal point, if any. // Get digits after decimal point, if any.
if (*p == '.') { if (*p == '.') {
double pow10 = 10.0; float pow10 = 10.0f;
p += 1; p += 1;
while (valid_digit(*p)) { while (valid_digit(*p)) {
value += (*p - '0') / pow10; value += (*p - '0') / pow10;
pow10 *= 10.0; pow10 *= 10.0f;
p += 1; p += 1;
} }
} }
// Handle exponent, if any. // Handle exponent, if any.
scale = 1.0; scale = 1.0f;
if ((*p == 'e') || (*p == 'E')) { if ((*p == 'e') || (*p == 'E')) {
unsigned int expon; unsigned int expon;
p += 1; p += 1;
@ -316,12 +316,13 @@ static float _atof(const char *p)
expon = expon * 10 + (*p - '0'); expon = expon * 10 + (*p - '0');
p += 1; p += 1;
} }
if (expon > 308) expon = 308; if (expon > 308)
expon = 308;
// Calculate scaling factor. // Calculate scaling factor.
while (expon >= 50) { scale *= 1E50; expon -= 50; } // while (expon >= 50) { scale *= 1E50f; expon -= 50; }
while (expon >= 8) { scale *= 1E8; expon -= 8; } while (expon >= 8) { scale *= 1E8f; expon -= 8; }
while (expon > 0) { scale *= 10.0; expon -= 1; } while (expon > 0) { scale *= 10.0f; expon -= 1; }
} }
// Return signed and scaled floating point result. // Return signed and scaled floating point result.
@ -445,7 +446,7 @@ static void cliCMix(char *cmdline)
} }
cliPrint("Sanity check:\t"); cliPrint("Sanity check:\t");
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
cliPrint(fabs(mixsum[i]) > 0.01f ? "NG\t" : "OK\t"); cliPrint(fabsf(mixsum[i]) > 0.01f ? "NG\t" : "OK\t");
cliPrint("\r\n"); cliPrint("\r\n");
return; return;
} else if (strncasecmp(cmdline, "reset", 5) == 0) { } else if (strncasecmp(cmdline, "reset", 5) == 0) {

View file

@ -157,9 +157,9 @@ void hmc5883lInit(void)
LED1_TOGGLE; LED1_TOGGLE;
} }
magGain[X] = fabs(660.0f * HMC58X3_X_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[X]); magGain[X] = fabsf(660.0f * HMC58X3_X_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[X]);
magGain[Y] = fabs(660.0f * HMC58X3_Y_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[Y]); magGain[Y] = fabsf(660.0f * HMC58X3_Y_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[Y]);
magGain[Z] = fabs(660.0f * HMC58X3_Z_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[Z]); magGain[Z] = fabsf(660.0f * HMC58X3_Z_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[Z]);
// leave test mode // leave test mode
i2cWrite(MAG_ADDRESS, HMC58X3_R_CONFA, 0x70); // Configuration Register A -- 0 11 100 00 num samples: 8 ; output rate: 15Hz ; normal measurement mode i2cWrite(MAG_ADDRESS, HMC58X3_R_CONFA, 0x70); // Configuration Register A -- 0 11 100 00 num samples: 8 ; output rate: 15Hz ; normal measurement mode

View file

@ -350,7 +350,7 @@ int getEstimatedAltitude(void)
BaroAlt_tmp = 153.8462f * (baroTemperature + 27315) * (1.0f - expf(0.190259f * logf(PressureScaling))); // in cm BaroAlt_tmp = 153.8462f * (baroTemperature + 27315) * (1.0f - expf(0.190259f * logf(PressureScaling))); // in cm
BaroAlt = (float)BaroAlt * cfg.baro_noise_lpf + (float)BaroAlt_tmp * (1.0f - cfg.baro_noise_lpf); // additional LPF to reduce baro noise BaroAlt = (float)BaroAlt * cfg.baro_noise_lpf + (float)BaroAlt_tmp * (1.0f - cfg.baro_noise_lpf); // additional LPF to reduce baro noise
dt = accTimeSum * 1e-6; // delta acc reading time in seconds dt = accTimeSum * 1e-6f; // delta acc reading time in seconds
// Integrator - velocity, cm/sec // Integrator - velocity, cm/sec
vel_acc = (float)accSum[2] * accVelScale * (float)accTimeSum / (float)accSumCount; vel_acc = (float)accSum[2] * accVelScale * (float)accTimeSum / (float)accSumCount;