# How to fill an integer array with some nans?

**URL:** <https://fortran-lang.discourse.group/t/how-to-fill-an-integer-array-with-some-nans/3696>\
**Category:** Help\
**Created:** [June 7, 2022, 9:40pm UTC](https://fortran-lang.discourse.group/t/how-to-fill-an-integer-array-with-some-nans/3696 "2022-06-07T21:40:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fortran4r](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@fortran4r](https://fortran-lang.discourse.group/u/fortran4r)\
**Post date:** [June 7, 2022, 9:40pm UTC](https://fortran-lang.discourse.group/t/how-to-fill-an-integer-array-with-some-nans/3696/1 "2022-06-07T21:40:17Z")

</div>

```auto
program test
  use ieee_arithmetic
  integer :: n
  integer, allocatable :: x(:)
  n = 5
  allocate(x(n))
  x = [1, 2, 3, 4, 5]
  x(1) = ieee_value(0, ieee_quiet_nan)
  print *, x
end program

```

This program only works for a real array.

---

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [June 7, 2022, 9:53pm UTC](https://fortran-lang.discourse.group/t/how-to-fill-an-integer-array-with-some-nans/3696/2 "2022-06-07T21:53:59Z")

</div>

There is no **integer NaN**. You could `transfer` real NaN into integer variable but you would get perfectly valid, finite integer value.

In real world, people have been using values like -99999999 to signal error / “nan” but that requires knowing for sure that there will be no such values in normal course of computations.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [June 7, 2022, 10:08pm UTC](https://fortran-lang.discourse.group/t/how-to-fill-an-integer-array-with-some-nans/3696/3 "2022-06-07T22:08:59Z")

</div>

An integer cannot be set to NaN, but in the `allocate` statement you can use `source` to set the values of an integer array to something that “sticks out”, such as `-huge()`. Here is an example:

```auto
program test
  integer :: n
  integer, allocatable :: x(:)
  n = 3
  allocate(x(n), source = -huge(0))
  x(1:n-1) = 0
  print*,x ! 0 0 -2147483647
end program

```
