News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

floating point

Started by Tinieblaster, July 16, 2005, 07:58:13 PM

Previous topic - Next topic

Tinieblaster

Hello I have a problem with a code of floating point ... I hope someone can help me ... I want to do:
[content of Tedit (ej. 4)] * 16 + 3.5 = 67.5 and to show this result in another Tedit this is my code:
invoke GetDlgItemText,hWin,1006,addr VARTedit,10


fild dword Ptr ds:[VARTedit]
fild  dword Ptr ds:[_16_]
fmul

fld dword Ptr ds:[_3_5_]
fadd

fstp dword Ptr  ds:[Result]

fstp    Dword Ptr ds:[Desca]         


invoke wsprintf,addr Result, addr Format
invoke SetDlgItemText,hWin,1007,addr Result
.DATA

_16_ dd 16
_3_5_ dd 3.5 ; constant 3.5d

VARTedit dd ?
Desca dd ?
Result dd ?



Format db "%d"   ;entero decimal

:'( :'(

Eóin

What you need to do is convert the string returned by GetDlgItemText into a floating point number, and load that valuse into the FPU. The StrToFloat function from the masmlib will perform that conversion for you.

You'll probably also find it easier to use the FloatToStr function to convert the result back to a string instead of wsprintf because it doesn't handle floats, only the *printf functions from the stdc lib support floats.

raymond

If you are using the MASM32 package, you may also be interested in the numerous floating point functions provided in the FPULIB. If you don't have that package, the library with an extensive Help file is available for download from the following:

http://www.ray.masmcode.com/index.html#fputut

A tutorial related to the FPU and its instructions is also available from the above link. You may learn about the various pitfalls of using the FPU. For example in your code, the register where you had your result became "empty" after the
fstp dword Ptr  ds:[Result] instruction.

The fstp    Dword Ptr ds:[Desca] instruction would then have resulted in an invalid operation unless some valid data would have remained in the other register which became the TOP register.

BTW, the use of the ds: prefix is useless if you are using flat memory. You must have recently switched from 16-bit DOS assembly.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Tinieblaster

Thanks for his help it will try with what it shows me
greetings :wink