Skip to content

The square root operator implementation for fixed-point numbers #9

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

Merged
merged 17 commits into from
Apr 8, 2025

Conversation

blewater
Copy link
Contributor

  • Added the core sqrt function to Fixed, calculating the scaled square root and remainder.
  • Uses i128 for intermediate calculations (t = input.0 * SCALE_FACTOR) to avoid overflow.
  • Includes int_sqrt helper using Newton's method for u64.
  • Lots of unit tests for operator and constraint evaluation.

eval_fixed_sqrt Constraint (eval.rs):
Enforces the constraint out^2 + rem = input * SCALE_FACTOR

Copy link
Contributor

@raphaelDkhn raphaelDkhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice implementation @blewater, thanks! I just added some optimizations to avoid using i128. And I added a constraint to make sure the input is non-negative.

@raphaelDkhn raphaelDkhn merged commit 9a9f094 into gizatechxyz:master Apr 8, 2025
1 check passed
@raphaelDkhn
Copy link
Contributor

@all-contributors add @blewater for code

Copy link
Contributor

@raphaelDkhn

I've put up a pull request to add @blewater! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants