diff --git a/implementations/javascript/packages/core/src/float.ts b/implementations/javascript/packages/core/src/float.ts index 4ef7283..14a185c 100644 --- a/implementations/javascript/packages/core/src/float.ts +++ b/implementations/javascript/packages/core/src/float.ts @@ -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) { + w.state.pieces.push(this.toString()); } abstract toBytes(): Bytes; @@ -113,11 +112,11 @@ export class SingleFloat extends Float implements Preservable, PreserveWrit return bs; } - __preserve_text_on__(w: Writer) { + 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, PreserveWrit return bs; } - __preserve_text_on__(w: Writer) { + 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() + '"'; } }