Skip to content

Commit

Permalink
removed some double promotions that sneaked in, as well as replaced f…
Browse files Browse the repository at this point in the history
…abs() 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
  • Loading branch information
timecop@gmail.com committed Oct 13, 2013
1 parent 30ded7f commit ca7d7e3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
27 changes: 14 additions & 13 deletions src/cli.c
Expand Up @@ -258,44 +258,44 @@ 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) ) {
p += 1;
}

// Get sign, if any.
sign = 1.0;
sign = 1.0f;
if (*p == '-') {
sign = -1.0;
sign = -1.0f;
p += 1;

} else if (*p == '+') {
p += 1;
}

// 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;
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/drv_hmc5883l.c
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/imu.c
Expand Up @@ -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;
Expand Down

0 comments on commit ca7d7e3

Please sign in to comment.