Refactor to use BcMath\Number for internal storage#3
Open
barryvdh-bot wants to merge 9 commits intofruitcake:mainfrom
Open
Refactor to use BcMath\Number for internal storage#3barryvdh-bot wants to merge 9 commits intofruitcake:mainfrom
barryvdh-bot wants to merge 9 commits intofruitcake:mainfrom
Conversation
BREAKING CHANGES: - Minimum PHP version is now 8.4 (for BcMath\Number class) - Added ext-bcmath as required extension Changes: - Internal value storage now uses BcMath\Number instead of unit values - Internal calculations use scale 20 for higher precision - Added getValue() method to access internal BcMath\Number - toString() now accepts optional precision parameter - Updated tests for new implementation - Added tests for high precision scenarios This provides better precision for complex calculations while maintaining backwards compatibility with the existing API.
- Update run-tests.yml to only test PHP 8.4 and 8.5 - Update coverage.yml to use PHP 8.4 - Update phpunit-matcher.yml to use PHP 8.4 - Add bcmath and intl extensions to CI - Update to actions/checkout@v4 - Remove deprecated --no-suggest flag
- isZero() now checks if value rounds to zero at display precision - isPositive/isNegative respect the isZero check - toNumber() handles very small floats (< 1e-14) as zero to avoid scientific notation - Use number_format instead of sprintf to avoid scientific notation issues
Pre-round floats to 10 decimal places to correct floating-point representation errors before converting to BcMath\Number. e.g., 1.345 in float is ~1.34499999... which should round to 1.35, not 1.34
- testConstructWithNumber: Number in constructor - testArithmeticWithNumber: Number in add/sub/multiply/divide - testComparisonWithNumber: Number in comparisons
Fixes: - All comparison methods now use display precision for consistency - Division by zero now throws DivisionByZeroError New features: - compare() method returning -1, 0, 1 - abs() method for absolute value - negate() method to change sign - parseLocale() accepts optional locale parameter (null = system default) - Support for negative precision in toString() Tests added for all new functionality
- Default locale back to 'nl_NL' for backwards compatibility - Fix testComparisonConsistency: 1.006 rounds to 1.01, not 1.00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the Decimal class to use PHP 8.4's
BcMath\Numberclass for internal value storage instead of unit values with precision multipliers.Breaking Changes
BcMath\Numberclass)ext-bcmathas a required extensionChanges
Internal Storage
BcMath\Numberinstances instead of string unit valuesNew Features
getValue()method to access the internalBcMath\NumberinstancetoString()now accepts an optional precision parameter for custom output precisionImprovements
Backwards Compatibility
The public API remains the same:
getUnitValue()still works for backwards compatibilityTests
Added new tests for:
This PR was created by Borry 🤖