Skip to content
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

More efficient rounding #42

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

arash-binary
Copy link

Math::BigFloat is one of the reasons pip sizing is so slow
Replace it with Math::Round

Math::BigFloat is one of the reasons pip sizing is so slow
Replace it with Math::Round
Test roundcommon for a set of numbers in a range
@junbon-deriv
Copy link
Contributor

we probably need a PR in regentmarkets/cpan for this to work?

Numbers like 0.5 has floating point issues for very big precisions.
For instance you get 0.499999999999999944 for 0.5 with 18 decimal
point precision.
By turning this number into string as the input of sprintf, we avoid
this issue
In crypto repo we use `roundcommon` function for precisions up to 18
digits. This is while double precision data types can hold up to
around 15 digits numbers. So we use the BigFloat for big numbers and
keep nearest for smaller numbers (faster!)
Count the digits and based on that choose which technique to use
nearest function does not do any magic. It's rather easy to understand
what's happening in the code.
The tricky part if when to swtich to Math::BigFloat
@arash-binary arash-binary changed the title Use Math::Round for rounding More efficient rounding Nov 25, 2021
Since in here we only want to do rounding and no mathematical operation
is happening, we will do our rounding based on string values
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.

3 participants