Skip to content

Instantly share code, notes, and snippets.

@AngeloStavrow
Last active September 17, 2016 15:05
Show Gist options
  • Save AngeloStavrow/c858bf4d80f25744518ef90baf378e75 to your computer and use it in GitHub Desktop.
Save AngeloStavrow/c858bf4d80f25744518ef90baf378e75 to your computer and use it in GitHub Desktop.
Playing with Swift 3's Units and Measurements to calculate humidex values.
import Foundation
// The air temperature in degrees Celsius.
var airTemperature = Measurement(value: 29.74, unit: UnitTemperature.celsius)
// The dewpoint temperature in degrees Celsius.
var dewpoint = Measurement(value: 19.08, unit: UnitTemperature.celsius)
// Calculate the humidex value.
let humidex = airTemperature.value + 0.5555 * ((6.11 * exp(5417.7530 * ((1/273.16) - (1/dewpoint.converted(to: UnitTemperature.kelvin).value)))) - 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment