MCPcopy Create free account
hub / github.com/CieNTi/serial_port_plotter / simplifyFraction

Method simplifyFraction

qcustomplot/qcustomplot.cpp:6866–6882  ·  view source on GitHub ↗

! \internal Takes the fraction given by \a numerator and \a denominator and modifies the values to make sure the fraction is in irreducible form, i.e. numerator and denominator don't share any common factors which could be cancelled. */

Source from the content-addressed store, hash-verified

6864 factors which could be cancelled.
6865*/
6866void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const
6867{
6868 if (numerator == 0 || denominator == 0)
6869 return;
6870
6871 int num = numerator;
6872 int denom = denominator;
6873 while (denom != 0) // euclidean gcd algorithm
6874 {
6875 int oldDenom = denom;
6876 denom = num % denom;
6877 num = oldDenom;
6878 }
6879 // num is now gcd of numerator and denominator
6880 numerator /= num;
6881 denominator /= num;
6882}
6883
6884/*! \internal
6885

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected