WIP floor and modulo implementation, not working

This commit is contained in:
Mateusz Piątkowski 2022-06-04 15:32:27 +02:00
parent c1e1acd6e2
commit 1dbf859ee9
5 changed files with 16 additions and 1 deletions

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "lib/midi"]
path = lib/midi
url = git@engi.evolpe.it:pi/midi.git
url = https://engi.evolpe.it/pi/midi

BIN
src/.musique.hh.swp Normal file

Binary file not shown.

BIN
src/.number.cc.swp Normal file

Binary file not shown.

View File

@ -596,6 +596,8 @@ struct Number
auto simplify() const -> Number; ///< Returns self, but with gcd(num, den) == 1
void simplify_inplace(); ///< Update self, to have gcd(num, den) == 1
auto floor() const -> Number; ///< Round to first lower integer
bool operator==(Number const&) const;
bool operator!=(Number const&) const;
std::strong_ordering operator<=>(Number const&) const;
@ -608,6 +610,7 @@ struct Number
Number& operator*=(Number const& rhs);
Number operator/(Number const& rhs) const;
Number& operator/=(Number const& rhs);
Number operator%(Number const& rhs) const;
/// Parses source contained by token into a Number instance
static Result<Number> from(Token token);

View File

@ -48,6 +48,13 @@ void Number::simplify_inplace()
}
}
auto Number::floor() const -> Number
{
auto copy = simplify();
copy = copy - (copy % 1);
return copy;
}
bool Number::operator==(Number const& rhs) const
{
return (*this <=> rhs) == 0;
@ -119,6 +126,11 @@ Number& Number::operator/=(Number const& rhs)
return *this;
}
Number Number::operator%(Number const& rhs) const
{
return Number{num % rhs.num}.simplify();
}
std::ostream& operator<<(std::ostream& os, Number const& n)
{
return n.den == 1