MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / fraction

Method fraction

code/mathematics/fraction.cpp:4–9  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2 T gcd(T a, T b) { return b == T(0) ? a : gcd(b, a % b); }
3 T n, d;
4 fraction(T n_=T(0), T d_=T(1)) {
5 assert(d_ != 0);
6 n = n_, d = d_;
7 if (d < T(0)) n = -n, d = -d;
8 T g = gcd(abs(n), abs(d));
9 n /= g, d /= g; }
10 fraction(const fraction<T>& other)
11 : n(other.n), d(other.d) { }
12 fraction<T> operator +(const fraction<T>& other) const {

Callers

nothing calls this directly

Calls 1

gcdFunction · 0.70

Tested by

no test coverage detected