Skip to content

The asin interface loses accuracy when calculating values close to 1 #249

@happy-boy-maker

Description

@happy-boy-maker

When learning the source code of decimation.js, I found that the newly submitted pr recently modified the calculation formula of acos to avoid the loss of precision when calculating values near 1. I'm not very familiar with mathematics. However, I found that the calculation result of acos depends on asin. So when I was debugging, I separately printed the result in the formula (acos(x) = pi/2 - asin(x)), because pi is fixed, while asin has problems with the return value under different precisions. For this purpose, I compared the results of BigDecimalMath on java. Just as the correct result shows, asin loses precision when the significant bit is 31 during the calculation process. At the same time, I also found that BigDecimalMath uses the formula (acos(x) = pi/2 - asin(x)) in the calculation of acos. However, because it retains more significant bits during the calculation process and the return value of asin is correct, the correct result was finally obtained. This might be a common problem. In mathematical formulas, if a scenario like 1-x^2 occurs, it might be necessary to retain more significant bits during the calculation process. I tried to set Ctor.precision = pr + 6->Ctor.precision = pr + 8; In this way, the correct result can be obtained. Of course, the above is just a beginner's idea. If you are willing to answer, I would be very grateful!

asin(x) computed by... pr=31, x=0.9999999999999999995 pr=36, x=0.99999999999999999999995
...old method (incorrect) 1.570796325794896619231321691573 1.57079632579489661923132169159808478
...new method (correct) 1.570796325794896619231321691598 1.57079632579489661923132169159808478

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions