Commit 8ddb3fac authored by Joshua Ashton's avatar Joshua Ashton 🐸

[util] Implement simplest ratio helper

parent 48eefb92
#include <numeric>
#include <algorithm>
#include <cstdint>
namespace dxvk {
/**
* \brief Simplest ratio helper
*/
template <typename T>
class Ratio {
public:
Ratio(T num, T denom) {
const T gcd = std::gcd(num, denom);
m_num = num / gcd;
m_denom = denom / gcd;
}
inline T num() const { return m_num; }
inline T denom() const { return m_denom; }
inline bool operator == (const Ratio& other) const {
return num() == other.num() && denom() == other.denom();
}
inline bool operator != (const Ratio& other) const {
return !(*this == other);
}
inline bool operator >= (const Ratio& other) const {
return num() * other.denom() >= other.num() * denom();
}
inline bool operator > (const Ratio& other) const {
return num() * other.denom() > other.num() * denom();
}
inline bool operator < (const Ratio& other) const {
return !(*this >= other);
}
inline bool operator <= (const Ratio& other) const {
return !(*this > other);
}
private:
T m_num, m_denom;
};
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment