This package primarily provides some weather/atmospheric-related calculations. It also provides types for these calculations to traffic, helping to reduce the chance of mixing up units.
For example, these types prevent accidentally using a Celsius temperature as a Fahrenheit temperature:
Documentation: pkg.go.dev/github.com/cdzombak/libwx
go get github.com/cdzombak/libwx
DewPointF()
and DewPointC()
calculate the dew point given a temperature and relative humidity.
IndoorHumidityRecommendationF()
and IndoorHumidityRecommendationC()
provide a recommended maximum indoor humidity percentage for the given outdoor temperature.
WindChillF()
and WindChillC()
calculate the wind chill given the outdoor temperature and wind speed.
The following distance types are provided:
Mile
Meter
Km
(kilometer)NauticalMile
Each type provides methods to convert to the other types (e.g. NauticalMile.Meters()
). An Unwrap()
method also exists to get the raw value as a float64
.
The RelHumidity
type is an integer type representing a relative humidity percentage from 0-100
, inclusive. A clamping method and function for this range are provided.
An Unwrap()
method also exists to get the raw value as an int
.
The following pressure types are provided:
PressureInHg
(inches of mercury)PressureMb
(millibars)
Each type provides methods to convert to the other type (e.g. PressureInHg.Mb()
). An Unwrap()
method also exists to get the raw value as a float64
.
The following speed types are provided:
SpeedMph
(miles per hour)SpeedKmh
(kilometers per hour)SpeedKnots
(knots)
Each type provides methods to convert to the other types (e.g. SpeedKnots.Mph()
). An Unwrap()
method also exists to get the raw value as a float64
.
The following temperature types are provided:
Each type provides methods to convert to the other type (e.g. TempF.C()
). An Unwrap()
method also exists to get the raw value as a float64
.
Finally, libwx
provides some utility functions for comparing float64
and int
values:
IntCompare(a, b int) int
Float64Compare(a, b, tolerance float64) int
Float64Equal(a, b, tolerance float64) bool
The *Compare(…)
functions return:
-1
ifa < b
0
ifa == b
1
ifa > b
For float64
comparisons functions that accept a tolerance
, convenience tolerance constants are provided:
ToleranceExact = float64(0.0)
Tolerance0 = float64(1.0)
Tolerace1 = float64(0.1)
Tolerance01 = float64(0.01)
Tolerance001 = float64(0.001)
When making repeated comparisons with the same tolerance, having to pass the tolerance each time is tedious and increases room for human error. To help with this, curried versions of Float64Compare()
and Float64Equal()
are provided. These return a comparison function with the specified tolerance baked-in:
CurriedFloat64Compare(tolerance float64) func(float64, float64) int
CurriedFloat64Equal(tolerance float64) func(float64, float64) bool
For example:
package main
import (
wx "github.com/cdzombak/libwx"
)
function main() {
equalityChecker := wx.CurriedFloat64Equal(Tolerance1)
equalityChecker(1.0, 1.11) // => false
equalityChecker(1.0, 1.01) // => true
}
MIT; see LICENSE in this repo.
Chris Dzombak