Felix Roos 3c56f24eed build
2022-03-19 19:30:29 +01:00

46 lines
1.2 KiB
JavaScript

import Fraction from "../pkg/fractionjs.js";
import {TimeSpan} from "./strudel.js";
Fraction.prototype.sam = function() {
return this.floor();
};
Fraction.prototype.nextSam = function() {
return this.sam().add(1);
};
Fraction.prototype.wholeCycle = function() {
return new TimeSpan(this.sam(), this.nextSam());
};
Fraction.prototype.lt = function(other) {
return this.compare(other) < 0;
};
Fraction.prototype.gt = function(other) {
return this.compare(other) > 0;
};
Fraction.prototype.lte = function(other) {
return this.compare(other) <= 0;
};
Fraction.prototype.gte = function(other) {
return this.compare(other) >= 0;
};
Fraction.prototype.eq = function(other) {
return this.compare(other) == 0;
};
Fraction.prototype.max = function(other) {
return this.gt(other) ? this : other;
};
Fraction.prototype.min = function(other) {
return this.lt(other) ? this : other;
};
Fraction.prototype.show = function() {
return this.s * this.n + "/" + this.d;
};
Fraction.prototype.or = function(other) {
return this.eq(0) ? other : this;
};
const fraction = (n) => {
if (typeof n === "number") {
n = String(n);
}
return Fraction(n);
};
export default fraction;