News:

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

How do you print a floating point number?

Started by nixeagle, May 09, 2012, 02:31:22 AM

Previous topic - Next topic

raymond

Apart from what I already indicated, the remainder of the fp stuff is relatively simple and looks OK. However, other areas are intriguing.

In your calc_variance proc, what is the purpose of that instruction:
sar ebx, 31       ; shift arithmatic right by 31

Then, in the same proc,
xor edx, edx ; we are only doing 32 bit division... discarding all high bits!

Remember that a 32-bit division divides a 64-bit value by a 32-bit value, with the proviso that the quotient must fit in a 32-bit register. You should already have your 64-bit value in EDX:EAX since you seemingly "intended" to increment the high 32-bit due to any overflow from the addition of two 32-bit values. Rezeroing the high 32-bits of your addition is counterproductive.

If you did intend to increment the high 32-bit due to any overflow from the addition or squaring of the ECX register, you MUST review that code and change it.

I've noticed that you are using the following type of instruction in numerous places:
mov ecx, gu_total_samples-1

I assume you want to load the register with the content of the memory variable decremented by 1 and use it as a counter. Have you tested if that instruction actually gives you the result you want? Unless it's some type of a macro or a specialty of the assembler you are using, such an instruction in MASM syntax may load the register with the dword starting at one byte lower than the address of the memory variable. It may be safer to load only the content without modification and jump back into the loop until it reaches 0 with the jnz opcode instead of the jns opcode.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

jj2007

Hi nixeagle,

Attached a testbed for your print_float algo (no library needed).
There is an option RayMod=1 that allows to test Ray's proposal.

The output shows that there are still minor problems:
nixeagle float, Ray's mod = 0:
12.3566
1235.6600
1234568.9908
0.0054
1.2356
-123.1006

jj float, Real8:
12.346
1234.560
1234567.890123457       9 digits set
-0.0012346      7 digits set
1.235
-123.456


The *.asc file is like the *.asm but has colouring. It opens in WordPad or Ms Word.

HTH, jj :thumbu

nixeagle

Quote from: jj2007 on May 11, 2012, 09:30:47 AM
Hi nixeagle,

Attached a testbed for your print_float algo (no library needed).
There is an option RayMod=1 that allows to test Ray's proposal.

The output shows that there are still minor problems:
nixeagle float, Ray's mod = 0:
12.3566
1235.6600
1234568.9908
0.0054
1.2356
-123.1006

jj float, Real8:
12.346
1234.560
1234567.890123457       9 digits set
-0.0012346      7 digits set
1.235
-123.456


The *.asc file is like the *.asm but has colouring. It opens in WordPad or Ms Word.

HTH, jj :thumbu

Other than the off-by-one error with printing 4 digits after the decimal point, I think the rest can be explained due to the control word not being set. In the actual program I set the control word to truncation mode for the whole runtime of the program. See http://www.masm32.com/board/index.php?topic=18787.msg159632#msg159632 and the attachment labeled timing-0.5.

Also I'm not real sure, at a first glance why I have funky behavior with negative numbers, but my application should never have such numbers printed. :lol.

Once I finish going through raymond's code suggestions, I'll take a second look at this :bg.