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

View File

@ -157,9 +157,9 @@ void hmc5883lInit(void)
LED1_TOGGLE;
}
magGain[X] = fabs(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[Z] = fabs(660.0f * HMC58X3_Z_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[Z]);
magGain[X] = fabsf(660.0f * HMC58X3_X_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[X]);
magGain[Y] = fabsf(660.0f * HMC58X3_Y_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[Y]);
magGain[Z] = fabsf(660.0f * HMC58X3_Z_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[Z]);
// 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

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 = (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
vel_acc = (float)accSum[2] * accVelScale * (float)accTimeSum / (float)accSumCount;