treewide: fix math problems
PATCH 1/1 treewide: fix math problems
Found with bugprone-incorrect-roundings
Found with performance-type-promotion-in-math-fn
Signed-off-by Rosen Penev <[email protected]>
--- lib/libdvbv5/dvb-fe.c | 2 +- utils/rds-ctl/rds-ctl.cpp | 5 +++-- utils/v4l2-ctl/v4l2-ctl-tuner.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-)
lib/libdvbv5/dvb-fe.c +1 -1
@@ -1638,7 +1638,7 @@ static int __dvb_fe_snprintf_eng(char *buf, int len, float val, int metric)* Converts the number into an expoent and a * value between 0 and 1000, exclusive */ - exp = (int )log10 (val); + exp = (int )log10f (val);if (exp >0 ) exp = (exp /3 ) *3 ;else
utils/rds-ctl/rds-ctl.cpp +3 -2
@@ -28,6 +28,7 @@ #include <libv4l2rds.h> #include <cctype> +#include <cmath> #include <ctime> #include <list> #include <vector>
@@ -915,8 +916,8 @@ static void get_options(const int fd, const int capabilities, struct v4l2_freque else printf("\tFrequency range : %.1f MHz - %.1f MHz\n", vt.rangelow / 16.0, vt.rangehigh / 16.0); - printf("\tSignal strength/AFC : %d%%/%d\n", - static_cast<int>((vt.signal / 655.35)+0.5), vt.afc); + printf("\tSignal strength/AFC : %ld%%/%d\n", + std::lround(vt.signal / 655.25), vt.afc); printf("\tCurrent audio mode : %s\n", audmode2s(vt.audmode)); printf("\tAvailable subchannels: %s\n", rxsubchans2s(vt.rxsubchans).c_str());
utils/v4l2-ctl/v4l2-ctl-tuner.cpp +1 -1
@@ -422,7 +422,7 @@ void tuner_get(cv4l_fd &_fd) vt.rangelow / 16.0, vt.rangehigh / 16.0); if (vt.type != V4L2_TUNER_SDR && vt.type != V4L2_TUNER_RF) { - printf("\tSignal strength/AFC : %d%%/%d\n", static_cast<int>((vt.signal / 655.35)+0.5), vt.afc); + printf("\tSignal strength/AFC : %ld%%/%d\n", lround(vt.signal / 655.35), vt.afc); printf("\tCurrent audio mode : %s\n", audmode2s(vt.audmode)); printf("\tAvailable subchannels: %s\n", rxsubchans2s(vt.rxsubchans).c_str()); }
Signature · 1 line
2.25.2