UNPKG

@formatjs/ecma402-abstract

Version:

A collection of implementation for ECMAScript abstract operations

16 lines (15 loc) 646 B
import { Decimal } from "@formatjs/bigdecimal"; import { memoize } from "@formatjs/fast-memoize"; /** * Cached function to compute powers of 10 for Decimal.js operations. * This cache significantly reduces overhead in ComputeExponent and ToRawFixed * by memoizing expensive Decimal.pow(10, n) calculations. * * Common exponents (e.g., -20 to 20) are used repeatedly in number formatting, * so caching provides substantial performance benefits. * * @param exponent - Can be a number or Decimal. If Decimal, it will be converted to string for cache key. */ export const getPowerOf10 = memoize((exponent) => { return Decimal.pow(10, exponent); });