ratio
namespace opentl {
template <std::intmax_t Num, std::intmax_t Den = 1>
struct ratio;
}
A compile-time representation of a finite rational number, reduced to its
lowest terms. The denominator is always positive.
Template Parameters
| Name |
Description |
Num |
The numerator. |
Den |
The denominator. |
Member Constants
| Name |
Type |
Description |
num |
std::intmax_t |
The reduced numerator, preserving the sign. |
den |
std::intmax_t |
The reduced denominator, always positive. |
Member Types
| Type |
Description |
type |
The reduced form, ratio<num, den>. |
Example
#include <opentl/ratio.hpp>
int main() {
using half = opentl::ratio<1, 2>;
static_assert(half::num == 1);
static_assert(half::den == 2);
using quarter = opentl::ratio<2, -8>;
static_assert(quarter::num == -1);
static_assert(quarter::den == 4);
}