diff --git a/src/util/math.h b/src/util/math.h index f08b2e9be6a..ea9f5768bde 100644 --- a/src/util/math.h +++ b/src/util/math.h @@ -65,10 +65,10 @@ constexpr unsigned int roundUpToPowerOf2(unsigned int v) { CMATH_CONSTEXPR double roundToFraction(double value, int denominator) { - int wholePart = static_cast(value); - double fractionPart = value - wholePart; + double wholePart; + double fractionPart = std::modf(value, &wholePart); double numerator = std::round(fractionPart * denominator); - return wholePart + numerator / denominator; + return wholePart + (numerator / denominator); } template