Since I spent the time to dig up the method of calculating the wind chill given a specific temperature and wind speed, I figured I would go ahead and share it in case someone else finds it useful. Here’s three functions for calculating the wind chill, one each for Javascript, PHP, and Ruby.
// Javascript version
// wind = wind speed in knots
// temp = temperature in Celsius
function getWindChill(wind, temp) {
wind = wind * 1.852;
var wind2 = Math.pow(wind, 0.16);
var wind_chill = (13.12 + 0.6215 * temp - 11.37 * wind2 + 0.3965 * temp * wind2);
wind_chill = parseFloat(wind_chill.toFixed(2));
wind_chill = (wind <= 4.8) ? temp : wind_chill;
wind_chill = (temp > 10) ? temp : wind_chill;
return wind_chill;
}
// PHP version
// wind = wind speed in knots
// temp = temperature in Celsius
function getWindChill($wind, $temp) {
$wind = $wind * 1.852;
$wind2 = pow($wind, 0.16);
$wind_chill = (13.12 + 0.6215 * $temp - 11.37 * $wind2 + 0.3965 * $temp * $wind2);
$wind_chill = round($wind_chill, 2);
$wind_chill = ($wind <= 4.8) ? $temp : $wind_chill;
$wind_chill = ($temp > 10) ? $temp : $wind_chill;
return $wind_chill;
}
# Ruby version # wind = wind speed in knots # temp = temperature in Celsius def getWindChill(wind, temp) wind = (wind * 1.852) wind2 = wind**0.16 wind_chill = (13.12 + 0.6215 * temp - 11.37 * wind2 + 0.3965 * temp * wind2) (temp > 10) ? temp : (wind <= 4.8) ? temp : (wind_chill * 100).round.to_f / 100 end
As you can see, pretty simple, but hopefully one will prove useful to someone someday.
Tags: calculator, functions, Javascript, PHP, ruby, wind chill



