I'm having trouble dividing two floats or two integers and trying to get a float as a result.

szFPS db "%ld.00 fps", 0 ; defined up there

fld as.dwRate ; contains 15.0
fdiv as.dwScale ; contains 1.0
fstp x

invoke wsprintf, addr szBuffer, addr szFPS, x

When I run it as (fld, fdiv, and fstp), I get this:
1097859072.00 fps

But when I use (fild, fidiv, and fistp), I get this:
15.00 fps (the correct answer)

Anyone know what's wrong?
Posted on 2001-07-21 01:19:23 by dl?
Wsprintf can't print float values. Use the FloatToStr function in the Masm32 library. For example :


fld as.dwRate
fdiv as.dwScale
fst x
INVOKE FloatToStr, x, ADDR szBuffer
Posted on 2001-07-21 02:31:19 by Dr. Manhattan
karims right you should use FloatToStr over Wsprintf. However theres one other thing going on here.

You see the dwRate and the other vaule must be integers, thats why you only get the correct answer when you use fild and fidiv however if you want to output a floating point value use fstp not the integer version, then use FloatTOStr to convert the answer to a string.

Plus the variable your going to change to a string need to be a QWORD (8 bytes) not a DWORD
Posted on 2001-07-21 06:48:29 by Eóin
Thanks, those changes work great!

I always thought the ".00" in the wsprintf would work for floats.. must be printfs in the ctrldll.
Posted on 2001-07-21 07:05:05 by dl?