-
Notifications
You must be signed in to change notification settings - Fork 0
Fix BCMath::sqrt negative validation and algorithm precision issues #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
552c183
55066fe
5a53bcc
015dd75
a0d3f0d
4641ef2
adf4795
d0d231f
ef881ed
477d9a7
b1982ed
e892429
2975805
deebd4a
d54df99
ed6c176
1964a53
1eec590
13c0cc2
83ca621
ca08de6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -238,18 +238,57 @@ private static function checkEarlyZero(string $num1, string $num2, int $scale): | |||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Check for division by zero and throw exception. | ||||||||||
| * Check if a numeric string represents zero. | ||||||||||
| * | ||||||||||
| * @throws \DivisionByZeroError If divisor is zero | ||||||||||
| * Handles various zero formats: '0', '0.00', '-0.00', '+0.000', etc. | ||||||||||
| * Uses consistent normalization logic for reliable zero detection. | ||||||||||
| * | ||||||||||
| * Examples of inputs that return true: | ||||||||||
| * - '0', '0.0', '0.00', '0.000' | ||||||||||
| * - '-0', '-0.0', '-0.00', '-0.000' | ||||||||||
| * - '+0', '+0.0', '+0.00', '+0.000' | ||||||||||
| * - '00', '00.00', '000.000' | ||||||||||
| * | ||||||||||
| * Examples of inputs that return false: | ||||||||||
| * - '1', '0.1', '0.001', '-0.001' | ||||||||||
| * - 'abc', '', '.' | ||||||||||
| * | ||||||||||
| * @param string $number The numeric string to check | ||||||||||
| * | ||||||||||
| * @return bool True if the number is zero, false otherwise | ||||||||||
| */ | ||||||||||
| private static function checkDivisionByZero(string $divisor): void | ||||||||||
| private static function isZero(string $number): bool | ||||||||||
| { | ||||||||||
| // Normalize and check for zero - handle '0', '0.00', '-0.00', etc. | ||||||||||
| $normalized = ltrim($divisor, '+-'); | ||||||||||
| $normalized = ltrim($number, '+-'); | ||||||||||
| $normalized = ltrim($normalized, '0'); | ||||||||||
| $normalized = ltrim($normalized, '.'); | ||||||||||
| $normalized = rtrim($normalized, '0'); | ||||||||||
| if ($normalized === '' || $normalized === '.') { | ||||||||||
|
|
||||||||||
| return $normalized === '' || $normalized === '.'; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Check if a string starts with a negative sign after trimming whitespace. | ||||||||||
| * | ||||||||||
| * @param string $num The string to check | ||||||||||
| * | ||||||||||
| * @return bool True if the string starts with '-' after trimming, false otherwise | ||||||||||
| */ | ||||||||||
| private static function startsWithNegativeSign(string $num): bool | ||||||||||
| { | ||||||||||
| $trimmed = ltrim($num); | ||||||||||
|
|
||||||||||
| return $trimmed !== '' && $trimmed[0] === '-'; | ||||||||||
|
Comment on lines
+279
to
+281
|
||||||||||
| $trimmed = ltrim($num); | |
| return $trimmed !== '' && $trimmed[0] === '-'; | |
| return $num !== '' && $num[0] === '-'; |
Copilot
AI
Sep 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The startsWithNegativeSign method calls ltrim($num) which could be expensive for large strings. Since we're only checking the first character after trimming, consider using a more direct approach or caching the trimmed result.
Uh oh!
There was an error while loading. Please reload this page.