News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

output 80-bits number from the FPU to the console

Started by Mikl__, March 19, 2013, 10:15:12 PM

Previous topic - Next topic

TouEnMasm


Easy method with sprintf_s (msvcr100.dll)
Perfect for me.
Fa is a musical note to play with CL

Mikl__


jj2007

Quote from: Mikl__ on April 08, 2013, 03:28:30 PM
There are 19 decimal digits in my program

Str$() - good for 18.9 digits ;-)

Point is, there is an output limit imposed by the signed QWORD:

include \masm32\MasmBasic\MasmBasic.inc        ; download
.data
MyQ1        dq 1234567890123456789
MyQ2        dq 9222567890123456789
MyQ3        dq 9223567890123456789

        Init
        Print Str$("Q1=%Jf\n", MyQ1)
        Print Str$("Q2=%Jf\n", MyQ2)
        Inkey Str$("Q3=%Jf\n", MyQ3)
        Exit
end start

Q1=1234567890123456789.0
Q2=9222567890123456789.0
Q3=-9223176183586094827.0

That is, numbers starting with 9.22 and less can be displayed with 19 digits precision, numbers starting with 9.23 only with 18 digits.

dedndave

Mikl,
i would have to say, for someone new to assembler, that is a wonderful job   :t
the code is a bit long and mangled, but it seems to work   :P

i made some changes, just to make it easier to read and understand
the biggest changes:
        include    \masm32\include\masm32rt.inc
        .686p
        .MMX
        .XMM
;
;
;
@@:     INVOKE  MessageBox,0,edi,offset wTitle,MB_OK
        INVOKE  ExitProcess,0

dedndave

Quote from: jj2007 on April 08, 2013, 03:46:15 PM
That is, numbers starting with 9.22 and less can be displayed with
19 digits precision, numbers starting with 9.23 only with 18 digits.

i don't agree with that, at all - lol

in fact, i was reading a paper, the other day
it said that it was valid to return 21 digits, even though they may not all be mathematically usable
it would ensure that bin->decimal->bin yields the same result as the original binary value

RuiLoureiro

Quote from: dedndave on April 08, 2013, 11:38:00 PM
Quote from: jj2007 on April 08, 2013, 03:46:15 PM
That is, numbers starting with 9.22 and less can be displayed with
19 digits precision, numbers starting with 9.23 only with 18 digits.

i don't agree with that, at all - lol

in fact, i was reading a paper, the other day
it said that it was valid to return 21 digits, even though they may not all be mathematically usable
it would ensure that bin->decimal->bin yields the same result as the original binary value
:biggrin:
Dave,
I solved this problem some time ago
and it seems to me now that Jochen is right.

Dave, try to write a converter and you get the problem.
Yes, we use only FPU and qword converters.  :t

note: from raymond docs:
QWORD range   ±(263-1)  or  ±9223372036854775807



RuiLoureiro

Quote from: Mikl__ on April 08, 2013, 03:28:30 PM
There are 19 decimal digits in my program
:biggrin:
Hi Mikl__
                19 decimal digits are not 19 integer digits.
                 But if you want to print numbers like
                  -9123456789012345678.12345678901234...
                 divide it in integer part and decimal part
                 convert each and at the and put it together.
                 Did you understand ? It's math it's simple

dedndave


jj2007

Well, it does mention 18-21 digits for extended double, i.e. 10+ bytes...

dedndave

someplace, i saw accompaning text that referenced that article
i was trying to find it again, but at least i found the PDF - lol

RuiLoureiro

Quote from: dedndave on April 09, 2013, 03:58:00 AM
here is that paper i was reading that mentioned 21 decimal digits...

http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF
It is good to know this but the problem is how to implement it.
               
               21 decimal digits may be this: 0.000000111110123456780 ? ;)

dedndave

implement it the same as you did 18 or 19, except.....
..... it's 21

:lol:

i may want to do some calculation and testing to verify this value   :t

Gunther

Hi Dave,

Quote from: dedndave on April 09, 2013, 03:58:00 AM
here is that paper i was reading that mentioned 21 decimal digits...

http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF

very interesting paper by Prof. Kahan, the father of floating point.  :t

Gunther
You have to know the facts before you can distort them.

RuiLoureiro

Quote from: dedndave on April 09, 2013, 05:16:28 AM
i may want to do some calculation and testing to verify this value   :t
:biggrin:
               yes, i wait for your result, Dave

dedndave

calculating the number of digits required is simple enough
but, the number required to go from bin to decimal to bin is a little different story   :redface: