Repository navigation
Fix edge-case bugs in Decimal arithmetic, comparisons, and null handling - #67
Open
alvaro9rqc wants to merge 2 commits into
Open
alvaro9rqc wants to merge 2 commits into
alvaro9rqc wants to merge 2 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Author
|
Updated in ab90c8e:
|
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
While auditing
org.fhir.ucum.Decimal(using JML/OpenJML static verification and JUnit tests), we identified and fixed five edge-case defects:0 / 0silently returning0indoDivide():isZero()was checked beforeother.isZero(), sonew Decimal("0").divide(new Decimal("0"))returned0instead of throwingUcumException. Reordered the check so dividing by zero always throwsUcumException.Error("Unhandled")indoAdd()/doSubtract()for values< 0.1or scaled scientific notation: Whenmax < 0(e.g.,0.01 + 0.01,0.05 - 0.01) ormax > s3.length()(e.g.,1e3 + 1e3), both methods threwnew Error("Unhandled"). Added proper zero-padding for both branches.Decimal(String)andDecimal(String, int)now throwUcumExceptiononnullinput (and negativeprecision) instead ofNullPointerException;equals(Decimal, Decimal)returnsfalseonnullarguments andlimitPrecisionTo(Decimal)ignoresnull.comparesTo():new Decimal("-0").comparesTo(new Decimal("0"))previously returned-1, contradictingequals(Object)(true) andtoString()("0"). Normalized zero operands before sign comparison.stringSubtraction(): Replaced the string-mutatingreplaceCharborrow approach (which temporarily wrote'/'on chained borrows across'0'and ran in O(n²)) with a standard O(n)borrowvariable, removing the now-unusedreplaceCharhelper.Testing
UcumDecimalTestscovering all five fixes (testDivideByZero,testAddSubtractSmallAndScientificValues,testNullAndPrecisionGuards,testNegativeZeroComparisonConsistency).mvn package -P CHECKSTYLE(617/617 tests passing, 0 Checkstyle violations).Note: Analysis, patch drafting, and test verification were assisted by AI tools and reviewed manually.