Skip to content

Commit cd584b1

Browse files
committed
[src] Fix warnings about double promotion
1 parent 3632f01 commit cd584b1

File tree

13 files changed

+50
-49
lines changed

13 files changed

+50
-49
lines changed

examples/nucleo_f042k6/tmp12x/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ main()
4444
while(true) {
4545
if (timer.execute()) {
4646
const modm::Tmp123Temperature temperature = RF_CALL_BLOCKING(sensor.read());
47-
MODM_LOG_INFO.printf("Temperature %2.2f\n", temperature.getTemperatureFloat());
47+
MODM_LOG_INFO.printf("Temperature %2.2f\n", (double)temperature.getTemperatureFloat());
4848
}
4949
}
5050
}

examples/nucleo_f303re/temperature_mcp990x/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int main()
5050
{
5151
if (RF_CALL_BLOCKING(sensor.readInternalTemperature()))
5252
{
53-
MODM_LOG_INFO.printf("temperature: %3.3f\n °C\n", data.getTemperature());
53+
MODM_LOG_INFO.printf("temperature: %3.3f\n °C\n", (double)data.getTemperature());
5454
}
5555
else
5656
{

examples/nucleo_g474re/adc_basic/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ main()
4242
MODM_LOG_INFO << "adcValue=" << adcValue;
4343
float voltage = adcValue * 3.3 / 0xfff;
4444
MODM_LOG_INFO << " voltage=";
45-
MODM_LOG_INFO.printf("%.3f\n", voltage);
45+
MODM_LOG_INFO.printf("%.3f\n", (double)voltage);
4646
modm::delay(500ms);
4747
}
4848

examples/nucleo_g474re/ads7828/main.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -47,110 +47,110 @@ class AdcThread : public modm::pt::Protothread
4747
MODM_LOG_INFO << "-------------------------------" << modm::endl << modm::endl;
4848
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0));
4949
PT_CALL(adc.readConversionResult());
50-
MODM_LOG_INFO.printf("Ch0 measuremnt is \t %.4f", data.getVoltage(3.3f));
50+
MODM_LOG_INFO.printf("Ch0 measuremnt is \t %.4f", (double)data.getVoltage(3.3f));
5151
MODM_LOG_INFO << modm::endl;
5252

5353
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch1));
5454
PT_CALL(adc.readConversionResult());
55-
MODM_LOG_INFO.printf("Ch1 measuremnt is \t %.4f", data.getVoltage(3.3f));
55+
MODM_LOG_INFO.printf("Ch1 measuremnt is \t %.4f", (double)data.getVoltage(3.3f));
5656
MODM_LOG_INFO << modm::endl;
5757

5858
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch2));
5959
PT_CALL(adc.readConversionResult());
60-
MODM_LOG_INFO.printf("Ch2 measuremnt is \t %.4f", data.getVoltage(3.3f));
60+
MODM_LOG_INFO.printf("Ch2 measuremnt is \t %.4f", (double)data.getVoltage(3.3f));
6161
MODM_LOG_INFO << modm::endl;
6262

6363
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch3));
6464
PT_CALL(adc.readConversionResult());
65-
MODM_LOG_INFO.printf("Ch3 measuremnt is \t %.4f", data.getVoltage(3.3f));
65+
MODM_LOG_INFO.printf("Ch3 measuremnt is \t %.4f", (double)data.getVoltage(3.3f));
6666
MODM_LOG_INFO << modm::endl;
6767

6868
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch4));
6969
PT_CALL(adc.readConversionResult());
70-
MODM_LOG_INFO.printf("Ch4 measuremnt is \t %.4f", data.getVoltage(3.3f));
70+
MODM_LOG_INFO.printf("Ch4 measuremnt is \t %.4f", (double)data.getVoltage(3.3f));
7171
MODM_LOG_INFO << modm::endl;
7272

7373
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch5));
7474
PT_CALL(adc.readConversionResult());
75-
MODM_LOG_INFO.printf("Ch5 measuremnt is \t %.4f", data.getVoltage(3.3f));
75+
MODM_LOG_INFO.printf("Ch5 measuremnt is \t %.4f", (double)data.getVoltage(3.3f));
7676
MODM_LOG_INFO << modm::endl;
7777

7878
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch6));
7979
PT_CALL(adc.readConversionResult());
80-
MODM_LOG_INFO.printf("Ch6 measuremnt is \t %.4f", data.getVoltage(3.3f));
80+
MODM_LOG_INFO.printf("Ch6 measuremnt is \t %.4f", (double)data.getVoltage(3.3f));
8181
MODM_LOG_INFO << modm::endl;
8282

