UNPKG

@node-dlc/messaging

Version:
147 lines (146 loc) 3.77 kB
/// <reference types="node" /> import Decimal from 'decimal.js'; /** * IEEE 754 double-precision floating-point number implementation * * Format: 1 bit sign + 11 bits exponent + 52 bits mantissa * * This class works directly with the binary representation to avoid * precision loss when serializing/deserializing f64 values to/from buffers. */ export declare class F64 { private _buffer; /** * Create an F64 from raw bytes (IEEE 754 format) */ constructor(buffer?: Buffer); /** * Create F64 from JavaScript number */ static fromNumber(num: number): F64; /** * Create F64 from Decimal.js value * Uses the most precise conversion possible */ static fromDecimal(decimal: Decimal): F64; /** * Create F64 from string representation * Uses Decimal.js to parse the string without precision loss from JavaScript Number */ static fromString(str: string): F64; /** * Create F64 from bigint (treating as integer value) */ static fromBigInt(bigint: bigint): F64; /** * Create F64 representing zero (static method for API compatibility) */ static zero(): F64; /** * Create F64 with specific IEEE 754 components */ static fromComponents(sign: boolean, exponent: number, mantissa: bigint): F64; /** * Get the raw buffer containing IEEE 754 representation */ getBuffer(): Buffer; /** * Serialize to buffer (big-endian) */ serialize(): Buffer; /** * Deserialize from buffer (big-endian) */ static deserialize(buffer: Buffer): F64; /** * Convert to JavaScript number * This may lose precision for very large or very precise values */ toNumber(): number; /** * Convert to Decimal.js for arbitrary precision */ toDecimal(): Decimal; /** * Extract IEEE 754 components */ getComponents(): { sign: boolean; exponent: number; mantissa: bigint; }; /** * Check if the value is finite */ isFinite(): boolean; /** * Check if the value is NaN */ isNaN(): boolean; /** * Check if the value is infinite */ isInfinite(): boolean; /** * Check if the value is zero */ isZero(): boolean; /** * Get string representation */ toString(): string; /** * Convert to JSON-safe value: number if within safe range, string if too large * This preserves precision for very large numbers that exceed JavaScript's MAX_SAFE_INTEGER */ toJSONValue(): number | string; /** * Create F64 from JSON value (handles both number and string inputs) */ static fromJSONValue(value: number | string): F64; /** * Get hex representation of the raw bytes */ toHex(): string; /** * Create F64 from hex string */ static fromHex(hex: string): F64; /** * Compare with another F64 */ equals(other: F64): boolean; /** * Equality comparison (alias for equals, for API compatibility) */ eq(other: F64 | number): boolean; /** * Greater than comparison */ gt(other: F64 | number): boolean; /** * Less than comparison */ lt(other: F64 | number): boolean; /** * Greater than or equal comparison */ gte(other: F64 | number): boolean; /** * Less than or equal comparison */ lte(other: F64 | number): boolean; /** * Create a copy */ clone(): F64; /** * Constants */ static get ZERO(): F64; static get ONE(): F64; static get NEGATIVE_ONE(): F64; static get INFINITY(): F64; static get NEGATIVE_INFINITY(): F64; static get NaN(): F64; }