Question: ```
import java.util.*;
import java.lang.*;
import java.io.*;

public class MyClass {
    public static void main (final String[] args) {
        float distanceInMeters = 0.0f;
        long time = 1439230171182L;
        long previousTime = 1439230111554L;
        float speed = (distanceInMeters / 1000) / ((time - previousTime)/3600000);
        System.out.println(speed);
    }
}

```

This calculation returns "NaN". Does anyone know why?

Answer: 
Lets put some our values and calculate it:

```
(distanceInMeters / 1000) / ((time - previousTime)/3600000);

```

is same as

```
(       0.0f      / 1000) / ((1439230171182L - 1439230111554L)/3600000)

```

`0.0f/1000 = 0.0f` and `1439230171182L - 1439230111554L = 59628L` so we get

```
(           0.0f        ) / ((           59628L              )/3600000)

```

`59628L/3600000` = `0` (integer division) 

So we and up with `0.0f / 0` which is `NaN` (Not a Number).  

If you would divide `1.0f / 0` you would get `Infinity` and for `-1.0f / 0` you would get `-Infinity`
The solution is to add a float cast like this:

```
float speed = (distanceInMeters / 1000) / ((float)(time - previousTime)/3600000);

```

or like this:

```
float speed = (distanceInMeters / 1000) / ((time - previousTime)/3600000.0f);

```

I forgot about the Integer division in Java. Probably because I wrote a lot of JavaScript code previously.