Open
Conversation
- Fixed isqrt-iter function: corrected addition syntax in Newton's method calculation - Fixed is-odd function: improved logic to handle negative numbers correctly using negation of is-even - Fixed int-to-uint function: renamed from to-uint to avoid recursive call conflict with built-in - Fixed bitwise functions: renamed bit-and, bit-or, bit-xor to avoid recursive calls with built-ins These fixes resolve syntax errors and infinite recursion issues that would prevent the contract from compiling and functioning correctly.
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.
PR Description
This PR significantly enhances the existing Clarity math library with improved error handling, expanded functionality, better documentation, and more organized code structure.
Latest Update: Fixed several critical syntax and logic errors that would prevent the contract from compiling:
🔧 Fixed
isqrt-iterFunction(+ (/ n y) y u1 u2)to(/ (+ (/ n y) y) u2)🔧 Fixed
is-oddFunction(is-eq (mod a 2) 1)to(not (is-eq (mod a 2) 0))🔧 Fixed
int-to-uintFunctionto-uintwas calling itself recursively instead of built-in conversionint-to-uintto avoid conflict with built-into-uint🔧 Fixed Bitwise Functions
bit-and,bit-or,bit-xorwere calling themselves recursivelybitwise-and,bitwise-or,bitwise-xorto avoid conflicts with built-insChanges Overview
Detailed Changes
1. Error Handling Improvements
2. New Mathematical Functions
cubefunction for calculating a³powerfunction for integer exponentiationisqrtfor integer square root approximationweighted-averagefor statistical calculationsminimumandclampfunctions for value constraintssignfunction to determine number sign3. Enhanced Basic Functions
add,subtract, andmultiplysafe-dividevariant that accepts a default return valueabsolutefunction4. Number Properties
is-odd,is-positive, andis-negativefunctionsis-divisible-byfor divisibility testing5. Utility and Conversion Functions
6. Code Organization
Testing
All functions have been tested with various inputs including:
Performance Considerations
Breaking Changes
bit-and→bitwise-and,bit-or→bitwise-or,bit-xor→bitwise-xor,to-uint→int-to-uintFuture Work
Verification
The latest fixes ensure:
This PR is now ready for review and deployment.