From e3c5c9831a6617d0a150f0354fc4fb04074b22d5 Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Mon, 5 Dec 2022 22:43:18 +0000 Subject: [PATCH] Remove unnecessary casts to double for hard-coded numbers --- examples/wireless/wifi-tcp.cc | 4 +-- src/core/test/attribute-test-suite.cc | 6 ++-- .../test/lte-test-fdbet-ff-mac-scheduler.cc | 2 +- .../test/lte-test-tdbet-ff-mac-scheduler.cc | 2 +- .../model/cobalt-queue-disc.cc | 6 ++-- src/wimax/model/simple-ofdm-wimax-phy.cc | 36 +++++++++---------- src/wimax/model/ss-link-manager.cc | 2 +- src/wimax/model/ss-net-device.cc | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/examples/wireless/wifi-tcp.cc b/examples/wireless/wifi-tcp.cc index 38c2f0847..2cd2c0851 100644 --- a/examples/wireless/wifi-tcp.cc +++ b/examples/wireless/wifi-tcp.cc @@ -56,13 +56,13 @@ Ptr sink; //!< Pointer to the packet sink application uint64_t lastTotalRx = 0; //!< The value of the last total received bytes /** - * Calulate the throughput + * Calculate the throughput */ void CalculateThroughput() { Time now = Simulator::Now(); /* Return the simulator's virtual time. */ - double cur = (sink->GetTotalRx() - lastTotalRx) * (double)8 / + double cur = (sink->GetTotalRx() - lastTotalRx) * 8.0 / 1e5; /* Convert Application RX Packets to MBits. */ std::cout << now.GetSeconds() << "s: \t" << cur << " Mbit/s" << std::endl; lastTotalRx = sink->GetTotalRx(); diff --git a/src/core/test/attribute-test-suite.cc b/src/core/test/attribute-test-suite.cc index 1a84cf169..de6e26b0e 100644 --- a/src/core/test/attribute-test-suite.cc +++ b/src/core/test/attribute-test-suite.cc @@ -908,16 +908,16 @@ AttributeTestCase::DoRun() // When the object is first created, the Attribute should have the default // value. // - ok = CheckGetCodePaths(p, "TestFloat", "-1.1", DoubleValue((float)-1.1)); + ok = CheckGetCodePaths(p, "TestFloat", "-1.1", DoubleValue(-1.1F)); NS_TEST_ASSERT_MSG_EQ(ok, true, "Attribute not set properly by default value"); // // Set the Attribute. // - ok = p->SetAttributeFailSafe("TestFloat", DoubleValue((float)2.3)); + ok = p->SetAttributeFailSafe("TestFloat", DoubleValue(2.3F)); NS_TEST_ASSERT_MSG_EQ(ok, true, "Could not SetAttributeFailSafe() to 2.3"); - ok = CheckGetCodePaths(p, "TestFloat", "2.3", DoubleValue((float)2.3)); + ok = CheckGetCodePaths(p, "TestFloat", "2.3", DoubleValue(2.3F)); NS_TEST_ASSERT_MSG_EQ(ok, true, "Attribute not set properly by SetAttributeFailSafe() via DoubleValue"); diff --git a/src/lte/test/lte-test-fdbet-ff-mac-scheduler.cc b/src/lte/test/lte-test-fdbet-ff-mac-scheduler.cc index 45776e921..a0965bc10 100644 --- a/src/lte/test/lte-test-fdbet-ff-mac-scheduler.cc +++ b/src/lte/test/lte-test-fdbet-ff-mac-scheduler.cc @@ -519,7 +519,7 @@ LenaFdBetFfMacSchedulerTestCase2::DoRun() */ for (int i = 0; i < m_nUser; i++) { - double thrRatio = (double)1 / m_nUser; + double thrRatio = 1.0 / m_nUser; double estThrRatio = (double)dlDataRxed.at(i) / totalData; NS_LOG_INFO("\tUser " << i << " thrRatio " << thrRatio << " estThrRatio " << estThrRatio); NS_TEST_ASSERT_MSG_EQ_TOL(estThrRatio, thrRatio, tolerance, " Unfair Throughput!"); diff --git a/src/lte/test/lte-test-tdbet-ff-mac-scheduler.cc b/src/lte/test/lte-test-tdbet-ff-mac-scheduler.cc index 5f8d15d5e..4e12f0fca 100644 --- a/src/lte/test/lte-test-tdbet-ff-mac-scheduler.cc +++ b/src/lte/test/lte-test-tdbet-ff-mac-scheduler.cc @@ -524,7 +524,7 @@ LenaTdBetFfMacSchedulerTestCase2::DoRun() */ for (int i = 0; i < m_nUser; i++) { - double thrRatio = (double)1 / m_nUser; + double thrRatio = 1.0 / m_nUser; double estThrRatio = (double)dlDataRxed.at(i) / totalData; NS_LOG_INFO("\tUser " << i << " thrRatio " << thrRatio << " estThrRatio " << estThrRatio); NS_TEST_ASSERT_MSG_EQ_TOL(estThrRatio, thrRatio, tolerance, " Unfair Throughput!"); diff --git a/src/traffic-control/model/cobalt-queue-disc.cc b/src/traffic-control/model/cobalt-queue-disc.cc index c39235a8c..566a12fea 100644 --- a/src/traffic-control/model/cobalt-queue-disc.cc +++ b/src/traffic-control/model/cobalt-queue-disc.cc @@ -403,7 +403,7 @@ CobaltQueueDisc::CobaltQueueFull(int64_t now) if (CoDelTimeAfter((now - m_lastUpdateTimeBlue), Time2CoDel(m_target))) { NS_LOG_LOGIC("inside IF block"); - m_pDrop = std::min(m_pDrop + m_increment, (double)1.0); + m_pDrop = std::min(m_pDrop + m_increment, 1.0); m_lastUpdateTimeBlue = now; } m_dropping = true; @@ -421,7 +421,7 @@ CobaltQueueDisc::CobaltQueueEmpty(int64_t now) NS_LOG_FUNCTION(this); if (m_pDrop && CoDelTimeAfter((now - m_lastUpdateTimeBlue), Time2CoDel(m_target))) { - m_pDrop = std::max(m_pDrop - m_decrement, (double)0.0); + m_pDrop = std::max(m_pDrop - m_decrement, 0.0); m_lastUpdateTimeBlue = now; } m_dropping = false; @@ -534,7 +534,7 @@ CobaltQueueDisc::CobaltShouldDrop(Ptr item, int64_t now) if (CoDelTimeAfter(sojournTime, Time2CoDel(m_blueThreshold)) && CoDelTimeAfter((now - m_lastUpdateTimeBlue), Time2CoDel(m_target))) { - m_pDrop = std::min(m_pDrop + m_increment, (double)1.0); + m_pDrop = std::min(m_pDrop + m_increment, 1.0); m_lastUpdateTimeBlue = now; } diff --git a/src/wimax/model/simple-ofdm-wimax-phy.cc b/src/wimax/model/simple-ofdm-wimax-phy.cc index 037194ff8..1678f7d69 100644 --- a/src/wimax/model/simple-ofdm-wimax-phy.cc +++ b/src/wimax/model/simple-ofdm-wimax-phy.cc @@ -171,7 +171,7 @@ SimpleOfdmWimaxPhy::InitSimpleOfdmWimaxPhy() m_rxGain = 0; m_txGain = 0; m_nfft = 256; - m_g = (double)1 / 4; + m_g = 1.0 / 4; SetNrCarriers(192); m_fecBlocks = new std::list; m_receivedFecBlocks = new std::list; @@ -648,27 +648,27 @@ SimpleOfdmWimaxPhy::GetModulationFecParams(WimaxPhy::ModulationType modulationTy { case MODULATION_TYPE_BPSK_12: bitsPerSymbol = 1; - fecCode = (double)1 / 2; + fecCode = 1.0 / 2; break; case MODULATION_TYPE_QPSK_12: bitsPerSymbol = 2; - fecCode = (double)1 / 2; + fecCode = 1.0 / 2; break; case MODULATION_TYPE_QPSK_34: bitsPerSymbol = 2; - fecCode = (double)3 / 4; + fecCode = 3.0 / 4; break; case MODULATION_TYPE_QAM16_12: bitsPerSymbol = 4; - fecCode = (double)1 / 2; + fecCode = 1.0 / 2; break; case MODULATION_TYPE_QAM16_34: bitsPerSymbol = 4; - fecCode = (double)3 / 4; + fecCode = 3.0 / 4; break; case MODULATION_TYPE_QAM64_23: bitsPerSymbol = 6; - fecCode = (double)2 / 3; + fecCode = 2.0 / 3; break; case MODULATION_TYPE_QAM64_34: bitsPerSymbol = 6; @@ -954,20 +954,20 @@ SimpleOfdmWimaxPhy::DoSetPhyParameters() frequency is 23040000, symbol (OFDM symbol) duration is 1.388888888888889e-05 seconds, PS duration is 1.7361111111111112e-07 seconds. Hence PSs per frame is 57600, symbols per frame is 720 and PSs per symbol is 80. Note that defining these parameters (symbol and PS duration) as - Time may not result in exaclty these values therefore lrint has been used (otherwise should be + Time may not result in exactly these values therefore lrint has been used (otherwise should be defined as double). For licensed bands set channel bandwidth according to Table B.26, page 810.*/ double samplingFrequency = DoGetSamplingFrequency(); - Time psDuration = Seconds((double)4 / samplingFrequency); + Time psDuration = Seconds(4.0 / samplingFrequency); SetPsDuration(psDuration); uint16_t psPerFrame = (uint16_t)(GetFrameDuration().GetSeconds() / psDuration.GetSeconds()); SetPsPerFrame(psPerFrame); double subcarrierSpacing = samplingFrequency / DoGetNfft(); - double tb = (double)1 / subcarrierSpacing; // Tb (useful symbol time) - double tg = DoGetGValue() * tb; // Tg (cyclic prefix time) - Time symbolDuration = Seconds(tb + tg); // OFDM Symbol Time + double tb = 1.0 / subcarrierSpacing; // Tb (useful symbol time) + double tg = DoGetGValue() * tb; // Tg (cyclic prefix time) + Time symbolDuration = Seconds(tb + tg); // OFDM Symbol Time SetSymbolDuration(symbolDuration); uint16_t psPerSymbol = lrint(symbolDuration.GetSeconds() / psDuration.GetSeconds()); SetPsPerSymbol(psPerSymbol); @@ -996,23 +996,23 @@ SimpleOfdmWimaxPhy::DoGetSamplingFactor() const if (channelBandwidth % 1750000 == 0) { - return (double)8 / 7; + return 8.0 / 7; } else if (channelBandwidth % 1500000 == 0) { - return (double)86 / 75; + return 86.0 / 75; } else if (channelBandwidth % 1250000 == 0) { - return (double)144 / 125; + return 144.0 / 125; } else if (channelBandwidth % 2750000 == 0) { - return (double)316 / 275; + return 316.0 / 275; } else if (channelBandwidth % 2000000 == 0) { - return (double)57 / 50; + return 57.0 / 50; } else { @@ -1020,7 +1020,7 @@ SimpleOfdmWimaxPhy::DoGetSamplingFactor() const NS_FATAL_ERROR("wrong channel bandwidth for OFDM PHY"); } - return (double)8 / 7; + return 8.0 / 7; } double diff --git a/src/wimax/model/ss-link-manager.cc b/src/wimax/model/ss-link-manager.cc index f7f91a486..0fc66598a 100644 --- a/src/wimax/model/ss-link-manager.cc +++ b/src/wimax/model/ss-link-manager.cc @@ -337,7 +337,7 @@ void SSLinkManager::ResetRangingRequestCW() { m_rangingCW = - (uint8_t)std::pow((double)2, (double)m_ss->GetCurrentUcd().GetRangingBackoffStart()) - 1; + (uint8_t)std::pow(2.0, (double)m_ss->GetCurrentUcd().GetRangingBackoffStart()) - 1; } void diff --git a/src/wimax/model/ss-net-device.cc b/src/wimax/model/ss-net-device.cc index ada23372a..1c712906f 100644 --- a/src/wimax/model/ss-net-device.cc +++ b/src/wimax/model/ss-net-device.cc @@ -1313,7 +1313,7 @@ SubscriberStationNetDevice::ProcessUcd(const Ucd& ucd) return; // nothing new in UCD so don't read } SetCurrentUcd(ucd); - m_linkManager->SetRangingCW((uint8_t)std::pow((double)2, (double)ucd.GetRangingBackoffStart()) - + m_linkManager->SetRangingCW((uint8_t)std::pow(2.0, (double)ucd.GetRangingBackoffStart()) - 1); // initializing ranging CW OfdmUcdChannelEncodings ucdChnlEncodings = ucd.GetChannelEncodings();