Answer the question
In order to leave comments, you need to log in
How to bypass the double precision limit in C#?
There are two problems.
1. Two numbers are given - the range in which the solution of the equation is located. The search for a solution is made by dividing the segment in half. This is due to the fact that other methods of solution (for example, the method of chords or the method of tangents) are extremely inefficient and most often do not converge.
The problem is that if the boundaries of the segment are very small values, then when obtaining the middle of the segment, we get one of the boundary values, instead of the average. For example:
x1 = 0.00000000000000030426102110965129;
x2 = 0.00000000000000030426102110965134;
We get x = 0.00000000000000030426102110965134
x1 = -0.000000000000000070906981940269862;
x2 = -0.000000000000000070906981940269849;
We get x = -0.000000000000000070906981940269862
x1 = 0.00000000000000030426102110965129;
Having received an array of bytes of value, we have:
119 95 82 12 160 236 181 60
x2 = 0.00000000000000030426102110965134;
Similarly:
120 95 82 12 160 236 181 60
Answer the question
In order to leave comments, you need to log in
So. Stop.
Decimal can take a huge range of values, but due to decimal-to-binary conversions, the accuracy may still not be enough.
Alternatively, you can use BigInteger and store the comma as a separate number, you can also use BigInteger. In fact, a comma is an exponent at the base of the number system, that is, 10. Arithmetic is elementary.
There are thousands of implementations (including BigRational in C# F# ).
Almost all of them can be loaded from a string, and for those who cannot, we split by a point and count the number of zeros. But I must warn you - this method can go in cycles and for a very long time.
1) There is a Decimal type. You can try it. It will have more precision than double. If you need even more, then you already need to implement the mathematics of large numbers.
create your own complex data type
let it store two numbers double(number for example 1.5) and int(number 9 for example, which means 1.5/(10^9))
i.e. that (1.5, 9) == 0.0000000015
divide, add, etc. them
2) ideone.com/YjX5k6 or stackoverflow.com/questions/389993/extracting-mant...
1) Is it possible to modify the algorithm so that calculations are carried out in conditional coordinates from 0.0 to 1.0 (for example), instead of real x1 .. x2 , and then calculate the real x in any slow way?
What to do in such a situation is absolutely not clear.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question