I am trying to use quad precision in gfortran, but it seems like the real*16
does not work. After some fishing around, I have found that it may be implemented as real*10
. Is real*10
actually quad precision?
How can I test the precision of my code? Is there a standard simple algorithm for testing precision? For example, when I want to figure out what computer zero is, I continue to divide by 2.0 until I reach 0.0. Keeping track of the values lets me know when the computer 'thinks' that my non-zero number is zero - giving me computer zero.
Is there a good way of figuring out the precision with a type of algorithm like I described?
Adding to the existing answers... real*N is an extension to the language and is best not used. real*10 is not quad precision. Is is called "extended" -- it is a 10 byte type provided by Intel processors. real*16 may or may not be available on gfortran, depending on compiler version, hardware and availability of libquadmath. If provided in software, it will be slow.
The Fortran way of asking for the precision that you want is to use the selected_real_kind function to define a kind value for the precision that you want.
Will obtain a quad real number, if it is available. Alternatively, with Fortran 2008 or later you can "use ISO_FORTRAN_ENV" and then have access to the kind value REAL128. The kind values will be -1 if the precision is unavailable.
A related question: What does `real*8` mean?
real(kind=10) is the so-called extended 80-bit precision Wikipedia 80-bit.
real(kind=16) is the proper quadruple 128-bit precition Wikipedia 128-bit.
As already mentioned, you can employ selected_real_kind(), epsilon(), tiny(), huge() to select and check the precision to be used.
Try the gfortran command
on the test file
On my platform (FEDORA 20) it works.
Use kinds for modern Fortran code, i.e.
You can then use
selected_real_kind()
oriso_fortran_env
module orc_long_double
kind value fromiso_c_binding
module to get the kind variable. All of these have slightly different meaning.You can use
epsilon()
,tiny()
,huge()
ornearest()
intrinsics to assess the actual precision of your code.Quad precision in gfortran generally requires
libquadmath
library that should be available for most platforms, but maybe not by default.The gfortran documentation for kind type parameters answers this question, in particular the last sentence, which reads:
What you may have discovered is that
real*16
is not implemented on your platform.