Remove one of the sources of cyclic dependencies
This commit is contained in:
parent
f664399a8c
commit
22b2f162bc
|
@ -1,10 +1,9 @@
|
||||||
import { Tag } from "./constants";
|
import { Tag } from "./constants";
|
||||||
import { stringify } from "./text";
|
|
||||||
import { Value } from "./values";
|
import { Value } from "./values";
|
||||||
import type { GenericEmbedded } from "./embedded";
|
import type { GenericEmbedded } from "./embedded";
|
||||||
import type { Encoder, Preservable } from "./encoder";
|
import type { Encoder, Preservable } from "./encoder";
|
||||||
import type { Writer, PreserveWritable } from "./writer";
|
import type { Writer, PreserveWritable } from "./writer";
|
||||||
import { Bytes, dataview, underlying } from "./bytes";
|
import { Bytes, dataview } from "./bytes";
|
||||||
|
|
||||||
export type FloatType = 'Single' | 'Double';
|
export type FloatType = 'Single' | 'Double';
|
||||||
export const FloatType = Symbol.for('FloatType');
|
export const FloatType = Symbol.for('FloatType');
|
||||||
|
@ -16,8 +15,8 @@ export abstract class Float {
|
||||||
this.value = typeof value === 'number' ? value : value.value;
|
this.value = typeof value === 'number' ? value : value.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
__preserve_text_on__(w: Writer<any>) {
|
||||||
return stringify(this);
|
w.state.pieces.push(this.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract toBytes(): Bytes;
|
abstract toBytes(): Bytes;
|
||||||
|
@ -113,11 +112,11 @@ export class SingleFloat extends Float implements Preservable<any>, PreserveWrit
|
||||||
return bs;
|
return bs;
|
||||||
}
|
}
|
||||||
|
|
||||||
__preserve_text_on__(w: Writer<any>) {
|
toString(): string {
|
||||||
if (Number.isFinite(this.value)) {
|
if (Number.isFinite(this.value)) {
|
||||||
w.state.pieces.push(floatlikeString(this.value) + 'f');
|
return floatlikeString(this.value) + 'f';
|
||||||
} else {
|
} 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;
|
return bs;
|
||||||
}
|
}
|
||||||
|
|
||||||
__preserve_text_on__(w: Writer<any>) {
|
toString(): string {
|
||||||
if (Number.isFinite(this.value)) {
|
if (Number.isFinite(this.value)) {
|
||||||
w.state.pieces.push(floatlikeString(this.value));
|
return floatlikeString(this.value);
|
||||||
} else {
|
} else {
|
||||||
w.state.pieces.push('#xd"', this.toBytes().toHex(), '"');
|
return '#xd"' + this.toBytes().toHex() + '"';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue