Channels ▼
RSS

Design

C Snippet #4


Q: HOW DO I... compute the wind chill factor from temperature and wind speed?

A: Okay, so I've only seen this question come up twice. It's still a fascinating Snippet which could potentially save someone hours of research.



#include <math.h>
 
float wind_chill(int wind_speed, int temp)
{
      return (((10.45 + (6.686112 * sqrt((double) wind_speed))
            - (.447041 * wind_speed)) / 22.034 * (temp - 91.4)) + 91.4);
}

Updates to C Snippet #4


/*********************************************************/
/**** weather.h ****/

/*
**  SNIPPETS header file for weather functions
*/

#ifndef WEATHER__H
#define WEATHER__H

#include "metric.h"
#include "sniptype.h"

double wind_chill(int flag, double temp, double wind_speed);
double heat_index(int flag, double temp, double rh);

#endif /* WEATHER__H */


/*********************************************************/
/**** weather.c ****/


/*
**  SNIPPETS weaather functions
**
**  Public domain, based on the standard NOAA formuolas.
*/

/*
**  Wind Chill for exposed human skin, expressed as a function of wind
**  speed in Miles per Hour and temperature in degrees Fahrenheit.
**
**  Parameters: 1 - Metric flag
**              2 - Temperature (degrees F or C)
**              3 - Wind speed (mph or kph)
**
**  Returns: Wind chill in degreers F or C to match the input
*/

#include <math.h>
#include "weather.h"
 
double wind_chill(int flag, double temp, double wind_speed)
{
      double retval;

      if (flag)   // Convert to English if metric
      {
            temp = C_to_F(temp);
            wind_speed = KPH_to_MPH(wind_speed);
      }
      retval = temp;

      if (wind_speed >= 3.0 && temp <= 50.0)
      {
            double V2 = pow(wind_speed, 0.16);
            
            retval = 35.74 + (0.6215 * temp) - (35.75 * V2) + (0.4275 * temp * V2);
      }
      if (flag)
            retval = F_to_C(retval);
      return retval;
}

/*
**  Heat Index for an everage size human in late morning or early afternoon with a wind
**  speed of ~6 MPH, expressed as a function of relative humidity and temperature.
**
**  Parameters: 1 - Metric flag
**              2 - Temperature (degrees F or C)
**              3 - Relative huidity (percent)
**
**  Returns: Heat index in degreers F or C to match the input
*/

double heat_index(int flag, double temp, double rh)
{
      double retval;

      if (flag)   // Convert to English if metric
            temp = C_to_F(temp);
      retval = temp;

      if (rh >= 40.0 && temp >= 80.0)
      {
            double T2 = temp*temp, R2 = rh*rh;
            double coeff[] = {-42.379, 2.04901523, 10.14333127, -0.22475541,
                              -6.83783E-3, -5.481717E-2, 1.22874E-3, 8.5282E-4,
                              -1.99E-6};

            retval = coeff[0] +
                     coeff[1] * temp +
                     coeff[2] * rh +
                     coeff[3] * temp * rh +
                     coeff[4] * T2 +
                     coeff[5] * R2 +
                     coeff[6] * T2 * rh +
                     coeff[7] * temp * R2 +
                     coeff[8] * T2 * R2;
      }
      if (flag)
            retval = F_to_C(retval);
      return retval;
}

#ifdef TEST
#include <stdio.h>

