[petsc-dev] NaN constant?

Barry Smith bsmith at mcs.anl.gov
Wed Oct 28 08:56:53 CDT 2015


  There is no portable way that I am aware of in C89 to generate a NaN.

  Barry

> On Oct 21, 2015, at 5:36 PM, Adrian Croucher <a.croucher at auckland.ac.nz> wrote:
> 
> hi,
> 
> You may have looked at this before, but I was wondering if there'd be any merit in having a NaN constant (PETSC_NAN or similar) in PETSc?
> 
> I gather in C there is a NAN macro available, but in Fortran there isn't anything unless you have a compiler supporting the new(-ish) IEEE_ARITHMETIC module- which for gfortran means version 5.
> 
> Could PETSc perhaps just create a NaN using the C NAN macro and make it available, so that Fortran users could use it too?
> 
> Otherwise Fortran users have to try and make NaNs by dividing numbers by zero and hoping the compiler doesn't complain, or using the transfer() routine to get the appropriate NaN bit pattern onto a float, and I don't know if that is very portable or not.
> 
> Cheers, Adrian
> 
> -- 
> Dr Adrian Croucher
> Senior Research Fellow
> Department of Engineering Science
> University of Auckland, New Zealand
> email: a.croucher at auckland.ac.nz
> tel: +64 (0)9 923 84611
> 




More information about the petsc-dev mailing list