user8761: I have Arduino Mega and Weather Shield. I want to calculate wind speed.
float get_wind_speed()
{

float deltaTime = millis() - lastWindCheck; //750ms 

deltaTime /= 1000.0; 

  float windSpeed = (float)windClicks / deltaTime; //3 / 0.750s = 4

  windClicks = 0; //Sıfırla ve yeni oluşan rüzgarı izle
  lastWindCheck = millis();

  windSpeed *= 1.492; //4 * 1.492 = 5.968MPH

 Serial.println();
 Serial.print("Windspeed :");
 Serial.println(windSpeed);

 return(windSpeed);
}

But when I run my code I see two windspeed value. First one is windspeed=0.0 or any value. Second one is windspeed=nan.
How can I make it better?

user3917: When debugging a problem like this one, print out values of the variables that the calculation depends on.
In this case, you may find that both windClicks and deltaTime are 0 or 0.0.  The IEEE 754 floating-point-operations specification dictates a result of NaN (not-a-number) for various zero over zero calculations.  It dictates a result of +Inf or -Inf for calculations like 7/0.0 or -13/0.0.  [See, for example, the stackoverflow question, Why does division by zero with floating point (or double precision) numbers not throw an exception.]
If arithmetic generates a NaN or +Inf result, subsequent arithmetic using that result will also produce NaN or +Inf results.
To deal with the problem, you could use deltaTime > 0 as a required pre-condition for calculation of windSpeed.  That is, have an if-statement protecting the calculation block.

8761: <p>I have Arduino Mega and Weather Shield. I want to calculate wind speed.</p>

<pre><code>float get_wind_speed()
{

float deltaTime = millis() - lastWindCheck; //750ms 

deltaTime /= 1000.0; 

  float windSpeed = (float)windClicks / deltaTime; //3 / 0.750s = 4

  windClicks = 0; //Sıfırla ve yeni oluşan rüzgarı izle
  lastWindCheck = millis();

  windSpeed *= 1.492; //4 * 1.492 = 5.968MPH

 Serial.println();
 Serial.print("Windspeed :");
 Serial.println(windSpeed);

 return(windSpeed);
}
</code></pre>

<p>But when I run my code I see two windspeed value. First one is windspeed=0.0 or any value. Second one is windspeed=nan.</p>

<p>How can I make it better?</p>
 3917: <p>When debugging a problem like this one, print out values of the variables that the calculation depends on.</p>

<p>In this case, you may find that both <code>windClicks</code> and <code>deltaTime</code> are 0 or 0.0.  The IEEE 754 floating-point-operations specification dictates a result of <code>NaN</code> (not-a-number) for various zero over zero calculations.  It dictates a result of <code>+Inf</code> or <code>-Inf</code> for calculations like 7/0.0 or -13/0.0.  [See, for example, the stackoverflow question, <a href="https://stackoverflow.com/q/12954193">Why does division by zero with floating point (or double precision) numbers not throw an exception</a>.]</p>

<p>If arithmetic generates a <code>NaN</code> or <code>+Inf</code> result, subsequent arithmetic using that result will also produce <code>NaN</code> or <code>+Inf</code> results.</p>

<p>To deal with the problem, you could use <code>deltaTime &gt; 0</code> as a required pre-condition for calculation of <code>windSpeed</code>.  That is, have an if-statement protecting the calculation block.</p>
