1/**
 2 * Floating-point precision utilities
 3 *
 4 * Provides functions to normalize floating-point numbers for consistent comparison
 5 * and display, addressing JavaScript's floating-point precision issues.
 6 */
 7
 8import { PRECISION_MULTIPLIER } from '$lib/constants/precision';
 9
10/**
11 * Normalize floating-point numbers for consistent comparison
12 * Addresses JavaScript floating-point precision issues (e.g., 0.949999988079071 → 0.95)
13 */
14export function normalizeFloatingPoint(value: unknown): unknown {
15	return typeof value === 'number'
16		? Math.round(value * PRECISION_MULTIPLIER) / PRECISION_MULTIPLIER
17		: value;
18}
19
20/**
21 * Type-safe version that only accepts numbers
22 */
23export function normalizeNumber(value: number): number {
24	return Math.round(value * PRECISION_MULTIPLIER) / PRECISION_MULTIPLIER;
25}