Remove one of the sources of cyclic dependencies

This commit is contained in:
Tony Garnock-Jones 2023-11-19 15:54:01 +01:00
parent f664399a8c
commit 22b2f162bc
1 changed files with 9 additions and 10 deletions

View File

@ -1,10 +1,9 @@
import { Tag } from "./constants";
import { stringify } from "./text";
import { Value } from "./values";
import type { GenericEmbedded } from "./embedded";
import type { Encoder, Preservable } from "./encoder";
import type { Writer, PreserveWritable } from "./writer";
import { Bytes, dataview, underlying } from "./bytes";
import { Bytes, dataview } from "./bytes";
export type FloatType = 'Single' | 'Double';
export const FloatType = Symbol.for('FloatType');
@ -16,8 +15,8 @@ export abstract class Float {
this.value = typeof value === 'number' ? value : value.value;
}
toString() {
return stringify(this);
__preserve_text_on__(w: Writer<any>) {
w.state.pieces.push(this.toString());
}
abstract toBytes(): Bytes;
@ -113,11 +112,11 @@ export class SingleFloat extends Float implements Preservable<any>, PreserveWrit
return bs;
}
__preserve_text_on__(w: Writer<any>) {
toString(): string {
if (Number.isFinite(this.value)) {
w.state.pieces.push(floatlikeString(this.value) + 'f');
return floatlikeString(this.value) + 'f';
} else {
w.state.pieces.push('#xf"', this.toBytes().toHex(), '"');
return '#xf"' + this.toBytes().toHex() + '"';
}
}
@ -157,11 +156,11 @@ export class DoubleFloat extends Float implements Preservable<any>, PreserveWrit
return bs;
}
__preserve_text_on__(w: Writer<any>) {
toString(): string {
if (Number.isFinite(this.value)) {
w.state.pieces.push(floatlikeString(this.value));
return floatlikeString(this.value);
} else {
w.state.pieces.push('#xd"', this.toBytes().toHex(), '"');
return '#xd"' + this.toBytes().toHex() + '"';
}
}