Rocky_Mountain_Vending/.pnpm-store/v10/files/fb/af1729287fcd1bc37b4f5e2e71d409ded6c99e412776862aac62c316607036418ffaf5ab79471bb8b4c16d751a029c6ee909579696892058ebf5a954fde249
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

34 lines
1.3 KiB
Text

import Decimal from 'decimal.js';
import { ComputeExponentForMagnitude } from './ComputeExponentForMagnitude';
import { FormatNumericToString } from './FormatNumericToString';
/**
* The abstract operation ComputeExponent computes an exponent (power of ten) by which to scale x
* according to the number formatting settings. It handles cases such as 999 rounding up to 1000,
* requiring a different exponent.
*
* NOT IN SPEC: it returns [exponent, magnitude].
*/
export function ComputeExponent(internalSlots, x) {
if (x.isZero()) {
return [0, 0];
}
if (x.isNegative()) {
x = x.negated();
}
var magnitude = x.log(10).floor();
var exponent = ComputeExponentForMagnitude(internalSlots, magnitude);
// Preserve more precision by doing multiplication when exponent is negative.
x = x.times(Decimal.pow(10, -exponent));
var formatNumberResult = FormatNumericToString(internalSlots, x);
if (formatNumberResult.roundedNumber.isZero()) {
return [exponent, magnitude.toNumber()];
}
var newMagnitude = formatNumberResult.roundedNumber.log(10).floor();
if (newMagnitude.eq(magnitude.minus(exponent))) {
return [exponent, magnitude.toNumber()];
}
return [
ComputeExponentForMagnitude(internalSlots, magnitude.plus(1)),
magnitude.plus(1).toNumber(),
];
}