8383
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch7));
8484
PT_CALL(adc.readConversionResult());
85-
MODM_LOG_INFO.printf("Ch7 measuremnt is \t %.4f", data.getVoltage(3.3f));
85+
MODM_LOG_INFO.printf("Ch7 measuremnt is \t %.4f", (double)data.getVoltage(3.3f));
8686
MODM_LOG_INFO << modm::endl;
8787

8888
MODM_LOG_INFO << "----Diff Inputs-------------" << modm::endl;
8989

9090
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0Ch1));
9191
PT_CALL(adc.readConversionResult());
92-
MODM_LOG_INFO.printf("Ch0 - Ch1 is \t %.4f", data.getVoltage(3.3f));
92+
MODM_LOG_INFO.printf("Ch0 - Ch1 is \t %.4f", (double)data.getVoltage(3.3f));
9393
MODM_LOG_INFO << modm::endl;
9494

9595
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch2Ch3));
9696
PT_CALL(adc.readConversionResult());
97-
MODM_LOG_INFO.printf("Ch2 - Ch3 is\t %.4f", data.getVoltage(3.3f));
97+
MODM_LOG_INFO.printf("Ch2 - Ch3 is\t %.4f", (double)data.getVoltage(3.3f));
9898
MODM_LOG_INFO << modm::endl;
9999

100100
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch4Ch5));
101101
PT_CALL(adc.readConversionResult());
102-
MODM_LOG_INFO.printf("Ch4 - Ch5 is \t %.4f", data.getVoltage(3.3f));
102+
MODM_LOG_INFO.printf("Ch4 - Ch5 is \t %.4f", (double)data.getVoltage(3.3f));
103103
MODM_LOG_INFO << modm::endl;
104104

105105
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch6Ch7));
106106
PT_CALL(adc.readConversionResult());
107-
MODM_LOG_INFO.printf("Ch6 - Ch7 is \t %.4f", data.getVoltage(3.3f));
107+
MODM_LOG_INFO.printf("Ch6 - Ch7 is \t %.4f", (double)data.getVoltage(3.3f));
108108
MODM_LOG_INFO << modm::endl;
109109

110110
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch1Ch0));
111111
PT_CALL(adc.readConversionResult());
112-
MODM_LOG_INFO.printf("Ch1 - Ch0 is \t %.4f", data.getVoltage(3.3f));
112+
MODM_LOG_INFO.printf("Ch1 - Ch0 is \t %.4f", (double)data.getVoltage(3.3f));
113113
MODM_LOG_INFO << modm::endl;
114114

115115
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch3Ch2));
116116
PT_CALL(adc.readConversionResult());
117-
MODM_LOG_INFO.printf("Ch3 - Ch2 is \t %.4f", data.getVoltage(3.3f));
117+
MODM_LOG_INFO.printf("Ch3 - Ch2 is \t %.4f", (double)data.getVoltage(3.3f));
118118
MODM_LOG_INFO << modm::endl;
119119

120120
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch5Ch4));
121121
PT_CALL(adc.readConversionResult());
122-
MODM_LOG_INFO.printf("Ch5 - Ch4 is \t %.4f", data.getVoltage(3.3f));
122+
MODM_LOG_INFO.printf("Ch5 - Ch4 is \t %.4f", (double)data.getVoltage(3.3f));
123123
MODM_LOG_INFO << modm::endl;
124124

125125
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch7Ch6));
126126
PT_CALL(adc.readConversionResult());
127-
MODM_LOG_INFO.printf("Ch7 - Ch6 is \t %.4f", data.getVoltage(3.3f));
127+
MODM_LOG_INFO.printf("Ch7 - Ch6 is \t %.4f", (double)data.getVoltage(3.3f));
128128
MODM_LOG_INFO << modm::endl;
129129

130130
MODM_LOG_INFO << "---Toggling Power Down and Internal Ref----" << modm::endl;
131131

132132
PT_CALL(adc.setPowerDownSelection(modm::ads7828::PowerDown::InternalReferenceOffAdcConverterOff));
133133
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0));
134134
PT_CALL(adc.readConversionResult());
135-
MODM_LOG_INFO.printf("Default: \t\t\t\t %.4f", data.getVoltage(3.3f));
135+
MODM_LOG_INFO.printf("Default: \t\t\t\t %.4f", (double)data.getVoltage(3.3f));
136136
MODM_LOG_INFO << modm::endl;
137137

138138
PT_CALL(adc.setPowerDownSelection(modm::ads7828::PowerDown::InternalReferenceOnAdcConverterOff));
139139
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0));
140140
PT_CALL(adc.readConversionResult());
141-
MODM_LOG_INFO.printf("Internal ref on: \t\t\t %.4f", data.getVoltage(2.5f));
141+
MODM_LOG_INFO.printf("Internal ref on: \t\t\t %.4f", (double)data.getVoltage(2.5f));
142142
MODM_LOG_INFO << modm::endl;
143143

144144
PT_CALL(adc.setPowerDownSelection(modm::ads7828::PowerDown::InternalReferenceOffAdcConverterOn));
145145
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0));
146146
PT_CALL(adc.readConversionResult());
147-
MODM_LOG_INFO.printf("No power down \t\t\t\t %.4f", data.getVoltage(3.3f));
147+
MODM_LOG_INFO.printf("No power down \t\t\t\t %.4f", (double)data.getVoltage(3.3f));
148148
MODM_LOG_INFO << modm::endl;
149149

150150
PT_CALL(adc.setPowerDownSelection(modm::ads7828::PowerDown::InternalReferenceOnAdcConverterOn));
151151
PT_CALL(adc.startMeasurement(modm::ads7828::InputChannel::Ch0));
152152
PT_CALL(adc.readConversionResult());
153-
MODM_LOG_INFO.printf("Internal ref on, no power down: \t %.4f", data.getVoltage(2.5f));
153+
MODM_LOG_INFO.printf("Internal ref on, no power down: \t %.4f", (double)data.getVoltage(2.5f));
154154
MODM_LOG_INFO << modm::endl;
155155

156156
MODM_LOG_INFO << "-------------------------------" << modm::endl << modm::endl;

examples/nucleo_g474re/imu_lsm6dso/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ main()
103103
}
104104

105105
// print data anyways
106-
MODM_LOG_INFO.printf("TEMP=%+2.1f degC, ", (static_cast<int16_t>(data[0] | data[1] << 8) / 256.f) + 25.f);
106+
MODM_LOG_INFO.printf("TEMP=%+2.1f degC, ", (double)((static_cast<int16_t>(data[0] | data[1] << 8) / 256.f) + 25.f));
107107
MODM_LOG_INFO.printf("G_X=%+05i, ", static_cast<int16_t>(data[ 2] | data[ 3] << 8));
108108
MODM_LOG_INFO.printf("G_Y=%+05i, ", static_cast<int16_t>(data[ 4] | data[ 5] << 8));
109109
MODM_LOG_INFO.printf("G_Z=%+05i, ", static_cast<int16_t>(data[ 6] | data[ 7] << 8));

examples/nucleo_g474re/timer_input_capture/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace Board;
2525
constexpr uint16_t input_capture_overflow = 0xFFFF;
2626
constexpr float input_capture_freq_hz = 3000.00; // Hz
2727
constexpr uint16_t input_capture_prescaler = SystemClock::Frequency / input_capture_freq_hz;
28-
constexpr float input_capture_ms_per_tick = ( 1.0 / input_capture_freq_hz ) * 1000.0;
28+
constexpr float input_capture_ms_per_tick = ( 1.0f / input_capture_freq_hz ) * 1000.0;
2929

3030
// PWM Generator Timer Configuration
3131
constexpr uint16_t pwm_gen_overflow = 0xFFFF;
@@ -36,7 +36,7 @@ constexpr float pwm_gen_pulse_width_ms = 1.5f; // Milliseconds
3636
// Desired PWM Freq = Clock Freq / Timer Prescaler / Overflow Value
3737
// Timer Prescaler = Clock Freq / (Desired PWM Freq * Overflow Value)
3838
constexpr uint16_t pwm_gen_prescaler = SystemClock::Frequency / ( pwm_gen_frequency_hz * pwm_gen_overflow );
39-
constexpr float pwm_gen_period_ms = ( 1.0 / pwm_gen_frequency_hz ) * 1000;
39+
constexpr float pwm_gen_period_ms = ( 1.0f / pwm_gen_frequency_hz ) * 1000;
4040
constexpr uint16_t pwm_gen_ticks_per_period = pwm_gen_overflow / pwm_gen_period_ms;
4141
constexpr uint16_t pwm_pulse_width_in_ticks = pwm_gen_ticks_per_period * pwm_gen_pulse_width_ms;
4242
// --------------------------------------------------------------------------
@@ -175,4 +175,4 @@ int main()
175175
}
176176

177177
return 0;
178-
}
178+
}

examples/nucleo_l552ze-q/adc_basic/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ main()
4444
MODM_LOG_INFO << "adcValue=" << adcValue;
4545
const float voltage = adcValue * 3.3 / 0xfff;
4646
MODM_LOG_INFO << " voltage=";
47-
MODM_LOG_INFO.printf("%.3f\n", voltage);
47+
MODM_LOG_INFO.printf("%.3f\n", (double)voltage);
4848
Board::Leds::toggle();
4949
modm::delay(500ms);
5050
}

examples/stm32f3_discovery/accelerometer/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ class ReaderThread : public modm::pt::Protothread
4242
averageY.update(accelerometer.getData().getY());
4343

