UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

57 lines 1.85 kB
/** * Pick the index into {@link MAGNITUDE_PREFIXES} / {@link MAGNITUDE_SCALES} that best represents * `value`. * * "Best" here means: when `value` is divided by `MAGNITUDE_SCALES[i]`, the result lies in * `[1, 1000)` whenever possible. The sign of `value` is ignored — magnitude is what matters. * * Edge cases: * - `0`, `NaN` or any non-finite value returns the neutral index (no prefix, scale = 1) * - values smaller than `MAGNITUDE_SCALES[0]` clamp to the smallest prefix * - values larger than `MAGNITUDE_SCALES[MAX_INDEX]` clamp to the largest prefix * * @param {number} value * @returns {number} */ export function magnitude_prefix_index(value: number): number; /** * Get the SI prefix string that best represents `value`. * * @example * magnitude_prefix(1000) // 'k' * magnitude_prefix(0.001) // 'm' * magnitude_prefix(1) // '' * magnitude_prefix(1.5e9) // 'G' * * @param {number} value * @returns {string} */ export function magnitude_prefix(value: number): string; /** * Get the decimal scale that pairs with {@link magnitude_prefix} for the same input. * * @example * magnitude_scale(1000) // 1000 * magnitude_scale(0.001) // 0.001 * * @param {number} value * @returns {number} */ export function magnitude_scale(value: number): number; /** * SI decimal prefixes, ordered from smallest to largest. Indexed by {@link magnitude_prefix_index}. * * Covers the full SI prefix range: `q` (quecto, 1e-30) through `Q` (quetta, 1e30). * * @type {string[]} */ export const MAGNITUDE_PREFIXES: string[]; /** * Decimal scale that matches each prefix in {@link MAGNITUDE_PREFIXES}, same indexing. * * A non-prefixed value at index `i` corresponds to scale `10^(3*(i - 10))`. * * @type {number[]} */ export const MAGNITUDE_SCALES: number[]; //# sourceMappingURL=magnitude_prefix.d.ts.map