diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-03-17 23:09:05 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-03-17 23:09:05 +0100 |
commit | a5e82cbf790aaa0d7f352da51398abfb8352afc6 (patch) | |
tree | 6d41cd677f85448c38dca46e147a70e210fade51 /src/OutputUHD.cpp | |
parent | fdb59da8301c3679c6cebf54022b24048370184b (diff) | |
download | dabmod-a5e82cbf790aaa0d7f352da51398abfb8352afc6.tar.gz dabmod-a5e82cbf790aaa0d7f352da51398abfb8352afc6.tar.bz2 dabmod-a5e82cbf790aaa0d7f352da51398abfb8352afc6.zip |
Do not compare floats for equality. Use a 1PPM window instead
Diffstat (limited to 'src/OutputUHD.cpp')
-rw-r--r-- | src/OutputUHD.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index a57a46a..c9e630b 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -31,6 +31,7 @@ #include "Log.h" #include "RemoteControl.h" +#include <cmath> #include <iostream> #include <assert.h> #include <stdexcept> @@ -96,12 +97,12 @@ OutputUHD::OutputUHD( double master_clk_rate = myUsrp->get_master_clock_rate(); MDEBUG("OutputUHD:Checking master clock rate: %f...\n", master_clk_rate); - if (myConf.masterClockRate != master_clk_rate) { + if (fabs(master_clk_rate - myConf.masterClockRate) > + (myConf.masterClockRate * 1e-6)) { throw std::runtime_error("Cannot set USRP master_clock_rate. Aborted."); } } - MDEBUG("OutputUHD:Setting REFCLK and PPS input...\n"); myUsrp->set_clock_source(myConf.refclk_src); @@ -118,7 +119,8 @@ OutputUHD::OutputUHD( myUsrp->set_tx_rate(myConf.sampleRate); MDEBUG("OutputUHD:Actual TX Rate: %f Msps...\n", myUsrp->get_tx_rate()); - if (myConf.sampleRate != myUsrp->get_tx_rate()) { + if (fabs(myUsrp->get_tx_rate() / myConf.sampleRate) > + myConf.sampleRate * 1e-6) { MDEBUG("OutputUHD: Cannot set sample\n"); throw std::runtime_error("Cannot set USRP sample rate. Aborted."); } |