Refactor Fixed type to use runtime scale#18
Merged
Conversation
…s. Update Fixed struct to store scale as a field, modify related methods, and adjust tests for new Fixed implementation.
… subtraction, multiplication, division, remainder, and square root. Utilize random number generation for extensive coverage and edge case handling.
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.
Refactor Fixed type to use runtime scale and simplify evaluation tests. Update Fixed struct to store scale as a field, modify related methods, and adjust tests for new Fixed implementation.
Pull Request type
Please check the type of change your PR introduces:
What is the current behavior?
Issue Number: N/A
Previously we used const generics to set the scale of a
Fixednumber at compile time. This approach required specifying the scale as a type parameter (Fixed<SCALE>) and made it impossible to have dynamic scale values at runtime. This limitation prevented integration with LuminAir's dynamic fixed-point scale requirements.What is the new behavior?
Fixedstruct now stores scale as a runtime field instead of a const generic parameterFixed::from_f64(value, scale)orFixed::new(value, scale)from_f64_8(),from_f64_12(), etc. for common scalesscale(),value(),convert_to(),zero())Key Changes:
Fixed<const SCALE: u32>(i64)→Fixed { value: i64, scale: u32 }from_f64(value)→from_f64(value, scale)Does this introduce a breaking change?
Breaking Changes:
Fixed::from_f64()calls now require a scale parameterFixed<SCALE>becomesFixed(no const generic).0field access becomes.valuefield accessMigration Path:
Testing
Other information
This refactoring enables dynamic scale selection which is essential for LuminAir integration. The change maintains all existing functionality while providing the flexibility needed for runtime scale determination.
Files Changed:
src/lib.rs- Main Fixed type refactoring and comprehensive test restorationsrc/eval.rs- Updated evaluation tests to use runtime scale APITest Coverage: