News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

PI

Started by mabdelouahab, October 19, 2017, 06:11:20 PM

Previous topic - Next topic

mabdelouahab

This is the value of PI in the  windows calculator: 3.1415926535897932384626433832795
But the compilator does not accept the full value .
      
PI1 REAL8 3.1415926535897932384626433832795 ;error A2071:initializer magnitude too large for specified size
PI1 REAL8 3.14159265358979323846264338327;95 This is acceptable.

Same thing for REAL10

The second question, I use vc_printf with : "%.32lf" or "%.32f", but it prints only 16 digits. (Even with fldpi)

3.14159265358979310000000000000000

This is the code:


    include \masm32\include64\masm64rt.inc
.data
x1 REAL8 3.14159265358979323846264338327;95
x2 REAL8 0.0
.const
Fformat0 db "pi=%.32lf",13,10,0,0
Fformat1 db "pi=%.32f", 13,10,0,0
    .code
entry_point proc
invoke vc_printf ,addr Fformat0,x1
invoke vc_printf ,addr Fformat1,x1
finit
fldpi
fstp x2
invoke vc_printf ,addr Fformat0,x2
waitkey
    .exit                           
entry_point endp
end 

Quotepi=3.14159265358979310000000000000000
pi=3.14159265358979310000000000000000
pi=3.14159265358979310000000000000000
Press any key to continue...

hutch--

It may be worth seeing if anyone else has written a floating point to string conversion to get the extra precision.

jj2007

#2
include \Masm32\MasmBasic\Res\JBasic.inc
.data
PI1 REAL8 3.1415926535897932384626433832795
Init                                                                ; OPT_64 0  ; put 0 for 32 bit, 1 for 64 bit assembly
  MsgBox 0, Str$("The value of PI is %.17f", PI1), "Hi", MB_OK or MB_SETFOREGROUND
EndOfCode


Assembles fine with UAsm (see attached exe), but ML throws indeed an error. However, even if ML would accept the extra precision, what do you want to do with it? As Hutch wrote, you need your own routines to display the high precision. Standard CRT sucks.

But even REAL10 can handle only 18 digits. For more precision, you need QuadMath or similar:digits  1.23456789012345678901234567890123
PI      3.14159265358979323846264338327950      (as text)
MyPI    3.14159265358979323846264338327950      Real16 precision
MyPI    3.14159265358979323851280895940619      Real10 precision


Edit: Raymond is right (as usual), REAL10 can handle 18 digits, not 16 as I wrote initially.

raymond

REAL10 provides a full 64 bits of precision, which is equivalent to 18 digits of precision in the decimal system.

However, only 16 digits can be displayed if you rely on the FBSTP packed decimal instruction to convert the binary data to the decimal data. You would need some other means of converting the binary data to display the full 18 bits of the FPU to decimal.

Although the ALU has been upgraded to handle 64-bit instructions, the associated FPU in 64-bit computers is still limited to handling REAL10 as far as I know. The Windows calculator was providing a precision of over 30 decimal digits well before the advent of 64-bit computers. That was based on its own internal program for big numbers and extended precision, along with its own algo for binary/decimal conversions.
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

mabdelouahab

Quote from: hutch-- on October 19, 2017, 06:20:36 PM
It may be worth seeing if anyone else has written a floating point to string conversion to get the extra precision.
I did not find it in x64

@jj2007, UASM accept bigger than that figure:
      x0 REAL4 3.141592653589793238462643383279502884197169399375105820974945  ; Acceptable
      x1 REAL8 3.141592653589793238462643383279502884197169399375105820974945  ; Acceptable
QuadMath? I didn't find it in the MasmBasic (\masm32\MasmBasic\Res\QuadMath.inc) update October 04, 2017

@raymond , Thanks for the important information,I'll look for float128 :t

jj2007

Quote from: mabdelouahab on October 21, 2017, 02:17:42 AMQuadMath? I didn't find it in the MasmBasic (\masm32\MasmBasic\Res\QuadMath.inc) update October 04, 2017

Right, it seems to be missing in the latest release. Attached the current version, extract it as \Masm32\MasmBasic\Res\QuadMath.inc; second attachment is a demo, open in \Masm32\MasmBasic\RichMasm.exe and hit F6. Remember it needs a standard GCC installation, i.e. C:\TDM-GCC-32\bin\