[petsc-dev] fortran literals

Lisandro Dalcin dalcinl at gmail.com
Sat Sep 3 15:18:56 CDT 2016


On 2 September 2016 at 00:46, Scott Kruger <kruger at txcorp.com> wrote:

> Lisandro's description is the most natural way for a modern fortran
> programmer.
>
> But for completeness, this is equivalent:
>    x=REAL(0.123456789123456789123456789,KIND=PETSC_REAL_KIND)
>

I think you are wrong. The literal gets demoted to single precision, so you
loose digits.

$ cat tmp.f90
program main
  real(kind=8) x
  x = REAL(0.123456789123456789123456789,KIND=8)
  write (*,'(F18.16)') x
  x = 0.123456789123456789123456789_8
  write (*,'(F18.16)') x
end program main

$ gfortran tmp.f90
$ ./a.out
0.1234567910432816
0.1234567891234568


-- 
Lisandro Dalcin
============
Research Scientist
Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
Extreme Computing Research Center (ECRC)
King Abdullah University of Science and Technology (KAUST)
http://ecrc.kaust.edu.sa/

4700 King Abdullah University of Science and Technology
al-Khawarizmi Bldg (Bldg 1), Office # 0109
Thuwal 23955-6900, Kingdom of Saudi Arabia
http://www.kaust.edu.sa

Office Phone: +966 12 808-0459
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20160903/26905247/attachment.html>


More information about the petsc-dev mailing list