6#ifndef THEORETICA_RATIO_H
7#define THEORETICA_RATIO_H
9#ifndef THEORETICA_NO_PRINT
24 template <
typename T1,
typename T2 = T1>
85 return static_cast<T>(
num) /
static_cast<T>(
den);
93 return static_cast<T2>(
num) /
static_cast<T2>(
den);
102 inline operator T2() {
114 typename = std::enable_if_t<std::is_integral<T1>::value>,
115 typename = std::enable_if_t<std::is_integral<T2>::value>
132#ifndef THEORETICA_NO_PRINT
137 std::stringstream
res;
144 inline operator std::string() {
152 return out <<
obj.to_string();
representing a ratio between two objects, like a fraction or a rational polynomial.
Definition ratio.h:25
ratio(const T1 &n, const T2 &d)
Construct the object from two objects.
Definition ratio.h:42
ratio< T1, T2 > & reduce()
Reduces a fraction (ratio of integers) to lowest terms by dividing numerator and denominator by their...
Definition ratio.h:117
T2 den
The denominator.
Definition ratio.h:32
T1 num
The numerator.
Definition ratio.h:29
ratio operator/(const ratio &r) const
Divide two ratios (without explicitly using division)
Definition ratio.h:52
ratio()
Construct the object from the default constructors of the two types.
Definition ratio.h:36
T2 eval()
Evaluate the ratio as the division between numerator and denominator cast to the type of the denomina...
Definition ratio.h:92
friend std::ostream & operator<<(std::ostream &out, const ratio< T1, T2 > &obj)
Stream the ratio in string representation to an output stream (std::ostream)
Definition ratio.h:151
std::string to_string() const
Convert the ratio to string representation.
Definition ratio.h:135
ratio operator*(const ratio &r) const
Multiply two ratios.
Definition ratio.h:47
ratio operator/(const T2 &b) const
Divide the ratio by a factor.
Definition ratio.h:72
T eval_as()
Evaluate the ratio as the division between numerator and denominator cast to the specified type.
Definition ratio.h:84
ratio operator-(const ratio &r) const
Subtract two ratios.
Definition ratio.h:62
ratio operator*(const T1 &a) const
Multiply the ratio by a factor.
Definition ratio.h:67
ratio operator+(const ratio &r) const
Add two ratios.
Definition ratio.h:57
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
Vector make_error()
Create a vector representing an error state, with all NaN values.
Definition algebra.h:103
Integer1 gcd(Integer1 a, Integer2 b)
Compute the greatest common divisor of two numbers using Euclid's algorithm.
Definition real_analysis.h:1286