开发者

Radix Sort Floating Data

How does radix sorts float data? for example 12.4, 45.13 etc. would it read the right side of the decimal point first?or the left side of the decimal point first?And then if it read the right side of the decimal point, how would it treat the numbers, would it first read the rig开发者_运维百科htmost first?


See this page of a discussion of it.

http://codercorner.com/RadixSortRevisited.htm

Basically, computers store the floating point in a particular format. They do not write it out as 45.13. As a result, thinking about it that way won't relate to how it actually works.

Ignoring that, Radix sort has to look at the most significant part first. In a floating point number that it the left most digits. Essentially, we'd pad all the numbers to have the same number of digits before the decimal point. Then we'd read the digits left to right.


A radix sort operates on the binary representation of a number and sorts objects as if they were a big binary integer.

For real integers and strings, the binary representation corresponds quite well with with the collating order we tend to expect, and so radix sort is an interesting if somewhat unusual alternative.

It turns out that as long as the floating number is traversed in the correct direction, radix sort can work well, except that it will treat the sign bit backwards.

In the internal binary representation, FP values have a sign bit, about 10 bits of exponent, and then roughly 20 or 50 bits are the "fraction" or mantissa.

S E E E E E E E E M M M M M M M M M M M M M M M . . .

The exponent is biased so that small values are really the most negative exponents, so it sorts correctly, as does the mantissa.

As long as all the numbers are either positive or negative, or if the sign bit is first inverted, and the scan is left to right, then I think a radix sort will work on FP numbers.


The best code for radix sorting doubles that I know of is here: https://bitbucket.org/ais/usort/src/474cc2a19224/usort/f8_sort.c

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