Hi,

how can I convert a 80 Bit Float into a 64 Bit Float ?

Thanks,
Nordwind64
Posted on 2003-10-31 03:02:41 by Nordwind64
Hi,

ok, ok.
Now I use StrToFloat to direct convert a string into a 64 Bit float...

But can you please post a small example, how to compare two floats (qword) in memory (if this one is bigger...then...) ?

Thanks,
Nordwind64
Posted on 2003-10-31 07:12:46 by Nordwind64
There are numerous ways to compare two floats in memory. There are several FPU instructions available for such comparisons. See
http://www.masmforum.com/website/tutorials/fptute/fpuchap7.htm

If you are not yet entirely familiar with the floating point data format, also look at the following
http://www.masmforum.com/website/tutorials/fptute/fpuchap2.htm#floats

You would then realize that comparisons of 64-bit floats could also be made with CPU instructions, such as:
;first check the H.O. 4 bytes

lea ecx,Float1
lea edx,Float2
mov eax,[ecx+4]
cmp eax,[edx+4]
jl float1_less_than_float2 ;(negative is smaller than positive)
jg float1_greater_than_float2
;H.O. 4 bytes are equal
;L.O. 4 bytes must now be compared
or eax,eax
js neg_numbers
mov eax,[ecx]
cmp eax,[edx]
jz both_equal
jb float1_less_than_float2 ;notice jb instead of jl here
ja float1_greater_than_float2 ;and, ja instead of jg
neg_numbers:
mov eax,[ecx]
cmp eax,[edx]
jz both_equal
ja float1_less_than_float2
jb float1_greater_than_float2
....
Raymond
Posted on 2003-10-31 08:46:18 by Raymond
Thank you, Raymond !!!

I will try yor links and your code.
What about a fpu version of your code? I wants to learn...

Regards,
Nordwind64
Posted on 2003-10-31 09:06:50 by Nordwind64
What about a fpu version of your code?
The links should give you the answer to that question. If not, ask for a clarification. A great deal of time was spent preparing that tutorial on the FPU.

Raymond
Posted on 2003-10-31 09:25:27 by Raymond

Hi,

how can I convert a 80 Bit Float into a 64 Bit Float ?

Thanks,
Nordwind64


fld mem80
fstp mem64

????
Cheers,
Randy Hyde
Posted on 2003-10-31 09:51:43 by rhyde
Hi & thanks !!!

Raymond, you're right. I've to spent some time with the tutorial. ;-)

Randall, wow, very easy.
Sorry, I never worked with fpu functions... Have I to init the coprocessor ?

Regards,
Nordwind64
Posted on 2003-10-31 13:28:43 by Nordwind64

Hi & thanks !!!

Raymond, you're right. I've to spent some time with the tutorial. ;-)

Randall, wow, very easy.
Sorry, I never worked with fpu functions... Have I to init the coprocessor ?

Regards,
Nordwind64


You can generally assume it's initialized if you're running under Windows and
you haven't executed any MMX instructions lately (or without executing EMMS).

You can also execut FINIT just to be safe.
Cheers,
Randy Hyde
Posted on 2003-10-31 14:12:26 by rhyde
Hi Raymond.

sorry, your code with CPU instruction don't work correct.
The float1-greater-than-float2 routine makes an error with negativ floats.
Can you please look for it ?

Thanks,
Nordwind64
Posted on 2003-10-31 14:40:48 by Nordwind64
Thank you, Randy !!!
Posted on 2003-10-31 14:41:57 by Nordwind64
Nordwind64

My apology. The code would work if both are positive or one is positive and the other negative. However, it would not work with 2 negative numbers because the "cmp" simulates a subtraction. The "jl" relies on SF xor OF and the sign gets set wrong in this situation. A separate comparison would need to be done when both are negative.

Raymond
Posted on 2003-10-31 19:27:32 by Raymond
I think you can do it like this:


mov eax,[Float1]
mov ecx,[Float1+4]
cmp eax,[Float2]
mov edx,[Float2+4]
mov eax,ecx
sbb eax,edx
jz is_equal
lahf
or ecx,edx
ror eax,9
xor ecx,eax
js is_less
Posted on 2003-11-01 06:00:33 by Sephiroth3
sbb eax,edx
jz is_equal
The CF flag does not get set if the first parameter of the comparison is greater than the second parameter. So, even though the H.O. dwords may be equal, the sbb eax,edx does not guarantee two equal values when the ZF flag gets set.

While it is possible to use the CPU to compare floats, it's always easier to use the FPU, specially with the PentiumPro and newer processors.
    fld Float2

fld Float1
fcomip
fstp st ;clear the FPU register
jz both_equal
jc float1_less_than_float2
jmp float1_greater_than_float2
....
Raymond
Posted on 2003-11-01 10:02:10 by Raymond
Hi,

Sephiroth, seems to works fine. Tested within a listview sorting with many many negative, positive und decimal floats. Works fast.

Raymond, is the fpu function fast than the cpu version ? Have a P4/1800.

Regards,
Nordwind64
Posted on 2003-11-01 13:05:03 by Nordwind64
I don't know about the relative speed. It would have to be tested under various conditions. The FPU instruction is straightforward and guaranteed to be error free under ALL conditions, even if the difference is only in the last significant bit.

Raymond
Posted on 2003-11-01 20:33:40 by Raymond
Hi,

you had right, Raymond !
There are errors with numbers with little dfiferences. I will try you fpu code now.

Thanks,
Nordwind64
Posted on 2003-11-02 03:54:17 by Nordwind64
Hi,

Error:
fcomip / instruction or register not accepted in current CPU mode... ?

Can you please post a routine, that works with all CPU's ?
I tried fcompp: Acception error in float operation...

Please help again.
Nordwind64
Posted on 2003-11-02 04:10:09 by Nordwind64
Was that an assembler error message for the "fcomip" instruction or was it while running the program?

If it was an assembler message, did you use the .686 directive as indicated in the tutorial?

Raymond
Posted on 2003-11-02 09:43:25 by Raymond
Hi,

ah, .686. No, my is .383.....
.686, does so compiled programs only run on Pentium Pro systems ?
The program should run on all systems.

Regards,
Nordwind64
Posted on 2003-11-02 13:48:33 by Nordwind64
Hi again.

Now with .686 comand.
"invalid instruction operands" from the assembler/compiler...

Nordwind64
Posted on 2003-11-02 13:59:12 by Nordwind64