[hal] Use std::lround() instead of adding 0.5 and truncating (#3012)

This commit is contained in:
Peter Johnson
2021-03-19 14:24:46 -07:00
committed by GitHub
parent 48e9f39513
commit 160fb740f4
3 changed files with 13 additions and 12 deletions

View File

@@ -191,8 +191,8 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status) {
if (*status != 0) {
return;
}
uint16_t pwmPeriodPower = static_cast<uint16_t>(
std::log(1.0 / (16 * 1.0E-6 * rate)) / std::log(2.0) + 0.5);
uint16_t pwmPeriodPower =
std::lround(std::log(1.0 / (16 * 1.0E-6 * rate)) / std::log(2.0));
digitalSystem->writePWMPeriodPower(pwmPeriodPower, status);
}