Skip to content

More efficient rounding#42

Open
arash-binary wants to merge 28 commits intoderiv-com:masterfrom
arash-binary:underlyings/refactor_pip_size
Open

More efficient rounding#42
arash-binary wants to merge 28 commits intoderiv-com:masterfrom
arash-binary:underlyings/refactor_pip_size

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