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 <[email protected]> 
> 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: [email protected]
> tel: +64 (0)9 923 84611
> 

Reply via email to