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.
integer, parameter :: QR_K = selected_real_kind (32)
real (kind=QR_K) :: MyReal
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?
Use kinds for modern Fortran code, i.e.
real(some_kind_value) :: variable
You can then use selected_real_kind()
or iso_fortran_env
module or c_long_double
kind value from iso_c_binding
module to get the kind variable. All of these have slightly different meaning.
You can use epsilon()
, tiny()
, huge()
or nearest()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With