Skip to content

Commit

Permalink
refactor(util): optimize roundToFraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Aug 23, 2022
1 parent fca22df commit db05a1a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/util/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ constexpr unsigned int roundUpToPowerOf2(unsigned int v) {

CMATH_CONSTEXPR double
roundToFraction(double value, int denominator) {
int wholePart = static_cast<int>(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<typename T>
Expand Down

0 comments on commit db05a1a

Please sign in to comment.