# Value NaN of a variable

**URL:** https://discourse.processing.org/t/value-nan-of-a-variable/14220
**Category:** Beginners
**Created:** [September 26, 2019, 4:01pm UTC](https://discourse.processing.org/t/value-nan-of-a-variable/14220 "2019-09-26T16:01:06Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Ignaki](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@Ignaki](https://discourse.processing.org/u/Ignaki)
#### Post date: [September 26, 2019, 4:01pm UTC](https://discourse.processing.org/t/value-nan-of-a-variable/14220/1 "2019-09-26T16:01:06Z")

</div>

What does it mean wnen the printed value of a variable is “NaN”?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [September 26, 2019, 5:19pm UTC](https://discourse.processing.org/t/value-nan-of-a-variable/14220/2 "2019-09-26T17:19:59Z")

</div>

> `NaN` means _“Not a Number”_

```auto
println(0.0/0.0);
println(sqrt(-1));

```

why not show the code what produces it?

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [September 26, 2019, 6:28pm UTC](https://discourse.processing.org/t/value-nan-of-a-variable/14220/3 "2019-09-26T18:28:11Z")

</div>

Lets assume you are talking about a `float`. In Java a `float` is stored in 4 bytes of memory that’s 32 bits, since each bit can be 0 or 1 that gives us 4294967296 different combinations to encode a floating point number. Not all those combinations represent a valid floating point number hence **Not a Number** or `NaN`

---

<div class="post-metadata">

### Author: ![Ignaki](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@Ignaki](https://discourse.processing.org/u/Ignaki)
#### Post date: [September 30, 2019, 6:57pm UTC](https://discourse.processing.org/t/value-nan-of-a-variable/14220/4 "2019-09-30T18:57:05Z")

</div>

Hi, this is the code that produces NaN:

```auto
void setup()
{
size(1000,1000);
background(255);
}
void draw()
{
  float x,y,xm,xM,ym,yM,A,B,inc,Zx,Zy;
  xm = -10; xM = 10; ym = -10; yM = 10;
  inc = (xM-xm)/1000;
  x = xm; y = ym;
  A = (x - xm)/(xM-xm)*1000;
  B = (y-ym)/(yM-ym)*1000;
  println(x,y,inc);
       for (int i = 0; i < 1000; i=i+1)
         {
            for (int k = 0; k < 1000; k++)
              {                    
               for (int l = 0; l < 20 ; l++)
                { println(x,y);
                  Zx = x*x-y*y;
                 Zy = 2*x*y;
           
                 if( Zx*Zx + Zy*Zy < 10)
                  {A = (x - xm)/(xM-xm)*1000;
                   B = (y-ym)/(yM-ym)*1000;  
                   stroke(l);
                   point(A,B);
                  }
                 x = Zx;
                 y = Zy;

               }
            y = ym + k*inc;
           
          }
           x = xm + i*inc;
          }
          exit();
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [September 30, 2019, 7:38pm UTC](https://discourse.processing.org/t/value-nan-of-a-variable/14220/5 "2019-09-30T19:38:25Z")

</div>

that code must be posted in the  
`</> Preformatted text ` from the editor menu

> Zx = xx-yy;  
> Zy = 2xy;

this code can not run.

BUT  
should it mean:

```auto
        Zx = x*x-y*y;
        Zy = 2*x*y;

```

the code runs and produce your NaN error.

* * *

try

```auto
  println( "float min: "+Float.MIN_VALUE+ " max: "+Float.MAX_VALUE);

```

that tells you the range of possible FLOAT numbers  
your loops do  
`x = Zx = x*x-y*y;`  
after 7 loops that value is out of range…

* * *

and the position you calculate for the points  
`point(A,B);`  
is always 0 , 0

* * *

sorry but to run that math 20 000 000 times ( points ) is questionable

---

<div class="post-metadata">

### Author: ![Ignaki](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@Ignaki](https://discourse.processing.org/u/Ignaki)
#### Post date: [October 1, 2019, 3:31pm UTC](https://discourse.processing.org/t/value-nan-of-a-variable/14220/6 "2019-10-01T15:31:17Z")

</div>

Thank you very much.

It’s obvious that I have some serious misconceptions, is there any book that explains in comprehensvly processing functioning?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [October 2, 2019, 12:56am UTC](https://discourse.processing.org/t/value-nan-of-a-variable/14220/7 "2019-10-02T00:56:36Z")

</div>

please repair your above code posting first.

* * *

i asked you to try one line of code to understand the floating point number range  
what was the result?  
is there a number type that can cover a bigger number range? YES “double”  
would it help in your case / math ? i think NOT

* * *

yes there are books,  
but also

- the reference [https://processing.org/reference/](https://processing.org/reference/)
- the examples [https://processing.org/examples/](https://processing.org/examples/)  
++PDE / File / Examples /…
- add loadable examples  
++PDE / Tools / Add Tool / Examples /
- the tutorials [https://processing.org/tutorials/](https://processing.org/tutorials/)
- the videos [http://learningprocessing.com/videos/](http://learningprocessing.com/videos/)

all might depend of YOUR best way of learning.

* * *

the problem is that from you code it is not clear  
what you want to do?

- -1- cover the canvas with points and find some nice way to color them?
- -2- use 20 000 000 points to draw some structure on the canvas ?spiral?..

so for -1-:  
show a easy start:

```auto
void setup() {
  size(500, 500);
  colorMode(HSB, width, 100, 100);
}

void draw() {
  many_points();
}

void many_points() {
  for ( int x = 0; x < width; x++)
    for ( int y = 0; y < height; y++ ) {
      stroke(x, 100, 100);
      point(x, y);
    }
}

```

---

<div class="post-metadata">

### Author: ![Ignaki](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@Ignaki](https://discourse.processing.org/u/Ignaki)
#### Post date: [October 3, 2019, 3:34pm UTC](https://discourse.processing.org/t/value-nan-of-a-variable/14220/8 "2019-10-03T15:34:07Z")

</div>

Again, thank you very much!!!
