Skip to content

Commit

Permalink
feat(math): Add warning for invalid precision in BN format method
Browse files Browse the repository at this point in the history
Added a warning when precision is less than minPrecision in the BN.format method.
This maintains backward compatibility while alerting users to potential issues.
The warning suggests setting precision >= minPrecision for correct behavior.

Resolves TODO in packages/math/src/bn.ts
  • Loading branch information
VolodymyrBg authored Jan 14, 2025
1 parent ebe5ecd commit 5f9bea4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/math/src/bn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,15 @@ export class BN extends BnJs implements BNInputOverrides, BNHiddenTypes, BNHelpe
return this.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

// Adjust precision and minPrecision
// TODO: This really should throw an error because you can't have a precision less than the minPrecision but this would be a breaking change
// Warn if precision is less than minPrecision
if (initialPrecision < initialMinPrecision) {
console.warn(
`Warning: precision (${initialPrecision}) is less than minPrecision (${initialMinPrecision}). ` +
'This may lead to unexpected behavior. Consider setting precision >= minPrecision.'
);
}

// Adjust precision and minPrecision to maintain backward compatibility
const minPrecision =
initialMinPrecision > initialPrecision ? initialPrecision : initialMinPrecision;
const precision =
Expand Down

0 comments on commit 5f9bea4

Please sign in to comment.