WIP floor and modulo implementation, not working
This commit is contained in:
parent
c1e1acd6e2
commit
1dbf859ee9
2
.gitmodules
vendored
2
.gitmodules
vendored
@ -1,3 +1,3 @@
|
|||||||
[submodule "lib/midi"]
|
[submodule "lib/midi"]
|
||||||
path = 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
BIN
src/.musique.hh.swp
Normal file
Binary file not shown.
BIN
src/.number.cc.swp
Normal file
BIN
src/.number.cc.swp
Normal file
Binary file not shown.
@ -596,6 +596,8 @@ struct Number
|
|||||||
auto simplify() const -> Number; ///< Returns self, but with gcd(num, den) == 1
|
auto simplify() const -> Number; ///< Returns self, but with gcd(num, den) == 1
|
||||||
void simplify_inplace(); ///< Update self, to have 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;
|
||||||
bool operator!=(Number const&) const;
|
bool operator!=(Number const&) const;
|
||||||
std::strong_ordering 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);
|
||||||
Number operator/(Number const& rhs) const;
|
Number operator/(Number const& rhs) const;
|
||||||
Number& operator/=(Number const& rhs);
|
Number& operator/=(Number const& rhs);
|
||||||
|
Number operator%(Number const& rhs) const;
|
||||||
|
|
||||||
/// Parses source contained by token into a Number instance
|
/// Parses source contained by token into a Number instance
|
||||||
static Result<Number> from(Token token);
|
static Result<Number> from(Token token);
|
||||||
|
@ -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
|
bool Number::operator==(Number const& rhs) const
|
||||||
{
|
{
|
||||||
return (*this <=> rhs) == 0;
|
return (*this <=> rhs) == 0;
|
||||||
@ -119,6 +126,11 @@ Number& Number::operator/=(Number const& rhs)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Number Number::operator%(Number const& rhs) const
|
||||||
|
{
|
||||||
|
return Number{num % rhs.num}.simplify();
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, Number const& n)
|
std::ostream& operator<<(std::ostream& os, Number const& n)
|
||||||
{
|
{
|
||||||
return n.den == 1
|
return n.den == 1
|
||||||
|
Loading…
Reference in New Issue
Block a user