int main(void)
{
      // Test data
      double Tf[] =     // Temp in degrees F
      {65, 20, 0, -20, 80, 90, 100};
      double Tc[] =     // Temp in degrees C
      {18.33333, -6.666667, -17.77778, -28.88889, 26.66667, 32.22222, 37.77778};
      double Wm[] =     // Wind speed in MPH
      {0, 100, 10, 30};
      double Wk[] =     // Wind speed in KPH
      {0, 160.9344, 16.09344, 48.28032};
      double Hr[] =     // Relative humidity in percent
      {0, 100, 60, 90};
      double WCf[] =    // Wind chill in degrees F
      {9, 1, -16, -26, -40, -53};
      double WCc[] =    // Wind chill in degrees C
      {-12.77778, -17.22222, -26.66667, -32.22222, -40, -47.22222};
      double HIf[] =    // Heat index in degrees F
      {81, 85, 99, 121, 129};
      double HIc[] =    // Heat index in degrees F
      {27.22222, 29.44444, 37.22222, 49.44444, 53.88889};

      puts("Apparent Temperaures");
      puts("--------------------");
      puts("The following tests use equivalent data for English and metric units:");
      puts("\nThese should all return 65F or 18.33333C");
      printf("wind_chill(%d, %fF, %fMPH) = %fF\n",
             False_, Tf[0], Wm[0], wind_chill(False_, Tf[0], Wm[0]));
      printf("wind_chill(%d, %fF, %fMPH) = %fF\n",
             False_, Tf[0], Wm[1], wind_chill(False_, Tf[0], Wm[1]));
      printf("wind_chill(%d, %fC, %fKPH) = %fC\n",
             True_, Tc[0], Wk[0], wind_chill(True_, Tc[0], Wk[0]));
      printf("wind_chill(%d, %fC, %fKPH) = %fC\n",
             True_, Tc[0], Wk[1], wind_chill(True_, Tc[0], Wk[1]));
      printf("heat_index(%d, %fF, %f%%) = %fF\n",
             False_, Tf[0], Hr[0], heat_index(False_, Tf[0], Hr[0]));
      printf("heat_index(%d, %fF, %f%%) = %fF\n",
             False_, Tf[0], Hr[1], heat_index(False_, Tf[0], Hr[1]));
      printf("heat_index(%d, %fC, %f%%) = %fC\n",
             True_, Tc[0], Hr[0], heat_index(True_, Tc[0], Hr[0]));
      printf("heat_index(%d, %fC, %f%%) = %fC\n",
             True_, Tc[0], Hr[1], heat_index(True_, Tc[0], Hr[1]));

      puts("\nThese should all return the indicated values");
      printf("wind_chill(%d, %fF, %fMPH) = %fF (should be %fF)\n",
             False_, Tf[1], Wm[2], wind_chill(False_, Tf[1], Wm[2]), WCf[0]);
      printf("wind_chill(%d, %fF, %fMPH) = %fF (should be %fF)\n",
             False_, Tf[1], Wm[3], wind_chill(False_, Tf[1], Wm[3]), WCf[1]);
      printf("wind_chill(%d, %fF, %fMPH) = %fF (should be %fF)\n",
             False_, Tf[2], Wm[2], wind_chill(False_, Tf[2], Wm[2]), WCf[2]);
      printf("wind_chill(%d, %fF, %fMPH) = %fF (should be %fF)\n",
             False_, Tf[2], Wm[3], wind_chill(False_, Tf[2], Wm[3]), WCf[3]);
      printf("wind_chill(%d, %fF, %fMPH) = %fF (should be %fF)\n",
             False_, Tf[3], Wm[2], wind_chill(False_, Tf[3], Wm[2]), WCf[4]);
      printf("wind_chill(%d, %fF, %fMPH) = %fF (should be %fF)\n",
             False_, Tf[3], Wm[3], wind_chill(False_, Tf[3], Wm[3]), WCf[5]);

      printf("wind_chill(%d, %fC, %fKPH) = %fC (should be %fC)\n",
             True_, Tc[1], Wk[2], wind_chill(True_, Tc[1], Wk[2]), WCc[0]);
      printf("wind_chill(%d, %fC, %fKPH) = %fC (should be %fC)\n",
             True_, Tc[1], Wk[3], wind_chill(True_, Tc[1], Wk[3]), WCc[1]);
      printf("wind_chill(%d, %fC, %fKPH) = %fC (should be %fC)\n",
             True_, Tc[2], Wk[2], wind_chill(True_, Tc[2], Wk[2]), WCc[2]);
      printf("wind_chill(%d, %fC, %fKPH) = %fC (should be %fC)\n",
             True_, Tc[2], Wk[3], wind_chill(True_, Tc[2], Wk[3]), WCc[3]);
      printf("wind_chill(%d, %fC, %fKPH) = %fC (should be %fC)\n",
             True_, Tc[3], Wk[2], wind_chill(True_, Tc[3], Wk[2]), WCc[4]);
      printf("wind_chill(%d, %fC, %fKPH) = %fC (should be %fC)\n",
             True_, Tc[3], Wk[3], wind_chill(True_, Tc[3], Wk[3]), WCc[5]);
      puts("");
      printf("heat_index(%d, %fF, %f%%) = %fF (should be %fF)\n",
             False_, Tf[4], Hr[2], heat_index(False_, Tf[4], Hr[2]), HIf[0]);
      printf("heat_index(%d, %fF, %f%%) = %fF (should be %fF)\n",
             False_, Tf[4], Hr[3], heat_index(False_, Tf[4], Hr[3]), HIf[1]);
      printf("heat_index(%d, %fF, %f%%) = %fF (should be %fF)\n",
             False_, Tf[5], Hr[2], heat_index(False_, Tf[5], Hr[2]), HIf[2]);
      printf("heat_index(%d, %fF, %f%%) = %fF (should be %fF)\n",
             False_, Tf[5], Hr[3], heat_index(False_, Tf[5], Hr[3]), HIf[3]);
      printf("heat_index(%d, %fF, %f%%) = %fF (should be %fF)\n",
             False_, Tf[6], Hr[2], heat_index(False_, Tf[6], Hr[2]), HIf[4]);
      printf("heat_index(%d, %fC, %f%%) = %fC (should be %fC)\n",
             True_, Tc[4], Hr[2], heat_index(True_, Tc[4], Hr[2]), HIc[0]);
      printf("heat_index(%d, %fC, %f%%) = %fC (should be %fC)\n",
             True_, Tc[4], Hr[3], heat_index(True_, Tc[4], Hr[3]), HIc[1]);
      printf("heat_index(%d, %fC, %f%%) = %fC (should be %fC)\n",
             True_, Tc[5], Hr[2], heat_index(True_, Tc[5], Hr[2]), HIc[2]);
      printf("heat_index(%d, %fC, %f%%) = %fC (should be %fC)\n",
             True_, Tc[5], Hr[3], heat_index(True_, Tc[5], Hr[3]), HIc[3]);
      printf("heat_index(%d, %fC, %f%%) = %fC (should be %fC)\n",
             True_, Tc[6], Hr[2], heat_index(True_, Tc[6], Hr[2]), HIc[4]);

      puts("\nNote: The formulas are approximations. Exposure to direct sunlight can");
      puts("      cause the apparent tmperatures to be higher.");

      return EXIT_SUCCESS;
}

