Upgrade Fix64/UFix64 to use github.com/onflow/fixed-point library #4285
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.
Closes #4127
Description
This PR upgrades
Fix64ValueandUFix64Valueto use thegithub.com/onflow/fixed-pointlibrary, following the same pattern asFix128Value/UFix128Value. This is a draft PR for initial review.Link to Devin run: https://app.devin.ai/sessions/3d6a099b4b7b4a5c84c4162298b7922f
Requested by: [email protected]
Key Changes
Type definitions (
interpreter/value_fix64.go,interpreter/value_ufix64.go):type Fix64Value int64totype Fix64Value fix.Fix64type UFix64Value struct { UFix64Value values.UFix64Value }totype UFix64Value fix.UFix64func() fix.Fix64andfunc() fix.UFix64callbacks.Add(),.Sub(),.Mul(),.Div(),.Mod().Lt(),.Lte(),.Gt(),.Gte()Added utility functions (
fixedpoint/convert.go,fixedpoint/check.go):Fix64FromBigInt(),Fix64ToBigInt(),UFix64FromBigInt(),UFix64ToBigInt()Fix64FactorAsBigIntandUFix64FactorAsBigIntconstantsUpdated call sites:
bbq/compiler/compiler.go: Cast values when creating constantsinterpreter/decode.go: Updated CBOR decodinginterpreter/interpreter.go: Fixed string parsers and min/max constantsstdlib/account.go: Addedfix.UFix64(balance)conversions for account balancesCritical Areas for Review
Type conversions in
stdlib/account.go:484,510: Verify thatfix.UFix64(balance)correctly converts rawuint64balance values to the scaled fixed-point representationSaturation arithmetic behavior: The old code used custom
SaturatingPlus/SaturatingMinusmethods; the new code manually handles overflow by returningfix.UFix64Max/fix.UFix64Zero. Verify semantics match.Storage encoding/decoding: Changes to CBOR encoding in
value_ufix64.go- verify roundtrip correctnessArithmetic precision: All arithmetic operations now use
fix.RoundTruncate- verify this matches expected behaviorInterface completeness: While the code compiles and implements
atree.Storable,NumberValue, etc., verify all requirements are metTesting Status
Checklist:
masterbranchFiles changedin the Github PR explorer