-
Notifications
You must be signed in to change notification settings - Fork 17
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
Enhance the precision of fixed-point square root computations #16
Conversation
cab4dc4
to
c521fcb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase the latest main
branch to enable CI pipeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve the git commit messages by using complete sentences and making them informative.
You should avoid submitting pull requests via the In this case, you should perform the following steps to resolve the unintended conflicts: $ git remote add upstream https://github.com/sysprog21/mado
$ git fetch upstream
$ git reset --hard 65fa6e742a6bc16b31b6b41d3dec722857298a7f
$ git cherry-pick origin/main
$ git rebase upstream/main After verifying via Improve your skills with Git by watching the videos: https://hackmd.io/@sysprog/git-with-github |
ac884a2
to
053eba6
Compare
if (as <= 0) | ||
return 0; | ||
if (CHECK_INTERVAL(as, TWIN_SFIXED_ONE, (1 << (2 - 1)))) | ||
return TWIN_SFIXED_ONE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is used to find an approximation of sin and cos values. However, this method makes it hard to calculate the square root when the numbers are near 1, which causes the wrong approximation of sin and cos values, especially when the radian is near pi/2 or 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two figures below are sin and cos value calculted with (first) and without (second) CHECK_INTERVAL. Test on rv32emu/tests/line.c.
The current square root calculation for fixed-point numbers cannot handle values less than 1 accurately. To improve precision, replace the existing method with the digit-by-digit calculation method. This approach, combined with offset manipulation, will minimize precision loss during the square root calculation.
Thank @marvin0102 for contributing! |
The original fixed point sqrt can not calculate sqrt of numbers less than 1. Implement a new sqrt calculation that is more precise and without fixed point multiplication.
Below is the comparison of sqrt from 0~2. "math.h" stands for function 'sqrt()' from library math.h. "original" stands for original sqrt implementation. "precise" stands for new implemented method.