mirror of
https://gitlab.com/square-game-liberation-front/F.E.I.S.git
synced 2025-02-28 15:30:32 +01:00
Add unsigned long long constructors for fractions
This commit is contained in:
parent
a0be5cec0e
commit
b6741d46ea
@ -12,7 +12,7 @@ namespace better {
|
||||
return (
|
||||
level == other.level
|
||||
and (
|
||||
((not timing.has_value()) and (not other.timing.has_value()))
|
||||
((not timing.has_value()) or (not other.timing.has_value()))
|
||||
or (**timing == **other.timing)
|
||||
) and hakus == other.hakus
|
||||
and *notes == *other.notes
|
||||
@ -90,12 +90,8 @@ namespace better {
|
||||
) {
|
||||
auto new_object = nlohmann::ordered_json::object();
|
||||
for (const auto& [key, value] : object.items()) {
|
||||
if (not fallback.contains(key)) {
|
||||
if ((not fallback.contains(key)) or (fallback[key] != value)) {
|
||||
new_object[key] = value;
|
||||
} else {
|
||||
if (fallback[key] != value) {
|
||||
new_object[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new_object;
|
||||
|
@ -55,7 +55,9 @@ namespace better {
|
||||
if (not song_timing.empty()) {
|
||||
memon["timing"] = song_timing;
|
||||
}
|
||||
fallback_timing_object.update(song_timing);
|
||||
// Adding this line back in will toggle "strict" timing mode :
|
||||
// chart timing objects will have their redundant values removed
|
||||
// fallback_timing_object.update(song_timing);
|
||||
auto json_charts = nlohmann::ordered_json::object();
|
||||
for (const auto& [name, chart] : charts) {
|
||||
json_charts[name] = chart.dump_to_memon_1_0_0(fallback_timing_object);
|
||||
|
@ -5,6 +5,16 @@
|
||||
#include <gmpxx.h>
|
||||
#include <stdexcept>
|
||||
|
||||
Fraction::Fraction(const unsigned long long a) {
|
||||
const unsigned long a_low = a & 0x00000000ffffffffULL;
|
||||
const unsigned long a_high = a >> 32;
|
||||
value = a_low + (mpq_class{a_high} << 32);
|
||||
}
|
||||
|
||||
Fraction::Fraction(const unsigned long long a, const unsigned long long b) {
|
||||
value = Fraction{a}.value / Fraction{b}.value;
|
||||
}
|
||||
|
||||
Fraction::Fraction(const Decimal& d) {
|
||||
const auto reduced = d.reduce();
|
||||
const mpq_class sign = (reduced.sign() > 0 ? 1 : -1);
|
||||
|
@ -21,6 +21,8 @@ public:
|
||||
value.canonicalize();
|
||||
};
|
||||
|
||||
explicit Fraction(const unsigned long long a);
|
||||
Fraction(const unsigned long long a, const unsigned long long b);
|
||||
explicit Fraction(const Decimal& d);
|
||||
explicit operator std::int64_t() const;
|
||||
explicit operator std::uint64_t() const;
|
||||
|
@ -11,6 +11,11 @@ TEST_CASE("Fractions") {
|
||||
SUBCASE("std::uint64_t") {
|
||||
CHECK(Fraction{UINT64_MAX, UINT64_C(1)} == Fraction{"18446744073709551615/1"});
|
||||
}
|
||||
SUBCASE("unsigned long long") {
|
||||
CHECK(Fraction{18446744073709551615ULL} == Fraction{"18446744073709551615/1"});
|
||||
CHECK(Fraction{12345678912345678912ULL} == Fraction{"12345678912345678912/1"});
|
||||
CHECK(Fraction{1234567891234567ULL, 1234567ULL} == Fraction{"1234567891234567/1234567"});
|
||||
}
|
||||
SUBCASE("decimals") {
|
||||
CHECK(Fraction{Decimal{"0.0000000000000000001"}} == Fraction{"1/10000000000000000000"});
|
||||
CHECK(Fraction{Decimal{"12345.6789"}} == Fraction{123456789,10000});
|
||||
|
Loading…
x
Reference in New Issue
Block a user