The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Tinieblaster on July 16, 2005, 07:58:13 PM

Title: floating point
Post by: Tinieblaster on July 16, 2005, 07:58:13 PM
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

:'( :'(
Title: Re: floating point
Post by: Eóin on July 16, 2005, 09:51:57 PM
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.
Title: Re: floating point
Post by: raymond on July 17, 2005, 01:36:48 AM
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
Title: Re: floating point
Post by: Tinieblaster on July 17, 2005, 05:39:57 AM
Thanks for his help it will try with what it shows me
greetings :wink