#endif // TEST


/*********************************************************/
/**** sniptype.h ****/

/*
**  SNIPTYPE.H - Include file for SNIPPETS data types and commonly used macros
*/

#ifndef SNIPTYPE__H
#define SNIPTYPE__H

#include <stdlib.h>                             /* For free()           */
#include <string.h>                             /* For NULL & strlen()  */

typedef enum {Error_ = -1, Success_, False_ = 0, True_} Boolean_T;

#ifdef BYTE
 #undef BYTE
#endif
#ifdef WORD
 #undef WORD
#endif
#  ifdef DWORD
 #undef DWORD
#endif
typedef unsigned char  BYTE;
typedef unsigned short WORD;
typedef unsigned long  DWORD;

typedef union {
      signed char       c;
      BYTE              b;
} VAR8_;

typedef union {
      VAR8_             v8[2];
      signed short      s;
      WORD              w;
} VAR16_;

typedef union {
      VAR16_            v16[2];
      signed long       l;
      DWORD             dw;
      float             f;
      void              *p;
} VAR32_;

typedef union {
      VAR32_            v32[2];
      double            d;
} VAR64_;

#define NUL '\0'
#define LAST_CHAR(s) (((char *)s)[strlen(s) - 1])
#define TOBOOL(x) (!(!(x)))
#define FREE(p) (free(p),(p)=NULL)

#endif /* SNIPTYPE__H */

