The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: etow on January 30, 2008, 12:27:14 PM

Title: How to display precision of a real number in console?
Post by: etow on January 30, 2008, 12:27:14 PM
Hi

I need to know how to display a real number up to 5 digits to the right of decimal point.

Thanks
Title: Re: How to display precision of a real number in console?
Post by: ToutEnMasm on January 30, 2008, 01:28:34 PM
Hello,
Here is the answer and all you need to make it
http://www.masm32.com/board/index.php?topic=8022.msg58718#msg58718
Title: Re: How to display precision of a real number in console?
Post by: etow on January 31, 2008, 12:22:27 AM
Hi ToutEnMasm,

I downloaded strsafe.zip and strsafeinc.zip.

How do I use them in MASM?
Title: Re: How to display precision of a real number in console?
Post by: raymond on January 31, 2008, 01:52:04 AM
You could also use the FpuFLtoA function from the Fpu.lib (which comes with MASM32) to convert your real number to ASCII. If you do, PLEASE read the HELP file which comes with the library.
Title: Re: How to display precision of a real number in console?
Post by: ToutEnMasm on January 31, 2008, 09:22:36 AM
Quote
I downloaded strsafe.zip and strsafeinc.zip.

How do I use them in MASM?

Put the .inc in the \masm32\include directorie ,the lib in \masm32\lib as the others.
In your source:
Quote
include \masm32\include\strsafe.inc
includelib \masm32\lib\strsafe.lib

and then you can call the functions exactly as the sample show you.


Title: Re: How to display precision of a real number in console?
Post by: etow on January 31, 2008, 02:37:20 PM
Thanks ToutEnMasm!
Title: Re: How to display precision of a real number in console?
Post by: etow on February 01, 2008, 10:51:42 PM
Hi ToutEnMasm,

Which functions do I call for displaying the real or floating point precision
by using the strsafe.inc and strsafe.lib?

Please reply soon

Thanks
Title: Re: How to display precision of a real number in console?
Post by: GregL on February 02, 2008, 01:16:12 AM
etow,

You can not do it with only strsafe.inc and strsafe.lib, those functions only display strings. You need to use sprintf or FpuFLtoA to convert the floating-point variables to a string first. Another method is to use printf.

Title: Re: How to display precision of a real number in console?
Post by: donkey on February 02, 2008, 04:29:28 AM
Quote from: etow on January 30, 2008, 12:27:14 PM
Hi

I need to know how to display a real number up to 5 digits to the right of decimal point.

Thanks

msvcrt.dll contains sprintf which can convert doubles to strings...

mov eax, offset double
invoke sprintf,offset buffer,"%#0.5f",[eax],[eax+4]
add esp,16

Title: Re: How to display precision of a real number in console?
Post by: etow on February 04, 2008, 01:22:54 PM
Thanks  Donkey