UNPKG

@technobuddha/library

Version:
30 lines (29 loc) 1.13 kB
import { type DeconstructedNumber } from './@types/deconstructed-number.ts'; /** * Deconstructs a number into its sign, value, mantissa, and exponent, and separates its whole and fractional parts. * @param input - The number to deconstruct. Must be a finite number. * @param precision - The number of significant digits to use (default: 9, min: 1, max: 15). * @returns An object containing the normalized value, sign, mantissa, exponent, and separate representations * of the whole and fractional parts. * @throws `TypeError` If the input is NaN or not a finite number. * @example * ```typescript * const result = deconstructNumber(123.456); * // result = { * // value: 123.456, * // sign: 1, * // mantissa: "123456", * // exponent: 2, * // whole: { ... }, * // fraction: { ... } * // } * ``` * @group Math * @category Number */ export declare function deconstructNumber(input: number, precision?: number): DeconstructedNumber & { /** The fractional part of the number. */ fractional: DeconstructedNumber; /** The whole part of the number. */ whole: DeconstructedNumber; };