/*********************************************************/
/**** metric.h ****/

/*************************************************
*
*         ANSI C Metric Conversion Macros
*              Mike Smith, Freeware
*   6 Grenville Road, Plymouth, England, PL4 9PX
*
*             mike@msmith.demon.co.uk
*
*   Version: 1.03
*   History: 5th of May, 1997
*
*   1.01 Taken out formulas and added values only Mon 17th April 1995
*   1.02 Error corrections Sat 13th July 1996
*   1.03 Added macros 5th of May, 1997
*   1.04 Added dram <-> fl.oz. macros (RBS) 21-Aug-1998
*   1.05 Added in.^3 <-> l. macros (RBS) 05-Sep-1998
*   2.00 Added C++, velocity and temperature macros (RBS) 23-Sep-2009
*
**************************************************/

#ifndef METRIC__H
#define METRIC__H


#if !(defined(__cplusplus) && __cplusplus)

/******** Length Conversion Macros **********/

#define CM_to_IN(x) (0.3937 * (x))
#define IN_to_CM(x) (2.54 * (x))
#define IN_to_M(x) (0.0254 * (x))
#define IN_to_MM(x) (25.4 * (x))
#define KM_to_MILE(x) (0.6214 * (x))
#define M_to_IN(x) (39.37 * (x))
#define M_to_FT(x) (3.28083 * (x))
#define M_to_YARD(x) (1.093611 * (x))
#define MILE_to_KM(x) (1.609 * (x))
#define MM_to_IN(x) (0.03937 * (x))
#define YARD_to_M(x) (0.9144 * (x))
#define IN_to_FT(x) ((x) / 12.0)
#define IN_to_YARD(x) ((x) / 36.0)
#define IN_to_MILE(x) ((x) / 63360.0)
#define FT_to_IN(x) (12.0 * (x))
#define FT_to_M(x) (0.3048 * (x))
#define FT_to_YARD(x) ((x) / 3.0)
#define FT_to_MILE(x) ((x) / 5280.0)
#define MILE_to_IN(x) (63360.0 * (x))
#define MILE_to_FT(x) (5280.0 * (x))
#define MILE_to_YARD(x) (1760.0 * (x))

#define AWG_to_IN(awg) (0.46/pow(1.1229283027,(awg)+3))

/******* Weight/Mass Macros ************/

#define G_to_OZ(x) (0.03527 * (x))
#define KG_to_LBS(x) (2.2046 * (x))
#define LBS_to_KG(x) (0.4545 * (x))
#define LBS_to_OZ(x) (16.0 * (x))
#define OZ_to_G(x) (28.3527 * (x))
#define OZ_to_LBS(x) ((x) / 16.0)

/******* Velocity Conversion Macros ********/

#define MPH_to_KPH(x) MILE_to_KM(x)
#define KPH_to_MPH(x) KM_to_MILE(x)
#define FPS_to_MPS(x) FT_to_M(x)
#define MPS_to_FPS(x) M_to_FT(x)

/******* Temperature Conversion Macros ********/

#define C_to_F(x) (1.8 * (x) + 32)
#define F_to_C(x) (((x) - 32) / 1.8)

/******* Liquid Conversion Macros ********/

#define CL_to_OZ(x) (0.338 * (x))
#define ML_to_OZ(x) (0.0338 * (x))
#define OZ_to_CL(x) (2.95857988 * (x))
#define OZ_to_ML(x) (29.5857 * (x))

#define OZ_to_DRAM(x) (16.0 * (x))
#define DRAM_to_OZ(x) (0.0625 * (x))

/***********************************************
*
*      In case you are unaware there are:
*           16 ounces in a US quart
*           20 ounces in a UK quart
*
*  This, of course, makes gallons different
*     too.  Supplied below are US to UK
*           conversions as well.
*
************************************************/

