I have a couple of questions concerning: sorting floating point values.

1.) Is there a library out there, that sorts floating point values accurately.

2.) In C/C++/Java, when you have an array of integers, int Value[1000], and assuming the values of the arrays is from -500 to 499. When you tried to sort and print them out the negative(-) sign is still placed in the array. So my theory is that the arrays are converted to character string( is more like a character string array instead of an integer array). Is this true? Or the conversion starts when the arrays are printed out. For example a sorted arrays looks like this.

Values[0] = -1 (1111 1111 1111b)
Values[1] = 0 (0000 0000 0000b)
Values[2] = 1 [0000 0000 0001b]

printf("%d", Values[0]);

I'm guessing this printing part will be the start of the conversion to character string, since Values[0] is negative and it needs that - sign. And also positive values doesn't need to be converted. Am I right?

3. I know sorting floating point values is very hard. For me the best way to sort these values is to convert to character string. So if I have a billion arrays(floating points), i have to convert these values first to character string then sort them out(yuck!!! ugly this is an extra overhead - convert then sort). So in this case, when the programmer starts to sort his/her arrays(floating point values) the sorting routine assumes that the arrays are already in character string to minimize overhead when the sorting routines starts.

I really need your help on this issue. Tell me what you think, what you can suggest... Thanks
Posted on 2002-01-20 09:33:21 by stryker
Im not too sure if there is a Floating Point Kit or anything out there, but you can do floating point comparisons. This mean you dont need to have them as ASCII strings to compare with. Its a bit wierd to do, but still simpler:

Here is a MACRO to compare any two QWORDS:


fTest MACRO Q1:REQ, Q2:REQ
LOCAL @OVER
fld Q1 ; load the q1
fcomp Q2
fstsw ax
sahf ; load ah into coniditon bits
ENDM


This *should* (didnt test it) compare to floats, and then get the Floating Point Status bits, and load them on top of the Intel x86 Status register, such that Intel comands like JE, JNE, JZ, JNE, JA, JB, etc. can not be applied from a floating point compare.

Ie)

fTest QuadWord1, QuadWord2
ja QuadWord1_Greater
jmp Elsewhere.

Hope this helps... (I made a crude macro kit for help me on a project once, you free to exploit what you can from it)
:alright:
NaN
Posted on 2002-01-20 11:26:18 by NaN
Thanks NaN!!! I'll play with it. Because I was thinking of converting to ascii first then do the sorting...
Posted on 2002-01-20 11:32:11 by stryker
If all floating point is positive then you can sort them as it where integers.
Posted on 2002-01-20 19:07:52 by dxantos