Skip to content

Commit

Permalink
Rename anglicus to arabicus
Browse files Browse the repository at this point in the history
  • Loading branch information
hunter-richardson committed Jun 21, 2024
1 parent 0e753d5 commit d09b163
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/miscella/numerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import RomanNumeral from 'js-roman-numerals';

type Par = {
arabicus: number,
latinum: string;
};

export default class Numerator {
static minimus: Par = {
arabicus: 0.0,
latinum: 'N'
};

static maximus: Par = {
arabicus: 39993999.0 + (11.0 / 12.0),
latinum: '|MMMCMXCIX|MMMCMXCIXS×'
};

static fracti (): Map<number, string> {
const numeri: Map<number, string> = new Map;
numeri.set(1, '·');
numeri.set(2, ':');
numeri.set(3, '∴');
numeri.set(4, '::');
numeri.set(5, '×');
numeri.set(6, 'S');
numeri.set(7, 'S·');
numeri.set(8, 'S:');
numeri.set(9, 'S∴');
numeri.set(10, 'S::');
numeri.set(11, 'S×');
return numeri;
}

static convertibilis (arabicus: number): boolean {
return [
arabicus >= Numerator.minimus.arabicus,
arabicus <= Numerator.maximus.arabicus
].all();
}

static romanus (arabicus: number): string {
if (this.convertibilis(arabicus)) {
if (arabicus === Numerator.minimus.arabicus) {
return Numerator.minimus.latinum;
} else if (Number.isInteger(arabicus)) {
if (arabicus >= 4000) {
const inferior: number = arabicus % 4000;
const superior: number = (arabicus - inferior) / 1000;
return `|${new RomanNumeral(superior)}|${new RomanNumeral(inferior)}`;
} else {
return new RomanNumeral(arabicus).toString();
}
} else {
const integer: number = Math.floor(arabicus);
const fractus: number = 12 * (arabicus - integer);
const fractum: string | undefined = this.fracti().get(fractus);
return fractum ? this.romanus(integer).concat(fractum) : '';
}
} else {
throw new Error(`Iacta interfuturu'st valor: ${arabicus}`);
}
}

static arabicus (romanus: string): number {
const fractus: string = [
...this.fracti().values()
].first(valor => romanus.includes(valor))[0];
if (fractus) {
const numerator: number = [
...this.fracti().entries()
].first(valor => valor[ 1 ] === fractus)[0];
romanus = romanus.replace(fractus, '');
return this.arabicus(romanus) + (numerator / 12.0);
} else if (romanus === 'N') {
return 0;
} else if (romanus.startsWith('|')) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [ _, superior, inferior ] = romanus.split('|');
return (10 * this.arabicus(superior)) + this.arabicus(inferior);
} else {
return new RomanNumeral(romanus).toInt();
}
}
}

0 comments on commit d09b163

Please sign in to comment.