[petsc-dev] fortran literals

Barry Smith bsmith at mcs.anl.gov
Wed Sep 7 15:41:16 CDT 2016


   I think the Fortran side is simple and have a branch I've been working on barry/use-fortran-kind-consistently that I will put in master once I have all the .F90 examples updated.

   Barry

C is ugly.

> On Sep 7, 2016, at 3:10 PM, Munson, Todd <tmunson at mcs.anl.gov> wrote:
> 
> 
> Did we come to a conclusion on this?  Is it worthwhile adding macros for C and 
> Fortran literals to make sure they match the PetscScalar type along with the 
> appropriate configure tests?
> 
> Todd.
> 
>> On Sep 3, 2016, at 3:18 PM, Lisandro Dalcin <dalcinl at gmail.com> wrote:
>> 
>> 
>> 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
> 




More information about the petsc-dev mailing list