#define KL_to_UKGAL(x) (211.344 * (x))
#define KL_to_USGAL(x) (264.18 * (x))
#define L_to_UKGAL(x) (0.2199 * (x))
#define L_to_UKQ(x) (0.945 * (x))
#define L_to_USGAL(x) (0.26455 * (x))
#define L_to_USQ(x) (1.0582 * (x))
#define L_to_CM3(x) (1000.0 * (x))
#define UKGAL_to_KL(x) (0.0047316 * (x))
#define UKGAL_to_L(x) (4.546 * (x))
#define UKGAL_to_USGAL(x) (1.25 * (x))
#define UKQ_to_L(x) (1.0582 * (x))
#define UKQ_to_USQ(x) (1.25 * (x))
#define USGAL_to_KL(x) (0.003785 * (x))
#define USGAL_to_L(x) (3.78 * (x))
#define USGAL_to_UKGAL(x) (0.8 * (x))
#define USQ_to_L(x) (0.945 * (x))
#define USQ_to_UKQ(x) (0.8 * (x))
#define CM3_to_L(x) (0.001 * (x))

/**** Area Conversion Macros ****/

#define CM2_to_IN2(x) (0.155 * (x))
#define FT2_to_M2(x) (0.0930 * (x))
#define IN2_to_CM2(x) (6.4516 * (x))
#define IN2_to_MM2(x) (645.161 * (x))
#define KM2_to_MILE2(x) (0.386 * (x))
#define M2_to_FT2(x) (10.75 * (x))
#define MILE2_to_KM2(x) (2.5906 * (x))
#define MM2_to_IN2(x) (0.00155 * (x))

/******** Volume Conversion Macros *********/

#define CM3_to_IN3(x) (0.061 * (x))
#define IN3_to_CC(x) (16.3934 * (x))
#define IN3_to_CM3(x) (16.3934 * (x))
#define KM3_to_MILE3(x) (0.25 * (x))
#define M3_to_YARD3(x) (1.308 * (x))
#define MILE3_to_KM3(x) (4.0 * (x))
#define YARD3_to_M3(x) (0.764526 * (x))
#define M3_to_FT3(x) (35.3144754 * (x))
#define FT3_to_M3(x) (2.8317e-2 * (x))

#define L_to_IN3(x) (CM3_to_IN3(L_to_CM3(x)))
#define IN3_to_L(x) (CM3_to_L(IN3_to_CM3(x)))
#define L_to_FT3(x) (L_to_IN3(x) / 1728)
#define FT3_to_L(x) (IN3_to_L((x) * 1728))

#else // C++

/******** Length Conversion Functions **********/

inline double CM_to_IN(double x) {return 0.3937 * x;}
inline double IN_to_CM(double x) {return 2.54 * x;}
inline double IN_to_M(double x) {return 0.0254 * x;}
inline double IN_to_MM(double x) {return 25.4 * x;}
inline double KM_to_MILE(double x) {return 0.6214 * x;}
inline double M_to_IN(double x) {return 39.37 * x;}
inline double M_to_FT(double x) {return 3.28083 * x;}
inline double M_to_YARD(double x) {return 1.093611 * x;}
inline double MILE_to_KM(double x) {return 1.609 * x;}
inline double MM_to_IN(double x) {return 0.03937 * x;}
inline double YARD_to_M(double x) {return 0.9144 * x;}
inline double IN_to_FT(double x) {return x / 12.0;}
inline double IN_to_YARD(double x) {return x / 36.0;}
inline double IN_to_MILE(double x) {return x / 63360.0;}
inline double FT_to_IN(double x) {return 12.0 * x;}
inline double FT_to_M(double x) {return 0.3048 * x;}
inline double FT_to_YARD(double x) {return x / 3.0;}
inline double FT_to_MILE(double x) {return x / 5280.0;}
inline double MILE_to_IN(double x) {return 63360.0 * x;}
inline double MILE_to_FT(double x) {return 5280.0 * x;}
inline double MILE_to_YARD(double x) {return 1760.0 * x;}

inline double AWG_to_IN(double awg) {return 0.46/pow(1.1229283027,awg+3);}

/******* Weight/Mass Functions ************/

