From ab41036a451e25fb70f455a6cb4daf9bbdef807d Mon Sep 17 00:00:00 2001 From: Lumi Pakkanen Date: Tue, 14 May 2024 09:36:23 +0300 Subject: [PATCH] Tweak universal format of real zero --- src/__tests__/interval.spec.ts | 2 +- src/monzo.ts | 12 ++---------- src/parser/__tests__/expression.spec.ts | 7 +++++++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/__tests__/interval.spec.ts b/src/__tests__/interval.spec.ts index b32040b4..b6799407 100644 --- a/src/__tests__/interval.spec.ts +++ b/src/__tests__/interval.spec.ts @@ -118,7 +118,7 @@ describe('Interchange format', () => { it('has an expression for real zero', () => { const interval = new Interval(TimeReal.fromValue(0), 'linear'); interval.node = interval.asMonzoLiteral(true); - expect(interval.toString()).toBe('[1 0.>@0.rc'); + expect(interval.toString()).toBe('[-1>@inf'); }); it('has an expression for real -2', () => { diff --git a/src/monzo.ts b/src/monzo.ts index 2736ce9c..1aadd3b5 100644 --- a/src/monzo.ts +++ b/src/monzo.ts @@ -789,16 +789,8 @@ export class TimeReal { basis.push({numerator: -1, denominator: null, radical: false}); components.push({sign: '', left: 1, right: '', exponent: null}); } else if (this.value === 0) { - basis.push({numerator: 0, denominator: null, radical: false}); - components.push({sign: '', left: 1, right: '', exponent: null}); - basis.push('rc'); - components.push({ - sign: '', - left: 0, - separator: '.', - right: '', - exponent: null, - }); + basis.push('inf'); + components.push({sign: '-', left: 1, right: '', exponent: null}); return {type: 'MonzoLiteral', components, ups: 0, lifts: 0, basis}; } if (!isFinite(this.value)) { diff --git a/src/parser/__tests__/expression.spec.ts b/src/parser/__tests__/expression.spec.ts index 797490c7..c596124e 100644 --- a/src/parser/__tests__/expression.spec.ts +++ b/src/parser/__tests__/expression.spec.ts @@ -2403,4 +2403,11 @@ describe('Poor grammar / Fun with "<"', () => { expect(interval.isAbsolute()).toBe(true); expect(interval.valueOf()).toBe(-Infinity); }); + + it('parses the universal real zero', () => { + const interval = evaluate('[-1>@inf') as Interval; + expect(interval.isAbsolute()).toBe(false); + expect(interval.valueOf()).toBe(0); + expect(interval.value).toBeInstanceOf(TimeReal); + }); });