From fd2d8cb9c148b28d356582f07970874b11110321 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Fri, 28 Apr 2023 20:52:03 -0700 Subject: [PATCH] [hal] Use std::log2() for base-2 logarithm (#5278) --- hal/src/main/native/athena/DIO.cpp | 3 +-- hal/src/main/native/sim/DIO.cpp | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/hal/src/main/native/athena/DIO.cpp b/hal/src/main/native/athena/DIO.cpp index e6308fbb75..57b115384e 100644 --- a/hal/src/main/native/athena/DIO.cpp +++ b/hal/src/main/native/athena/DIO.cpp @@ -200,8 +200,7 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status) { if (*status != 0) { return; } - uint16_t pwmPeriodPower = - std::lround(std::log(1.0 / (16 * 1.0E-6 * rate)) / std::log(2.0)); + uint16_t pwmPeriodPower = std::lround(std::log2(1.0 / (16 * 1.0E-6 * rate))); digitalSystem->writePWMPeriodPower(pwmPeriodPower, status); } diff --git a/hal/src/main/native/sim/DIO.cpp b/hal/src/main/native/sim/DIO.cpp index b611b35e8a..f827bbf956 100644 --- a/hal/src/main/native/sim/DIO.cpp +++ b/hal/src/main/native/sim/DIO.cpp @@ -127,9 +127,7 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status) { // higher freq. // TODO: Round in the linear rate domain. // uint8_t pwmPeriodPower = static_cast( - // std::log(1.0 / (kExpectedLoopTiming * 0.25E-6 * rate)) / - // std::log(2.0) + - // 0.5); + // std::log2(1.0 / (kExpectedLoopTiming * 0.25E-6 * rate)) + 0.5); // TODO(THAD) : Add a case to set this in the simulator // digitalSystem->writePWMPeriodPower(pwmPeriodPower, status); }