inline double G_to_OZ(double x) {return 0.03527 * x;}
inline double KG_to_LBS(double x) {return 2.2046 * x;}
inline double LBS_to_KG(double x) {return 0.4545 * x;}
inline double LBS_to_OZ(double x) {return 16.0 * x;}
inline double OZ_to_G(double x) {return 28.3527 * x;}
inline double OZ_to_LBS(double x) {return x / 16.0;}

/******* Velocity Conversion Functions ********/

inline double MPH_to_KPH(double x) {return MILE_to_KM(x);}
inline double KPH_to_MPH(double x) {return KM_to_MILE(x);}
inline double FPS_to_MPS(double x) {return FT_to_M(x);}
inline double MPS_to_FPS(double x) {return M_to_FT(x);}

/******* Temperature Conversion Functions ********/

inline double C_to_F(double x) {return 1.8 * x + 32;}
inline double F_to_C(double x) {return (x - 32) / 1.8;}

/******* Liquid Conversion Functions ********/

inline double CL_to_OZ(double x) {return 0.338 * x;}
inline double ML_to_OZ(double x) {return 0.0338 * x;}
inline double OZ_to_CL(double x) {return 2.95857988 * x;}
inline double OZ_to_ML(double x) {return 29.5857 * x;}

inline double OZ_to_DRAM(double x) {return 16.0 * x;}
inline double DRAM_to_OZ(double x) {return 0.0625 * x;}

/***********************************************
*
*      In case you are unaware there are:
*           16 ounces in a US quart
*           20 ounces in a UK quart
*
*  This, of course, makes gallons different
*     too.  Supplied below are US to UK
*           conversions as well.
*
************************************************/

inline double KL_to_UKGAL(double x) {return 211.344 * x;}
inline double KL_to_USGAL(double x) {return 264.18 * x;}
inline double L_to_UKGAL(double x) {return 0.2199 * x;}
inline double L_to_UKQ(double x) {return 0.945 * x;}
inline double L_to_USGAL(double x) {return 0.26455 * x;}
inline double L_to_USQ(double x) {return 1.0582 * x;}
inline double L_to_CM3(double x) {return 1000.0 * x;}
inline double UKGAL_to_KL(double x) {return 0.0047316 * x;}
inline double UKGAL_to_L(double x) {return 4.546 * x;}
inline double UKGAL_to_USGAL(double x) {return 1.25 * x;}
inline double UKQ_to_L(double x) {return 1.0582 * x;}
inline double UKQ_to_USQ(double x) {return 1.25 * x;}
inline double USGAL_to_KL(double x) {return 0.003785 * x;}
inline double USGAL_to_L(double x) {return 3.78 * x;}
inline double USGAL_to_UKGAL(double x) {return 0.8 * x;}
inline double USQ_to_L(double x) {return 0.945 * x;}
inline double USQ_to_UKQ(double x) {return 0.8 * x;}
inline double CM3_to_L(double x) {return 0.001 * x;}

/**** Area Conversion Functions ****/

inline double CM2_to_IN2(double x) {return 0.155 * x;}
inline double FT2_to_M2(double x) {return 0.0930 * x;}
inline double IN2_to_CM2(double x) {return 6.4516 * x;}
inline double IN2_to_MM2(double x) {return 645.161 * x;}
inline double KM2_to_MILE2(double x) {return 0.386 * x;}
inline double M2_to_FT2(double x) {return 10.75 * x;}
inline double MILE2_to_KM2(double x) {return 2.5906 * x;}
inline double MM2_to_IN2(double x) {return 0.00155 * x;}

/******** Volume Conversion Functions *********/

inline double CM3_to_IN3(double x) {return 0.061 * x;}
inline double IN3_to_CC(double x) {return 16.3934 * x;}
inline double IN3_to_CM3(double x) {return 16.3934 * x;}
inline double KM3_to_MILE3(double x) {return 0.25 * x;}
inline double M3_to_YARD3(double x) {return 1.308 * x;}
inline double MILE3_to_KM3(double x) {return 4.0 * x;}
inline double YARD3_to_M3(double x) {return 0.764526 * x;}
inline double M3_to_FT3(double x) {return 35.3144754 * x;}
inline double FT3_to_M3(double x) {return 2.8317e-2 * x;}

