Radix Sort Floating Data

How does radix sort floating point data? e.g. 12.4, 45.13, etc., will it first read the right part of the decimal point or the left part of the decimal point? And then, if she reads the right side of the decimal point, how would she handle the numbers, first he reads the right first?

+3
source share
3 answers

See this discussion page for this subject.

http://codercorner.com/RadixSortRevisited.htm

Basically, computers store floating point in a specific format. They do not write it as 45.13. As a result, thinking about it this way will not be related to how it works.

Ignoring this, Radix sort should first consider the most significant part. The floating point number that it has is the most digits. In fact, we scored all the numbers to have the same number of digits to the decimal point. Then we read the numbers from left to right.

+2
source

Sort radix works with the binary representation of a number and sorts objects as if they were a large binary integer.

For real integers and strings, the binary representation agrees well with the ordering that we usually expect, and therefore radix sorting is an interesting, if somewhat unusual, alternative.

It turns out that as long as the floating-point number intersects in the right direction, the numbering sorting may work well, except that it will process the sign bit back.

In the internal binary representation, the FP values ​​have a signed bit, about 10 bits of the exponent, and then about 20 or 50 bits are a β€œfraction” or mantissa.

SEEEEEEEEMMMMMMMMMMMM MMM . . . 

The indicator is biased so that small values ​​are indeed the most negative indicators, so it is sorted correctly, like the mantissa.

As long as all numbers are either positive or negative, or if the sign bit is first inverted and scanning from left to right, I think that radix sorting will work with FP numbers.

+1
source

The best parser sorting code I know is here: https://bitbucket.org/ais/usort/src/474cc2a19224/usort/f8_sort.c

0
source

Source: https://habr.com/ru/post/1341732/


All Articles