WindChill example:
/+
' Wind Chill for exposed human skin, expressed as a function of wind
' speed in Miles per Hour and temperature in degrees Fahrenheit.
'
' Public domain from numerous published references.
'
' To Compile: C:\dmd\MKod_ex>dmd windchill.d
'
' 02.Oct.04 Compiled and Tested with dmd v0.102
' 04.Jun.06 Compiled and Tested with dmd v0.160
' 10.Jan.07 Compiled and Tested with dmd v1.0
'
+/
private import std.math;
private import std.stdio;
/+
' Returns the Degrees that exposed human skin feels after
' calculating the current temperature and windspeed together.
'
' -- cDegreeType --
' 'F' = Fahrenheit
' 'C' = Celsius
'
+/
double windchill
(
in double dtemperature,
in int iwindspeed,
in char cDegreeType = 'F'
)
{
double dWindChill = 0.0;
if ( cDegreeType == 'C' || cDegreeType == 'c' )
{
dWindChill = convertCelsius2Fahrenheit( dtemperature );
}
if ( 4 > iwindspeed )
dWindChill = dtemperature;
else
{
dWindChill = ( ( ( 10.45 + ( 6.686112 * sqrt( cast(double)iwindspeed ) )
- ( .447041 * iwindspeed ) ) / 22.034 * ( dtemperature - 91.4 ) ) + 91.4 );
}
if ( cDegreeType == 'C' || cDegreeType == 'c' )
return convertFahrenheit2Celsius( dWindChill );
else
return dWindChill;
} // end double windchill( in double, in int, char = 'F' )
int main()
{
writefln( "Wind Chill for:" );
writefln( "32.0 Fahrenheit, 15mph winds...%3.1f Fahrenheit", windchill( 32.0, 15 ) );
writefln( "45.0 Fahrenheit, 17mph winds...%3.1f Fahrenheit", windchill( 45.0, 17 ) );
writefln();
writefln( "convertFahrenheit2Celsius( 32.0 ) = %3.1f Celsius", convertFahrenheit2Celsius( 32.0 ) );
writefln( "convertFahrenheit2Celsius( 45.0 ) = %3.1f Celsius", convertFahrenheit2Celsius( 45.0 ) );
writefln();
writefln( "Wind Chill for:" );
writefln( "0.0 Celsius, 15mph winds...%3.1f Celsius, %3.1f Fahrenheit",
windchill( 0.0, 15, 'C' ), windchill( convertCelsius2Fahrenheit( 0.0 ), 15 ) );
writefln( "7.2 Celsius, 17mph winds...%3.1f Celsius, %3.1f Fahrenheit", windchill( 7.2, 17, 'C' ),
windchill( convertCelsius2Fahrenheit( 7.2 ), 17 ) );
return 0;
} // end int main()
double convertFahrenheit2Celsius
(
in double dFahrenheit
)
{
return ( dFahrenheit - 32 ) * 5 / 9;
} // end double convertFahrenheit2Celsius( in double )
double convertCelsius2Fahrenheit
(
in double dCelsius
)
{
return dCelsius * 9 / 5 + 32;
} // end double convertCelsius2Fahrenheit( in double )
C:\dmd\MKoD_ex>..\bin\dmd windchill.d
C:\dmd\bin\..\..\dm\bin\link.exe windchill,,,user32+kernel32/noi;
C:\dmd\MKoD_ex>windchill
Wind Chill for:
32.0 Fahrenheit, 15mph winds...11.5 Fahrenheit
45.0 Fahrenheit, 17mph winds...27.3 Fahrenheit
convertFahrenheit2Celsius( 32.0 ) = 0.0 Celsius
convertFahrenheit2Celsius( 45.0 ) = 7.2 Celsius
Wind Chill for:
0.0 Celsius, 15mph winds...-35.3 Celsius, 11.5 Fahrenheit
7.2 Celsius, 17mph winds...-31.6 Celsius, 27.3 Fahrenheit
C:\dmd\MKoD_ex>