6 #ifndef THEORETICA_RATIO_H
7 #define THEORETICA_RATIO_H
9 #ifndef THEORETICA_NO_PRINT
22 template <
typename T1,
typename T2 = T1>
83 return static_cast<T
>(
num) /
static_cast<T
>(
den);
91 return static_cast<T2
>(
num) /
static_cast<T2
>(
den);
100 inline operator T2() {
105 #ifndef THEORETICA_NO_PRINT
110 std::stringstream res;
representing a ratio between two objects, like a fraction or a rational polynomial.
Definition: ratio.h:23
ratio(const T1 &n, const T2 &d)
Construct the object from two objects.
Definition: ratio.h:40
T2 den
The denominator.
Definition: ratio.h:30
T1 num
The numerator.
Definition: ratio.h:27
ratio operator/(const ratio &r) const
Divide two ratios (without explicitly using division)
Definition: ratio.h:50
ratio()
Construct the object from the default constructors of the two types.
Definition: ratio.h:34
T2 eval()
Evaluate the ratio as the division between numerator and denominator cast to the type of the denomina...
Definition: ratio.h:90
std::string to_string() const
Convert the ratio to string representation.
Definition: ratio.h:108
ratio operator*(const ratio &r) const
Multiply two ratios.
Definition: ratio.h:45
ratio operator/(const T2 &b) const
Divide the ratio by a factor.
Definition: ratio.h:70
T eval_as()
Evaluate the ratio as the division between numerator and denominator cast to the specified type.
Definition: ratio.h:82
ratio operator-(const ratio &r) const
Subtract two ratios.
Definition: ratio.h:60
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:124
ratio operator*(const T1 &a) const
Multiply the ratio by a factor.
Definition: ratio.h:65
ratio operator+(const ratio &r) const
Add two ratios.
Definition: ratio.h:55
std::string string(size_t length)
Generate a random string made of human-readable ASCII characters.
Definition: random.h:102
Main namespace of the library which contains all functions and objects.
Definition: algebra.h:27