#include <rational.h>
Definition at line 13 of file rational.h.
◆ Rational() [1/2]
| constexpr impeller::Rational::Rational |
( |
int32_t |
num | ) |
|
|
inlineexplicitconstexpr |
Definition at line 15 of file rational.h.
15: num_(num), den_(1) {}
◆ Rational() [2/2]
| constexpr impeller::Rational::Rational |
( |
int32_t |
num, |
|
|
uint32_t |
den |
|
) |
| |
|
inlineconstexpr |
Definition at line 17 of file rational.h.
17: num_(num), den_(den) {}
◆ GetDenominator()
| uint32_t impeller::Rational::GetDenominator |
( |
| ) |
const |
|
inline |
◆ GetHash()
| uint64_t impeller::Rational::GetHash |
( |
| ) |
const |
Definition at line 38 of file rational.cc.
38 {
39 if (num_ == 0) {
40 return 0;
41 }
42 uint64_t gcd = std::gcd(num_, den_);
43 return ((num_ / gcd) << 32) | (den_ / gcd);
44}
◆ GetNumerator()
| int32_t impeller::Rational::GetNumerator |
( |
| ) |
const |
|
inline |
◆ Invert()
| Rational impeller::Rational::Invert |
( |
| ) |
const |
◆ operator Scalar()
| impeller::Rational::operator Scalar |
( |
| ) |
const |
|
inlineexplicit |
Definition at line 29 of file rational.h.
29{ return static_cast<float>(num_) / den_; }
◆ operator<()
| bool impeller::Rational::operator< |
( |
const Rational & |
that | ) |
const |
Definition at line 28 of file rational.cc.
28 {
29 if (den_ == that.den_) {
30 return num_ < that.num_;
31 } else if ((num_ >= 0) != (that.num_ >= 0)) {
32 return num_ < that.num_;
33 } else {
34 return AbsToUnsigned(num_) * that.den_ < AbsToUnsigned(that.num_) * den_;
35 }
36}
◆ operator==()
| bool impeller::Rational::operator== |
( |
const Rational & |
that | ) |
const |
Definition at line 18 of file rational.cc.
18 {
19 if (den_ == that.den_) {
20 return num_ == that.num_;
21 } else if ((num_ >= 0) != (that.num_ >= 0)) {
22 return false;
23 } else {
24 return AbsToUnsigned(num_) * that.den_ == AbsToUnsigned(that.num_) * den_;
25 }
26}
The documentation for this class was generated from the following files: