Skip to content

Commit

Permalink
Fix: floating point literals must use the f suffix when working with …
Browse files Browse the repository at this point in the history
…float variables
  • Loading branch information
obones committed Jan 9, 2023
1 parent b605a3d commit 9d2a59a
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/devices/acurite.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ static int acurite_5n1_decode(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t
int wind_speed_raw = ((bb[3] & 0x1F) << 3)| ((bb[4] & 0x70) >> 4);
float wind_speed_kph = 0;
if (wind_speed_raw > 0) {
wind_speed_kph = wind_speed_raw * 0.8278 + 1.0;
wind_speed_kph = wind_speed_raw * 0.8278f + 1.0f;
}

if (message_type == ACURITE_MSGTYPE_5N1_WINDSPEED_WINDDIR_RAINFALL) {
Expand Down Expand Up @@ -857,7 +857,7 @@ static int acurite_atlas_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsig
if ((bb[4] & 0x30) != 0)
exception++;

tempf = (temp_raw - 400) * 0.1;
tempf = (temp_raw - 400) * 0.1f;
if (tempf > 158.0) {
decoder_logf(decoder, 1, __func__, "Atlas 0x%04X Ch %s, invalid temperature: %0.1f F",
sensor_id, channel_str, tempf);
Expand Down
2 changes: 1 addition & 1 deletion src/devices/blueline.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ static int blueline_decode(r_device *decoder, bitbuffer_t *bitbuffer)
const uint8_t temperature = offset_payload_u8[1];
const uint8_t flags = offset_payload_u8[0] >> 2;
const uint8_t battery = (flags & 0x20) >> 5;
const float temperature_C = (0.436 * temperature) - 30.36;
const float temperature_C = (0.436f * temperature) - 30.36f;
/* clang-format off */
data = data_make(
"model", "", DATA_STRING, "Blueline-PowerCost",
Expand Down
2 changes: 1 addition & 1 deletion src/devices/bresser_5in1.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static int bresser_5in1_decode(r_device *decoder, bitbuffer_t *bitbuffer)
/* check if the message is from a Bresser Professional Rain Gauge */
if ((msg[15] & 0xF) == 0x9) {
// rescale the rain sensor readings
rain = rain * 2.5;
rain = rain * 2.5f;
/* clang-format off */
data = data_make(
"model", "", DATA_STRING, "Bresser-ProRainGauge",
Expand Down
4 changes: 2 additions & 2 deletions src/devices/danfoss.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ static int danfoss_cfr_callback(r_device *decoder, bitbuffer_t *bitbuffer)
default: str_sw = "ERROR";
}

float temp_meas = (float)bytes[5] + (float)bytes[4] / 256.0;
float temp_setp = (float)bytes[7] + (float)bytes[6] / 256.0;
float temp_meas = (float)bytes[5] + (float)bytes[4] / 256.0f;
float temp_setp = (float)bytes[7] + (float)bytes[6] / 256.0f;

/* clang-format off */
data = data_make(
Expand Down
2 changes: 1 addition & 1 deletion src/devices/efergy_optical.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static int efergy_optical_callback(r_device *decoder, bitbuffer_t *bitbuffer)
// - red led (every 30s): bytes[3]=64 (0100 0000)
// - orange led (every 60s): bytes[3]=80 (0101 0000)
// - green led (every 90s): bytes[3]=96 (0110 0000)
seconds = (((bytes[3] & 0x30) >> 4) + 1) * 30.0;
seconds = (((bytes[3] & 0x30) >> 4) + 1) * 30.0f;

pulsecount = bytes[8];

Expand Down
2 changes: 1 addition & 1 deletion src/devices/emontx.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static int emontx_callback(r_device *decoder, bitbuffer_t *bitbuffer)
if (crc != words[13])
continue; // DECODE_FAIL_MIC

vrms = (float)words[4] / 100.0;
vrms = (float)words[4] / 100.0f;

/* clang-format off */
data = data_make(
Expand Down
8 changes: 4 additions & 4 deletions src/devices/oregon_scientific.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static unsigned short int cm180i_power(uint8_t const *msg, unsigned int offset)
val = (msg[4+offset*2] << 8) | (msg[3+offset*2] & 0xF0);
// tested across situations varying from 700 watt to more than 8000 watt to
// get same value as showed in physical CM180 panel (exactly equals to 1+1/160)
val *= 1.00625;
val *= 1.00625f;
return val;
}

Expand All @@ -146,7 +146,7 @@ static unsigned short int cm180_power(uint8_t const *msg)
val = (msg[4] << 8) | (msg[3] & 0xF0);
// tested across situations varying from 700 watt to more than 8000 watt to
// get same value as showed in physical CM180 panel (exactly equals to 1+1/160)
val *= 1.00625;
val *= 1.00625f;
return val;
}

Expand Down Expand Up @@ -767,7 +767,7 @@ static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer

unsigned short int ipower = cm180_power(msg);
unsigned long long itotal = cm180_total(msg);
float total_energy = itotal / 3600.0 / 1000.0;
float total_energy = itotal / 3600.0f / 1000.0f;
if (valid == 0) {
/* clang-format off */
data = data_make(
Expand Down Expand Up @@ -804,7 +804,7 @@ static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer
if (msg_len >= 140) itotal= cm180i_total(msg);

// per hour and in kilowat
float total_energy = itotal / 3600.0 / 1000.0;
float total_energy = itotal / 3600.0f / 1000.0f;

if (valid == 0) {
/* clang-format off */
Expand Down
2 changes: 1 addition & 1 deletion src/pulse_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pulse_detect_t *pulse_detect_create(void)
return NULL;
}

pulse_detect_set_levels(pulse_detect, 0, 0.0, -12.1442, 9.0, 0);
pulse_detect_set_levels(pulse_detect, 0, 0.0f, -12.1442f, 9.0f, 0);

return pulse_detect;
}
Expand Down
32 changes: 16 additions & 16 deletions src/pulse_slicer.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static int account_event(r_device *device, bitbuffer_t *bits, char const *demod_

int pulse_slicer_pcm(const pulse_data_t *pulses, r_device *device)
{
float samples_per_us = pulses->sample_rate / 1.0e6;
float samples_per_us = pulses->sample_rate / 1.0e6f;
int s_short = device->short_width * samples_per_us;
int s_long = device->long_width * samples_per_us;
int s_reset = device->reset_limit * samples_per_us;
Expand All @@ -83,8 +83,8 @@ int pulse_slicer_pcm(const pulse_data_t *pulses, r_device *device)
}

// precision reciprocals
float f_short = device->short_width > 0.0 ? 1.0 / (device->short_width * samples_per_us) : 0;
float f_long = device->long_width > 0.0 ? 1.0 / (device->long_width * samples_per_us) : 0;
float f_short = device->short_width > 0.0f ? 1.0f / (device->short_width * samples_per_us) : 0;
float f_long = device->long_width > 0.0f ? 1.0f / (device->long_width * samples_per_us) : 0;

int events = 0;
bitbuffer_t bits = {0};
Expand Down Expand Up @@ -119,7 +119,7 @@ int pulse_slicer_pcm(const pulse_data_t *pulses, r_device *device)
min_count = count;
preamble_len = count;
if (device->verbose > 1) {
float to_us = 1e6 / pulses->sample_rate;
float to_us = 1e6f / pulses->sample_rate;
print_logf(LOG_INFO, __func__, "Exact bit width (in us) is %.2f vs %.2f (pulse width %.2f vs %.2f), %d bit preamble",
to_us / f_long, to_us * s_long,
to_us / f_short, to_us * s_short, count);
Expand Down Expand Up @@ -168,7 +168,7 @@ int pulse_slicer_pcm(const pulse_data_t *pulses, r_device *device)
min_count = count;
preamble_len = count;
if (device->verbose > 1) {
float to_us = 1e6 / pulses->sample_rate;
float to_us = 1e6f / pulses->sample_rate;
print_logf(LOG_INFO, __func__, "Exact bit width (in us) is %.2f vs %.2f, %d bit preamble",
to_us / f_short, to_us * s_short, count);
}
Expand Down Expand Up @@ -211,10 +211,10 @@ int pulse_slicer_pcm(const pulse_data_t *pulses, r_device *device)

for (unsigned n = 0; n < pulses->num_pulses; ++n) {
// Determine number of high bit periods for NRZ coding, where bits may not be separated
int highs = (pulses->pulse[n]) * f_short + 0.5;
int highs = (pulses->pulse[n]) * f_short + 0.5f;
// Determine number of low bit periods in current gap length (rounded)
// for RZ subtract the nominal bit-gap
int lows = (pulses->gap[n] + s_short - s_long) * f_long + 0.5;
int lows = (pulses->gap[n] + s_short - s_long) * f_long + 0.5f;

// Add run of ones (1 for RZ, many for NRZ)
for (int i = 0; i < highs; ++i) {
Expand Down Expand Up @@ -257,7 +257,7 @@ int pulse_slicer_pcm(const pulse_data_t *pulses, r_device *device)

int pulse_slicer_ppm(const pulse_data_t *pulses, r_device *device)
{
float samples_per_us = pulses->sample_rate / 1.0e6;
float samples_per_us = pulses->sample_rate / 1.0e6f;

int s_short = device->short_width * samples_per_us;
int s_long = device->long_width * samples_per_us;
Expand Down Expand Up @@ -336,7 +336,7 @@ int pulse_slicer_ppm(const pulse_data_t *pulses, r_device *device)

int pulse_slicer_pwm(const pulse_data_t *pulses, r_device *device)
{
float samples_per_us = pulses->sample_rate / 1.0e6;
float samples_per_us = pulses->sample_rate / 1.0e6f;

int s_short = device->short_width * samples_per_us;
int s_long = device->long_width * samples_per_us;
Expand Down Expand Up @@ -449,7 +449,7 @@ int pulse_slicer_pwm(const pulse_data_t *pulses, r_device *device)

int pulse_slicer_manchester_zerobit(const pulse_data_t *pulses, r_device *device)
{
float samples_per_us = pulses->sample_rate / 1.0e6;
float samples_per_us = pulses->sample_rate / 1.0e6f;

int s_short = device->short_width * samples_per_us;
int s_long = device->long_width * samples_per_us;
Expand Down Expand Up @@ -536,7 +536,7 @@ static inline int pulse_slicer_get_symbol(const pulse_data_t *pulses, unsigned i

int pulse_slicer_dmc(const pulse_data_t *pulses, r_device *device)
{
float samples_per_us = pulses->sample_rate / 1.0e6;
float samples_per_us = pulses->sample_rate / 1.0e6f;

int s_short = device->short_width * samples_per_us;
int s_long = device->long_width * samples_per_us;
Expand Down Expand Up @@ -596,7 +596,7 @@ int pulse_slicer_dmc(const pulse_data_t *pulses, r_device *device)

int pulse_slicer_piwm_raw(const pulse_data_t *pulses, r_device *device)
{
float samples_per_us = pulses->sample_rate / 1.0e6;
float samples_per_us = pulses->sample_rate / 1.0e6f;

int s_short = device->short_width * samples_per_us;
int s_long = device->long_width * samples_per_us;
Expand All @@ -617,7 +617,7 @@ int pulse_slicer_piwm_raw(const pulse_data_t *pulses, r_device *device)
}

// precision reciprocal
float f_short = device->short_width > 0.0 ? 1.0 / (device->short_width * samples_per_us) : 0;
float f_short = device->short_width > 0.0f ? 1.0f / (device->short_width * samples_per_us) : 0;

int w;

Expand Down Expand Up @@ -658,7 +658,7 @@ int pulse_slicer_piwm_raw(const pulse_data_t *pulses, r_device *device)

int pulse_slicer_piwm_dc(const pulse_data_t *pulses, r_device *device)
{
float samples_per_us = pulses->sample_rate / 1.0e6;
float samples_per_us = pulses->sample_rate / 1.0e6f;

int s_short = device->short_width * samples_per_us;
int s_long = device->long_width * samples_per_us;
Expand Down Expand Up @@ -714,7 +714,7 @@ int pulse_slicer_piwm_dc(const pulse_data_t *pulses, r_device *device)

int pulse_slicer_nrzs(const pulse_data_t *pulses, r_device *device)
{
float samples_per_us = pulses->sample_rate / 1.0e6;
float samples_per_us = pulses->sample_rate / 1.0e6f;

int s_short = device->short_width * samples_per_us;
int s_long = device->long_width * samples_per_us;
Expand Down Expand Up @@ -774,7 +774,7 @@ int pulse_slicer_nrzs(const pulse_data_t *pulses, r_device *device)

int pulse_slicer_osv1(const pulse_data_t *pulses, r_device *device)
{
float samples_per_us = pulses->sample_rate / 1.0e6;
float samples_per_us = pulses->sample_rate / 1.0e6f;

int s_short = device->short_width * samples_per_us;
int s_long = device->long_width * samples_per_us;
Expand Down
12 changes: 6 additions & 6 deletions src/r_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ void r_init_cfg(r_cfg_t *cfg)
if (!cfg->demod)
FATAL_CALLOC("r_init_cfg()");

cfg->demod->level_limit = 0.0;
cfg->demod->min_level = -12.1442;
cfg->demod->min_snr = 9.0;
cfg->demod->level_limit = 0.0f;
cfg->demod->min_level = -12.1442f;
cfg->demod->min_snr = 9.0f;
// Pulse detect will only print LOG_NOTICE and lower.
cfg->demod->detect_verbosity = LOG_WARNING;

Expand Down Expand Up @@ -324,8 +324,8 @@ void calc_rssi_snr(r_cfg_t *cfg, pulse_data_t *pulse_data)
float ook_high_estimate = pulse_data->ook_high_estimate > 0 ? pulse_data->ook_high_estimate : 1;
float ook_low_estimate = pulse_data->ook_low_estimate > 0 ? pulse_data->ook_low_estimate : 1;
float asnr = ook_high_estimate / ook_low_estimate;
float foffs1 = (float)pulse_data->fsk_f1_est / INT16_MAX * cfg->samp_rate / 2.0;
float foffs2 = (float)pulse_data->fsk_f2_est / INT16_MAX * cfg->samp_rate / 2.0;
float foffs1 = (float)pulse_data->fsk_f1_est / INT16_MAX * cfg->samp_rate / 2.0f;
float foffs2 = (float)pulse_data->fsk_f2_est / INT16_MAX * cfg->samp_rate / 2.0f;
pulse_data->freq1_hz = (foffs1 + cfg->center_frequency);
pulse_data->freq2_hz = (foffs2 + cfg->center_frequency);
pulse_data->centerfreq_hz = cfg->center_frequency;
Expand All @@ -351,7 +351,7 @@ void calc_rssi_snr(r_cfg_t *cfg, pulse_data_t *pulse_data)
char *time_pos_str(r_cfg_t *cfg, unsigned samples_ago, char *buf)
{
if (cfg->report_time == REPORT_TIME_SAMPLES) {
double s_per_sample = 1.0 / cfg->samp_rate;
double s_per_sample = 1.0f / cfg->samp_rate;
return sample_pos_str(cfg->demod->sample_file_pos - samples_ago * s_per_sample, buf);
}
else {
Expand Down

0 comments on commit 9d2a59a

Please sign in to comment.