AdamWhiteHat / BigDecimal

An arbitrary-precision decimal (base 10) floating-point number class. Over 2.5 million downloads on NuGet!
MIT License
53 stars 15 forks source link

Pulling over the changes from my latest Incremental-Updates branch. #24

Closed Protiguous closed 8 months ago

Protiguous commented 8 months ago

All the faster tests still seem to pass, which should be expected as I have not made any functional changes yet. The newer tests, the “Trig” ones, are taking many minutes just to complete for each target framework.

I will look into them if time permits. And I may just about be ready to start sprinkling in some caching for any expensive calculations.

AdamWhiteHat commented 8 months ago

Regarding the Trig function tests: Yes, I am aware. The trig functions accomplish what they do using a Taylor series. The Taylor series is great and all, but it is known to converge very slowly for certain series on certain inputs. The functions that suffer from slow convergence is Arctan, and the two function Arcsin and Arccos, which utilize Arctan under the hood.

I have been looking into replacing the Taylor series in the Arctan function with something else that will be more performant for a while now.

Alternatives include:

Continued fractions is probably the route I'm going to go, as I already have experience (and a library) working with them, and they should enable taking the terms iteratively, incrementally increasing the precision of the estimate until the desired precision is reached, like the Taylor series does.

Id just skip the tests for now. I could also break them down more. Each trig test function calls Test_TrigFunction twice: Once for positive inputs, and once for negative inputs. And each Test_TrigFunction call tests the trig function being passed in 15 times, so a total of 30 calls to the trig function under test, per test.

The time it takes for each individual Arctan call to converge (of which there is 30 of them per test) can vary wildly, from 2ms to 5000ms.

Anyways, I think I finally made a breakthrough with the Continued fraction implementation. A change should hopefully be coming within a week or two (I have very limited time. I work myself to death at my day-job.).