Compare commits

...

5 Commits

Author SHA1 Message Date
Mateusz Piątkowski
26477e6363 better ode to joy 2022-06-22 17:43:04 +02:00
Mateusz Piątkowski
239590c94e better ode to joy 2022-06-22 17:41:13 +02:00
Mateusz Piątkowski
a0e42ad5e6 better ode to joy 2022-06-22 17:33:49 +02:00
Mateusz Piątkowski
70814d62a1 assertion error when trying floor(3) 2022-06-06 17:01:17 +02:00
Mateusz Piątkowski
1dbf859ee9 WIP floor and modulo implementation, not working 2022-06-04 15:32:27 +02:00
4 changed files with 27 additions and 14 deletions

2
.gitmodules vendored
View File

@ -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

View File

@ -1,15 +1,13 @@
var C = c47; var C = chord (c 3 1) (g 3 1) (c 4 1);
var E = e47; var G = chord (g 3 1) (d 4 1) (g 4 1);
var G = g47;
var A = a37;
oct 5; oct 5;
par (C 4) e e f g; par (C) e e f g;
par (G 4) g f e d; par (G) g f e d;
par (C 4) c c d e; par (C) c c d e;
par (G 4) e d d; par (G) e (d 5 (1/4)) (d 5 (1/2));
par (C 4) e e f g; par (C) e e f g;
par (G 4) g f e d; par (G) g f e d;
par (C 4) c c d e; par (C) c c d e;
par (G 4) d c; par (G) (d 4 (3/4)) c;
par (C 4) c par (C) (c 4 1)

View File

@ -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);

View File

@ -48,6 +48,13 @@ void Number::simplify_inplace()
} }
} }
auto Number::floor() const -> Number
{
auto copy = simplify();
copy = copy - (copy % Number(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