Skip to content

Commit

Permalink
Tweak universal format of real zero
Browse files Browse the repository at this point in the history
  • Loading branch information
frostburn committed May 14, 2024
1 parent ccaaff8 commit ab41036
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/interval.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
12 changes: 2 additions & 10 deletions src/monzo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 7 additions & 0 deletions src/parser/__tests__/expression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit ab41036

Please sign in to comment.