mirror of
https://gitlab.com/square-game-liberation-front/F.E.I.S.git
synced 2025-02-28 23:41:33 +01:00
Add signed long long constructors for Fraction
This commit is contained in:
parent
b0da3382ec
commit
33a14a6bda
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
#include <gmpxx.h>
|
#include <gmpxx.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@ -15,6 +16,24 @@ Fraction::Fraction(const unsigned long long a, const unsigned long long b) {
|
|||||||
value = Fraction{a}.value / Fraction{b}.value;
|
value = Fraction{a}.value / Fraction{b}.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Fraction::Fraction(const long long a) {
|
||||||
|
const unsigned long long abs = [&](){
|
||||||
|
if (a == INT64_MIN) {
|
||||||
|
return static_cast<unsigned long long>(INT64_MAX) + 1;
|
||||||
|
} else {
|
||||||
|
return static_cast<unsigned long long>(a < 0 ? -a : a);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
value = Fraction{abs}.value;
|
||||||
|
if (a < 0) {
|
||||||
|
value = -value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Fraction::Fraction(const long long a, const long long b) {
|
||||||
|
value = Fraction{a}.value / Fraction{b}.value;
|
||||||
|
}
|
||||||
|
|
||||||
Fraction::Fraction(const Decimal& d) {
|
Fraction::Fraction(const Decimal& d) {
|
||||||
const auto reduced = d.reduce();
|
const auto reduced = d.reduce();
|
||||||
const mpq_class sign = (reduced.sign() > 0 ? 1 : -1);
|
const mpq_class sign = (reduced.sign() > 0 ? 1 : -1);
|
||||||
|
@ -23,6 +23,8 @@ public:
|
|||||||
|
|
||||||
explicit Fraction(const unsigned long long a);
|
explicit Fraction(const unsigned long long a);
|
||||||
Fraction(const unsigned long long a, const unsigned long long b);
|
Fraction(const unsigned long long a, const unsigned long long b);
|
||||||
|
explicit Fraction(const long long a);
|
||||||
|
Fraction(const long long a, const long long b);
|
||||||
explicit Fraction(const Decimal& d);
|
explicit Fraction(const Decimal& d);
|
||||||
explicit operator std::int64_t() const;
|
explicit operator std::int64_t() const;
|
||||||
explicit operator std::uint64_t() const;
|
explicit operator std::uint64_t() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user