V
V
Vadim Mamonov2022-03-03 17:50:38
binary code
Vadim Mamonov, 2022-03-03 17:50:38

How to find the common part of real numbers?

Given a list of real numbers of double type. It is necessary to find the common part of given real numbers. How to do it faster? Whether it is possible somehow through bit operations?

Example 1 .
number 0 = 15.0123567
number 1 = 15.0123593
common part = 15.01235 since the differences start at 6 decimal places

Example 2 .
number 0 = 0.000123
number 1 = 102.00123
common part = 0.0, since the differences come immediately

Example 3 .
number 0 = 1.234578e-10
number 1 = 1.234567e-10
common part = 1.2345e-10, since the difference is after the digit 5

If anyone is wondering where this issue came from. It was necessary to find the area of ​​the polygon on the plane, which is given by the set of points (x_i, y_i) i = 0...N. Use the Gauss area formula. I started running tests and got an interesting picture when the coordinates of the points were very close to each other. For example, 1.1234567891***** (that is, they differ where they stand *), then the area turned out to be negative ... although in fact the area was positive if numbers with greater accuracy were used. Hence the idea of ​​how to fix this problem arose, so this is to shift the coordinates of the points so that from 1.1234567891***** it would become *.****00000000000e-11. I know another solution, but I don’t understand how it works at all, the fact is that if you multiply all the coordinates by, say, 1e6, then find the area using the Gauss formula, then divide the area by 1e12,

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2022-03-03
@dikysa

Through bit operations, you will not do anything, because you, apparently, need to find common digits in the decimal number system. In general, finding decimal digits for real numbers is a very difficult operation.
I think all you have to do is output both numbers to strings in some fixed format and then compare character by character.

L
Leonid Nikolaev, 2022-03-03
@nikonor

and how in the second example it turned out 0.0? what was generally meant then by the general part?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question