Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double variable precision

Status
Not open for further replies.

aruns07

Programmer
Jan 28, 2009
9
US
Hi ,

I am a beginner and I am trying to help a professor, to execute his Fortran program. He wants to setup the size of DOUBLE variables to 128 bits during compile time. I came across this option to set double variables default precision to 64 bits (-fdefault-double-8). Is there any other similar option for setting it up to 128 bits, or is it possible at all?

Thanks,
Arun
 
Can you declare the variables as real*16? If the compiler accepts it then you have your 128 bit variables.

There seem to be two variants:

real*1, real*2, real*3
real*4, real*8, real*16

Silverfrost takes the top variant, IVF/CVF/g95 take the bottom variant. I haven't checked with the standard as to which is the correct one.

Which variant of Fortran are you working with - 77, 90, 95 or 2003?
 
Thanks for the reply, xwb. I am a bit more clear about the things.

I think I am using Fortran 2003, on Debian Linux. But am not sure, so I am copying in the version dump below. Hope this gives you the info you asked for:

node22/geology> gfortran -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1.1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-cld --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1.1).

And about the variant, I don't know even how to find that out. Please let me know on how to do that.

Thanks for the reply,
Arun
 
Try this
Code:
program main
double precision dp
real*16 r16
print *, 'DP=', sizeof(dp)
print *, 'R16=', sizeof(r16)
stop
end
If the size of DP is 16 then it is 128 bits. Otherwise use real*16 for 128 bits.
 
Hi xwb,

Thanks for your continuous help. I tried compiling your test program and I got an error at first:

test.f:3.7:
real*16 r16
1
Error: Old-style type declaration REAL*16 not supported at (1)

And the command I used was:
gfortran -ffree-form test.f

Then I modified the declaration from 'real*16' to 'real' which gave me this output:

node22/geology> ./a.out
DP= 8
R16= 4

Please check if I did the right thing.

Thanks,
Arun
 
Try
Code:
program main
double precision dp
real(kind=8) r8
real(kind=16) r16
print *, 'DP=', sizeof(dp)
print *, 'R8=', sizeof(r8)
print *, 'R16=', sizeof(r16)
stop
end
 
Hello xwb,

I get an error message again:
node22/geology> gfortran -ffree-form test1.f
test1.f:4.12:

real(kind=16) r16
1
Error: Kind 16 not supported for type REAL at (1)

Thanks for looking on to this,
Arun
 
Rename your file from test1.f to test1.f95. I think it is assuming F77 syntax.

Alternatively, try kind=3 instead of kind=16
 
Hi xwb,

I still am receiving this error:

gfortran -ffree-form test1.f95
test1.f95:4.11:
real(kind=3) r16
1
Error: Kind 3 not supported for type REAL at (1)

Thanks,
Arun
 
Let me download the gfortran compiler and try it out. I normally use g95 or IVF.
 
I'll have to try a Linux system. Can only do that tomorrow.

Just remembered why I use g95 on windows - gfortran on windows has a load of cygwin dependencies which do not come with gfortran and some of them are next to impossible to find if you don't wish to install cygwin.
 
The best I can get is real*10 or real(kind=10) which gives 12 bytes (96bits) on a 32 bit OS. It may by 128bits on a 64 bit OS.
 
Thank you very much for your effort. That answers my question.

I will try it out and let you know.

Thanks again,
Arun
 
Hi xwb,

real(kind=10) gives me a size of 16 bytes. Is there a similar way of increasing the precision of 'double precision' variables ?

Thanks,
Arun
 
Just use real(kind=10) instead of double precision.
 
Hi xwb,

That really helped! Some functions which accept only double variables generated errors, but I used the dble() function to do the type cast.

One more question, are you familiar with the LAPACK library routines ?

Thanks,
Arun
 
No but if you start that as a new thread with LAPACK in the title, if anyone knows about it, they might respond.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top