linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] treewide: fix math problems
@ 2020-04-17 21:33 Rosen Penev
  0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2020-04-17 21:33 UTC (permalink / raw)
  To: linux-media

Found with bugprone-incorrect-roundings
Found with performance-type-promotion-in-math-fn

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 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(-)

diff --git a/lib/libdvbv5/dvb-fe.c b/lib/libdvbv5/dvb-fe.c
index 4ff64d58..46fadaf0 100644
--- a/lib/libdvbv5/dvb-fe.c
+++ b/lib/libdvbv5/dvb-fe.c
@@ -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
diff --git a/utils/rds-ctl/rds-ctl.cpp b/utils/rds-ctl/rds-ctl.cpp
index e0db5f39..58dc98a4 100644
--- a/utils/rds-ctl/rds-ctl.cpp
+++ b/utils/rds-ctl/rds-ctl.cpp
@@ -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());
diff --git a/utils/v4l2-ctl/v4l2-ctl-tuner.cpp b/utils/v4l2-ctl/v4l2-ctl-tuner.cpp
index 87c7790d..f6e268e3 100644
--- a/utils/v4l2-ctl/v4l2-ctl-tuner.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-tuner.cpp
@@ -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());
 			}
-- 
2.25.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-17 21:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-17 21:33 [PATCH] treewide: fix math problems Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).