[PATCH] Using a #define for constant 2^22 (not pow())

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/osmocom-sdr@lists.osmocom.org/.

Christian Vogel vogelchr at vogel.cx
Wed May 16 09:30:11 UTC 2012


pow() might require the math library to be linked with
rtl-sdl (e.g. when compiling with clang), even though
it's actually constant.
---
 src/rtl-sdr.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/rtl-sdr.c b/src/rtl-sdr.c
index 6a9539b..da79acb 100644
--- a/src/rtl-sdr.c
+++ b/src/rtl-sdr.c
@@ -675,6 +675,9 @@ int rtlsdr_set_tuner_gain_mode(rtlsdr_dev_t *dev, int mode)
 	return r;
 }
 
+/* two raised to the power of n */
+#define TWO_POW(n)		((double)(1ULL<<(n)))
+
 int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate)
 {
 	uint16_t tmp;
@@ -688,10 +691,10 @@ int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate)
 	if (samp_rate > MAX_SAMP_RATE)
 		samp_rate = MAX_SAMP_RATE;
 
-	rsamp_ratio = (dev->rtl_xtal * pow(2, 22)) / samp_rate;
+	rsamp_ratio = (dev->rtl_xtal * TWO_POW(22)) / samp_rate;
 	rsamp_ratio &= ~3;
 
-	real_rate = (dev->rtl_xtal * pow(2, 22)) / rsamp_ratio;
+	real_rate = (dev->rtl_xtal * TWO_POW(22)) / rsamp_ratio;
 
 	if ( ((double)samp_rate) != real_rate )
 		fprintf(stderr, "Exact sample rate is: %f Hz\n", real_rate);
-- 
1.7.0.4


--dDRMvlgZJXvWKvBx
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0002-include-math.h-was-not-needed.patch"



More information about the osmocom-sdr mailing list