Skip to content

Commit

Permalink
Ensure float literals and float versions of math functions are used.
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-carlos committed Nov 26, 2024
1 parent c43b899 commit 17016e2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions source/driver-models/Accelerometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ int Accelerometer::getZ()
*/
int Accelerometer::getPitch()
{
return (int) ((360*getPitchRadians()) / (2*PI));
return (int) ((360.0f*getPitchRadians()) / (2.0f*(float)PI));
}

/**
Expand Down Expand Up @@ -458,7 +458,7 @@ float Accelerometer::getPitchRadians()
*/
int Accelerometer::getRoll()
{
return (int) ((360*getRollRadians()) / (2*PI));
return (int) ((360.0f*getRollRadians()) / (2.0f*(float)PI));
}

/**
Expand Down
16 changes: 8 additions & 8 deletions source/driver-models/Compass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,16 @@ int Compass::tiltCompensatedBearing()
float z = (float) s.z;

// Precompute cos and sin of pitch and roll angles to make the calculation a little more efficient.
float sinPhi = sin(phi);
float cosPhi = cos(phi);
float sinTheta = sin(theta);
float cosTheta = cos(theta);
float sinPhi = sinf(phi);
float cosPhi = cosf(phi);
float sinTheta = sinf(theta);
float cosTheta = cosf(theta);

// Calculate the tilt compensated bearing, and convert to degrees.
float bearing = (360*atan2(x*cosTheta + y*sinTheta*sinPhi + z*sinTheta*cosPhi, z*sinPhi - y*cosPhi)) / (2*PI);
float bearing = (360.0f*atan2f(x*cosTheta + y*sinTheta*sinPhi + z*sinTheta*cosPhi, z*sinPhi - y*cosPhi)) / (20.f*(float)PI);

// Handle the 90 degree offset caused by the NORTH_EAST_DOWN based calculation.
bearing = 90 - bearing;
bearing = 90.0f - bearing;

// Ensure the calculated bearing is in the 0..359 degree range.
if (bearing < 0)
Expand All @@ -399,10 +399,10 @@ int Compass::basicBearing()
float x = (float) cs.x;
float y = (float) cs.y;

float bearing = (atan2(x,y))*180/PI;
float bearing = (atan2f(x,y))*180.0f/(float)PI;

if (bearing < 0)
bearing += 360.0;
bearing += 360.0f;

return (int)bearing;
}
Expand Down
4 changes: 2 additions & 2 deletions source/streams/LevelDetectorSPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ int LevelDetectorSPL::pullRequest()
sumSquares += v * v;
ptr += skip;
}
float rms = sqrt(sumSquares / count);
float rms = sqrtf(sumSquares / count);

/*******************************
* CALCULATE SPL
******************************/
float conv = ((float) maxVal * multiplier) / ((1 << 15) - 1) * gain;
conv = 20 * log10(conv / pref);
conv = 20.0f * log10f(conv / pref);

if (conv < minValue)
level = minValue;
Expand Down
2 changes: 1 addition & 1 deletion source/streams/StreamNormalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ ManagedBuffer StreamNormalizer::pull()
{
float calculatedZeroOffset = (float)z / (float)samples;

zeroOffset = zeroOffsetValid ? zeroOffset*0.5 + calculatedZeroOffset*0.5 : calculatedZeroOffset;
zeroOffset = zeroOffsetValid ? zeroOffset*0.5f + calculatedZeroOffset*0.5f : calculatedZeroOffset;
zeroOffsetValid = true;

if (stabilisation == 0 || abs((int)zeroOffset - zo) < stabilisation)
Expand Down
2 changes: 1 addition & 1 deletion source/streams/Synthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int Synthesizer::setFrequency(float frequency, int period, int envelopeStart, in
return DEVICE_BUSY;

// record our new intended frequency.
newPeriodNs = frequency == 0.0 ? 0 : (uint32_t) (1000000000.0f / frequency);
newPeriodNs = frequency == 0.0f ? 0 : (uint32_t) (1000000000.0f / frequency);

if (period == 0)
{
Expand Down

0 comments on commit 17016e2

Please sign in to comment.