About the REAL constants in iso_fortran_env
Angelo Graziosi
angelo.graziosi@alice.it
Wed Jul 8 22:39:00 GMT 2015
Oops...
Il 08/07/2015 23:46, Angelo Graziosi ha scritto:
> I have run this simple test
>
>
> $ cat test_kind.f90
> !
> ! gfortran test_kind.f90 -o test_kind.out
> !
>
> program test_kind
> use iso_fortran_env, only: INT64, REAL64, REAL128
> implicit none
>
> integer, parameter :: I1B = selected_int_kind(2)
> integer, parameter :: I8B = selected_int_kind(18)
>
> integer, parameter :: DP = selected_real_kind(12,60)
> integer, parameter :: QP = selected_real_kind(30,300)
>
> print *, 'I1B = ', I1B
> print *, 'I8B = ', I8B
> print *, 'DP = ', DP
> print *, 'QP = ', QP
>
> print *, 'INT64 = ', INT64
> print *, 'REAL64 = ', REAL128
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
it should be
print *, 'REAL64 = ', REAL64
and prints the right (expected) value: 8
> print *, 'REAL128 = ', REAL128
>
> end program test_kind
>
But this does not resolve the enigma.
Indeed, I have run the test in
https://gcc.gnu.org/ml/fortran/2011-07/msg00064.html, and it produces
the same (expected!) results:
$ ./precisiontest.out
4 8 10 16
3.14159274
3.1415926535897931
3.14159265358979323851
3.14159265358979323846264338327950280
so, it seems that
REAL_KINDS (1) == REAL32 OK
REAL_KINDS (2) == REAL64 OK
REAL_KINDS (3) == REAL128 ????
REAL_KINDS (4) == 16 = QP = selected_real_kind(30,300)
Angelo
>
> on an Athlon 64 X2 machine with GNU/Linux Mint 17.2 64bit and,
>
>
> $ gfortran -v
> Using built-in specs.
> COLLECT_GCC=gfortran
> COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
> Target: x86_64-linux-gnu
> Configured with: ../src/configure -v --with-pkgversion='Ubuntu
> 4.8.4-2ubuntu1~14.04'
> --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
> --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
> --program-suffix=-4.8 --enable-shared --enable-linker-build-id
> --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
> --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib
> --enable-nls --with-sysroot=/ --enable-clocale=gnu
> --enable-libstdcxx-debug --enable-libstdcxx-time=yes
> --enable-gnu-unique-object --disable-libmudflap --enable-plugin
> --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
> --enable-gtk-cairo
> --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre
> --enable-java-home
> --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64
> --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64
> --with-arch-directory=amd64
> --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc
> --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
> --with-multilib-list=m32,m64,mx32 --with-tune=generic
> --enable-checking=release --build=x86_64-linux-gnu
> --host=x86_64-linux-gnu --target=x86_64-linux-gnu
> Thread model: posix
> gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)
>
>
> The test produces
>
> $ ./test_kind.out
> I1B = 1
> I8B = 8
> DP = 8
> QP = 16
> INT64 = 8
> REAL64 = 10
> REAL128 = 10
>
> Now, why REAL64 and REAL128 are both 10 and not 8 and 16, respectively,
> as one would expect?
>
> It seems that other people are in confusion as me (see [*]). There [*],
> someone writes that 'real128 is bugged in gfortran'. Really this is a
> gfortran issue?
>
> There [*] someone suggests to use dp => real64 as alternative to the old
> double precision.. but '10' is a bit more than '8' ( =
> selected_real_kind(12,60) = selected_real_kind(15,307), here)
>
> When I use
>
> integer, parameter :: QP = selected_real_kind(30,300)
> real(QP) :: x
>
> am I really using quad-precision (16B), or it is downgraded to 10B?
>
>
> TIA for clarification,
> Angelo.
>
>
> ---
> [*]
> http://stackoverflow.com/questions/22362211/confusing-double-precision-real-in-fortran
>
>
More information about the Fortran
mailing list