4444
{
45-
bool xs = averageX.getValue() < -0.2;
46-
bool xn = averageX.getValue() > 0.2;
45+
bool xs = averageX.getValue() < -0.2f;
46+
bool xn = averageX.getValue() > 0.2f;
4747

48-
bool xe = averageY.getValue() < -0.2;
49-
bool xw = averageY.getValue() > 0.2;
48+
bool xe = averageY.getValue() < -0.2f;
49+
bool xw = averageY.getValue() > 0.2f;
5050

5151
Board::LedNorth::set(xn and not (xe or xw));
5252
Board::LedNorthEast::set(xn and xe);

examples/stm32f4_discovery/accelerometer/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ class ReaderThread : public modm::pt::Protothread
8787
averageY.update(accel.getData().getY());
8888
#endif
8989

90-
Board::LedOrange::set(averageX.getValue() < -0.2);
91-
Board::LedBlue::set(averageX.getValue() > 0.2);
92-
Board::LedGreen::set(averageY.getValue() < -0.2);
93-
Board::LedRed::set(averageY.getValue() > 0.2);
90+
Board::LedOrange::set(averageX.getValue() < -0.2f);
91+
Board::LedBlue::set(averageX.getValue() > 0.2f);
92+
Board::LedGreen::set(averageY.getValue() < -0.2f);
93+
Board::LedRed::set(averageY.getValue() > 0.2f);
9494

9595
timeout.restart(5ms);
9696
PT_WAIT_UNTIL(timeout.isExpired());

src/modm/math/geometry/angle.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ modm::Angle::normalize(float angle)
2222
{
2323
if (isPositive(angle))
2424
{
25-
while (angle > M_PI) {
26-
angle -= 2 * M_PI;
25+
while (angle > std::numbers::pi_v<float>) {
26+
angle -= 2 * std::numbers::pi_v<float>;
2727
}
2828
}
2929
else {
30-
while (angle < -M_PI) {
31-
angle += 2 * M_PI;
30+
while (angle < -std::numbers::pi_v<float>) {
31+
angle += 2 * std::numbers::pi_v<float>;
3232
}
3333
}
3434

@@ -41,10 +41,10 @@ modm::Angle::reverse(float angle)
4141
{
4242
if (isPositive(angle))
4343
{
44-
angle -= M_PI;
44+
angle -= std::numbers::pi_v<float>;
4545
}
4646
else {
47-
angle += M_PI;
47+
angle += std::numbers::pi_v<float>;
4848
}
4949

5050
return angle;
@@ -56,10 +56,10 @@ modm::Angle::perpendicular(float angle, const bool cw)
5656
{
5757
if (cw)
5858
{
59-
angle = modm::Angle::normalize(angle - M_PI_2);
59+
angle = modm::Angle::normalize(angle - std::numbers::pi_v<float>/2);
6060
}
6161
else {
62-
angle = modm::Angle::normalize(angle + M_PI_2);
62+
angle = modm::Angle::normalize(angle + std::numbers::pi_v<float>/2);
6363
}
6464

6565
return angle;

src/modm/math/geometry/angle.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <cmath>
2020
#include <math.h>
21+
#include <numbers>
2122

2223
// The circumference of a circle with diameter 1
2324
#ifndef M_PI
@@ -55,14 +56,14 @@ namespace modm
5556
static constexpr float
5657
toRadian(float angle)
5758
{
58-
return (angle * M_PI) / 180.f;
59+
return (angle * std::numbers::pi_v<float>) / 180.f;
5960
}
6061

6162
/// @ingroup modm_math_geometry
6263
static constexpr float
6364
toDegree(float angle)
6465
{
65-
return (angle * 180.f) / M_PI;
66+
return (angle * 180.f) / std::numbers::pi_v<float>;
6667
}
6768

6869
/**

src/modm/platform/can/common/can_bit_timings.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CanBitTiming
6363
static constexpr uint32_t round_uint32(float f)
6464
{
6565
uint32_t f_int = (uint32_t) f;
66-
if(f - f_int > 0.5)
66+
if(f - f_int > 0.5f)
6767
return f_int + 1;
6868
else
6969
return f_int;

src/modm/ui/color/brightness.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class BrightnessT
7575
*/
7676
template<std::unsigned_integral U>
7777
constexpr BrightnessT(RgbT<U> rgb)
78-
: value((0.2125 * float(rgb.red)) + (0.7154 * float(rgb.green)) +
79-
(0.0721 * float(rgb.blue)))
78+
: value((0.2125f * float(rgb.red)) + (0.7154f * float(rgb.green)) +
79+
(0.0721f * float(rgb.blue)))
8080
{}
8181

8282
/**

0 commit comments

Comments
 (0)