inline double L_to_IN3(double x) {return CM3_to_IN3(L_to_CM3(x));}
inline double IN3_to_L(double x) {return CM3_to_L(IN3_to_CM3(x));}
inline double L_to_FT3(double x) {return L_to_IN3(x / 1728);}
inline double FT3_to_L(double x) {return IN3_to_L(x * 1728);}

#endif // C++

#endif   /* METRIC__H */

/*********************************************************/
/**** weather.out ****/

Apparent Temperaures
--------------------
The following tests use equivalent data for English and metric units:

These should all return 65F or 18.33333C
wind_chill(0, 65.000000F, 0.000000MPH) = 65.000000F
wind_chill(0, 65.000000F, 100.000000MPH) = 65.000000F
wind_chill(1, 18.333330C, 0.000000KPH) = 18.333330C
wind_chill(1, 18.333330C, 160.934400KPH) = 18.333330C
heat_index(0, 65.000000F, 0.000000%) = 65.000000F
heat_index(0, 65.000000F, 100.000000%) = 65.000000F
heat_index(1, 18.333330C, 0.000000%) = 18.333330C
heat_index(1, 18.333330C, 100.000000%) = 18.333330C

These should all return the indicated values
wind_chill(0, 20.000000F, 10.000000MPH) = 8.854038F (should be 9.000000F)
wind_chill(0, 20.000000F, 30.000000MPH) = 1.298559F (should be 1.000000F)
wind_chill(0, 0.000000F, 10.000000MPH) = -15.934472F (should be -16.000000F)
wind_chill(0, 0.000000F, 30.000000MPH) = -25.864927F (should be -26.000000F)
wind_chill(0, -20.000000F, 10.000000MPH) = -40.722982F (should be -40.000000F)
wind_chill(0, -20.000000F, 30.000000MPH) = -53.028413F (should be -53.000000F)
wind_chill(1, -6.666667C, 16.093440KPH) = -12.859030C (should be -12.777780C)
wind_chill(1, -6.666667C, 48.280320KPH) = -17.056550C (should be -17.222220C)
wind_chill(1, -17.777780C, 16.093440KPH) = -26.630478C (should be -26.666670C)
wind_chill(1, -17.777780C, 48.280320KPH) = -32.147439C (should be -32.222220C)
wind_chill(1, -28.888890C, 16.093440KPH) = -40.401922C (should be -40.000000C)
wind_chill(1, -28.888890C, 48.280320KPH) = -47.238323C (should be -47.222220C)

heat_index(0, 80.000000F, 60.000000%) = 81.810923F (should be 81.000000F)
heat_index(0, 80.000000F, 90.000000%) = 85.641892F (should be 85.000000F)
heat_index(0, 90.000000F, 60.000000%) = 99.677718F (should be 99.000000F)
heat_index(0, 90.000000F, 90.000000%) = 121.901204F (should be 121.000000F)
heat_index(0, 100.000000F, 60.000000%) = 129.489027F (should be 129.000000F)
heat_index(1, 26.666670C, 60.000000%) = 27.672739C (should be 27.222220C)
heat_index(1, 26.666670C, 90.000000%) = 29.801060C (should be 29.444440C)
heat_index(1, 32.222220C, 60.000000%) = 37.598727C (should be 37.222220C)
heat_index(1, 32.222220C, 90.000000%) = 49.945103C (should be 49.444440C)
heat_index(1, 37.777780C, 60.000000%) = 54.160579C (should be 53.888890C)

Note: The formulas are approximations. Exposure to direct sunlight can cause the apparent tmperatures to be higher.

Note: The formulas are approximations. Exposure to direct sunlight can cause the apparent temperatures to be higher.

More C Snippets

All the code in C Snippets is either public domain or freeware and may therefore freely be used by the C programming community without restrictions. In most cases, if the original author is someone other than myself he or she will be identified. Thanks to all who have contributed to this collection over the years. I hope Dr. Dobb's readers will find these useful.

--Bob Stout
rbs@snippets.org


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video