аватар question@mail.ru · 01.01.1970 03:00

How to imagine Float in the form of Integer without loss of information?

There is a task of transforming float in the values ​​of the type int (one float value in one int value) without loss of information, i.e., then the reverse transformation can be performed later. How can this be implemented?

Important

it is necessary that the order and sum,
i.e. For any a, b: float should be performed:

  to_float (to_int (a) + to_int (b)) == a + bto_int (a) & lt; to_int (b) at a & lt; b, etc.    

found on the English -speaking SO, where the structure of the float values ​​is represented, but I can’t imagine how it can be applied to its task.

Note: nan and Inf You do not need to transform into my task.


attempts to solve

The production of serialization using pickle.dumps , and then getting into from these baites, from these baites. But this is not at all a rational decision and it does not satisfy the requirements at all.

there were attempts to realize this through byte representations of numbers (), the amount is not preserved in this option.

аватар answer@mail.ru · 01.01.1970 03:00
to_FLOAT (to_int (A) + to_int (b)) == a + bto_int (a) & lt; to_int (b) at a & lt; B, etc.

I remembered that in python inters are endless. It has 11 bits to a degree, which means when multiplying by 2 ** (2 ** 12) you will get an integer that can be put in int. It is only necessary to multiply as you translate, and not a fractional number - otherwise an overflow will occur.

Latest

Similar