Documentation
¶
Overview ¶
Package units is a library for looking up units, and for manipulating and converting between various units of measurement.
Index ¶
- Constants
- Variables
- func GetCsv() []string
- func NewConversion(from, to *Unit, formula string) (err error)
- func NewConversionFromFn(from, to *Unit, f ConversionFn, formula string)
- func NewRatioConversion(from, to *Unit, ratio float64)
- type AddResult
- type Conversion
- type ConversionFn
- type FmtOptions
- type Unit
- func All() []*Unit
- func Atto(b *Unit, o ...UnitOption) *Unit
- func Centi(b *Unit, o ...UnitOption) *Unit
- func Deca(b *Unit, o ...UnitOption) *Unit
- func Deci(b *Unit, o ...UnitOption) *Unit
- func Exa(b *Unit, o ...UnitOption) *Unit
- func Femto(b *Unit, o ...UnitOption) *Unit
- func Find(s string) (*Unit, error)
- func Giga(b *Unit, o ...UnitOption) *Unit
- func Hecto(b *Unit, o ...UnitOption) *Unit
- func Kilo(b *Unit, o ...UnitOption) *Unit
- func Mega(b *Unit, o ...UnitOption) *Unit
- func Micro(b *Unit, o ...UnitOption) *Unit
- func Milli(b *Unit, o ...UnitOption) *Unit
- func Nano(b *Unit, o ...UnitOption) *Unit
- func NewUnit(name, symbol string, opts ...UnitOption) (*Unit, error)
- func Peta(b *Unit, o ...UnitOption) *Unit
- func Pico(b *Unit, o ...UnitOption) *Unit
- func Quecto(b *Unit, o ...UnitOption) *Unit
- func Quetta(b *Unit, o ...UnitOption) *Unit
- func Ronna(b *Unit, o ...UnitOption) *Unit
- func Ronto(b *Unit, o ...UnitOption) *Unit
- func Tera(b *Unit, o ...UnitOption) *Unit
- func Yocto(b *Unit, o ...UnitOption) *Unit
- func Yotta(b *Unit, o ...UnitOption) *Unit
- func Zepto(b *Unit, o ...UnitOption) *Unit
- func Zetta(b *Unit, o ...UnitOption) *Unit
- func (u *Unit) AddAliases(aliases ...string) *AddResult
- func (u *Unit) AddSymbols(symbols ...string) *AddResult
- func (u *Unit) Aliases() []string
- func (u *Unit) ConvertTo(value float64, to *Unit) (Value, error)
- func (u *Unit) CsvLine() string
- func (u *Unit) HasName(alias string) bool
- func (u *Unit) HasSymbol(symbol string) bool
- func (u *Unit) Names() []string
- func (u *Unit) PluralName() string
- func (u *Unit) String() string
- func (u *Unit) Symbols() []string
- func (u *Unit) System() UnitSystem
- type UnitList
- type UnitOption
- type UnitQuantity
- type UnitSystem
- type Value
Constants ¶
const ( // PluralNone is a keyword for a unit that has no plural PluralNone = "<|_none_|>" // PluralAuto is a keyword for a unit that has an auto-generated plural PluralAuto = "<|_auto_|>" )
const CsvHeader = "Name,Symbol,PluralName,Quantity,System,Aliases & Symbols"
CsvHeader is the header row for the CSV output (> see func GetCsv). It matches the format of the Unit.CsvLine method.
Variables ¶
var ( Angle = Quantity("angle") Turn = newUnit("turn", "tr", Angle) Radian = newUnit("radian", "rad", Angle, SI) MilliRadian = Milli(Radian) MicroRadian = Micro(Radian) // Degree (= decimal degree) is a unit of angle equal to 1/360 of a circle. Degree = newUnit("degree", "°", Angle) Gon = newUnit("gon", "gon", Angle, Symbols("grad")) DeciGon = Deci(Gon) CentiGon = Centi(Gon) MilliGon = Milli(Gon) MicroGon = Micro(Gon) NanoGon = Nano(Gon) PicoGon = Pico(Gon) FemtoGon = Femto(Gon) AttoGon = Atto(Gon) ZeptoGon = Zepto(Gon) YoctoGon = Yocto(Gon) DecaGon = Deca(Gon) HectoGon = Hecto(Gon) KiloGon = Kilo(Gon) MegaGon = Mega(Gon) GigaGon = Giga(Gon) TeraGon = Tera(Gon) PetaGon = Peta(Gon) )
var ( Area = Quantity("area") // metric SquareMilliMeter = newUnit("square millimeter", "mm²", Area, SI) SquareCentiMeter = newUnit("square centimeter", "cm²", Area, SI) SquareDeciMeter = newUnit("square decimeter", "dm²", Area, SI) SquareMeter = newUnit("square meter", "m²", Area, SI) SquareDecaMeter = newUnit("square decameter", "dam²", Area, SI) SquareHectoMeter = newUnit("square hectometer", "hm²", Area, SI) SquareKiloMeter = newUnit("square kilometer", "km²", Area, SI) // imperial SquareMile = newUnit("square mile", "mi²", Area, BI) Acre = newUnit("acre", "ac", Area, BI) SquareInch = newUnit("square inch", "in²", Area, BI) SquareFoot = newUnit("square foot", "ft²", Area, BI) SquareYard = newUnit("square yard", "yd²", Area, BI) )
var ( Bi = Quantity("bits") Data = Quantity("bytes") Byte = newUnit("byte", "B", Data) KiloByte = newUnit("kilobyte", "KB", Data) MegaByte = newUnit("megabyte", "MB", Data) GigaByte = newUnit("gigabyte", "GB", Data) TeraByte = newUnit("terabyte", "TB", Data) PetaByte = newUnit("petabyte", "PB", Data) ExaByte = newUnit("exabyte", "", Data) ZettaByte = newUnit("zettabyte", "", Data) YottaByte = newUnit("yottabyte", "", Data) Kibibyte = newUnit("kibibyte", "KiB", Data, IEC) Mebibyte = newUnit("mebibyte", "MiB", Data, IEC) Gibibyte = newUnit("gibibyte", "GiB", Data, IEC) Tebibyte = newUnit("tebibyte", "TiB", Data, IEC) Pebibyte = newUnit("pebibyte", "PiB", Data, IEC) Exbibyte = newUnit("exbibyte", "EiB", Data, IEC) Zebibyte = newUnit("zebibyte", "ZiB", Data, IEC) Yobibyte = newUnit("yobibyte", "YiB", Data, IEC) Bit = newUnit("bit", "b", Bi) KiloBit = Kilo(Bit) MegaBit = Mega(Bit) GigaBit = Giga(Bit) TeraBit = Tera(Bit) PetaBit = Peta(Bit) ExaBit = Exa(Bit) Nibble = newUnit("nibble", "", Data) )
var ( Density = Quantity("density") // metric GramPerCubicCentimeter = newUnit("gram per cubic centimeter", "g/cm³", Density, SI) KilogramPerCubicCentimeter = newUnit("kilogram per cubic centimeter", "kg/cm³", Density, SI) GramPerCubicMeter = newUnit("gram per cubic meter", "g/m³", Density, SI) KilogramPerCubicMeter = newUnit("kilogram per cubic meter", "kg/m³", Density, SI) GramPerMilliliter = newUnit("gram per milliliter", "g/mL", Density, SI) GramPerLiter = newUnit("gram per liter", "g/L", Density, SI) KilogramPerLiter = newUnit("kilogram per liter", "kg/L", Density, SI) // imperial OuncePerCubicInch = newUnit("ounce per cubic inch", "oz/in³", Density, BI) OuncePerCubicFoot = newUnit("ounce per cubic foot", "oz/ft³", Density, BI) OuncePerGallon = newUnit("ounce per gallon", "oz/gal", Density, BI) PoundPerCubicInch = newUnit("pound per cubic inch", "lb/in³", Density, BI) PoundPerCubicFoot = newUnit("pound per cubic foot", "lb/ft³", Density, BI) PoundPerGallon = newUnit("pound per gallon", "lb/gal", Density, BI) SlugPerCubicFoot = newUnit("slug per cubic foot", "slug/ft³", Density, BI) TonPerCubicYard = newUnit("ton per cubic yard", "l ton/yd³", Density, BI) )
var ( DimensionlessRatio = Quantity("dimensionless ratio") Fraction = newUnit("fraction", "", DimensionlessRatio, Plural(PluralNone)) Percent = newUnit("percent", "", DimensionlessRatio, Plural(PluralNone)) Permille = newUnit("permille", "", DimensionlessRatio, Plural(PluralNone)) PartsPerMillion = newUnit("partsPerMillion", "", DimensionlessRatio, Plural(PluralNone)) PartsPerBillion = newUnit("partsPerBillion", "", DimensionlessRatio, Plural(PluralNone)) PartsPerTrillion = newUnit("partsPerTrillion", "", DimensionlessRatio, Plural(PluralNone)) )
var ( ElectricCharge = Quantity("electric charge") // SI unit metric Coulomb = newUnit("coulomb", "C", ElectricCharge, SI) ExaCoulomb = Exa(Coulomb) PetaCoulomb = Peta(Coulomb) TeraCoulomb = Tera(Coulomb) GigaCoulomb = Giga(Coulomb) MegaCoulomb = Mega(Coulomb) KiloCoulomb = Kilo(Coulomb) HectoCoulomb = Hecto(Coulomb) DecaCoulomb = Deca(Coulomb) DeciCoulomb = Deci(Coulomb) CentiCoulomb = Centi(Coulomb) MilliCoulomb = Milli(Coulomb) MicroCoulomb = Micro(Coulomb) NanoCoulomb = Nano(Coulomb) PicoCoulomb = Pico(Coulomb) FemtoCoulomb = Femto(Coulomb) AttoCoulomb = Atto(Coulomb) AmpereHour = newUnit("ampere-hour", "A·h", ElectricCharge, SI, Symbols("A⋅h", "A*h", "A.h", "Ah", "AHr")) KiloAmpereHour = Kilo(AmpereHour) MilliAmpereHour = Milli(AmpereHour) AmpereMinute = newUnit( "ampere-minute", "A·min", ElectricCharge, SI, Symbols("A⋅min", "A*min", "A.min", "Amin"), ) KiloAmpereMinute = Kilo(AmpereMinute) MilliAmpereMinute = Milli(AmpereMinute) AmpereSecond = newUnit("ampere-second", "A·s", ElectricCharge, SI, Symbols("A⋅s", "A*s", "A.s", "As")) KiloAmpereSecond = Kilo(AmpereSecond) MilliAmpereSecond = Milli(AmpereSecond) )
var ( ElectricCurrent = Quantity("electric current") // metric Ampere = newUnit("ampere", "A", ElectricCurrent, SI) MilliAmpere = Milli(Ampere) MicroAmpere = Micro(Ampere) NanoAmpere = Nano(Ampere) PicoAmpere = Pico(Ampere) FemtoAmpere = Femto(Ampere) AttoAmpere = Atto(Ampere) ZeptoAmpere = Zepto(Ampere) YoctoAmpere = Yocto(Ampere) KiloAmpere = Kilo(Ampere) MegaAmpere = Mega(Ampere) GigaAmpere = Giga(Ampere) TeraAmpere = Tera(Ampere) PetaAmpere = Peta(Ampere) ExaAmpere = Exa(Ampere) ZettaAmpere = Zetta(Ampere) YottaAmpere = Yotta(Ampere) )
var ( ElectricalResistance = Quantity("electrical resistance") Ohm = newUnit("ohm", "Ω", ElectricalResistance, SI, Symbols("Ω")) DecaOhm = Deca(Ohm) HectoOhm = Hecto(Ohm) KiloOhm = Kilo(Ohm) MegaOhm = Mega(Ohm) GigaOhm = Giga(Ohm) TeraOhm = Tera(Ohm) PetaOhm = Peta(Ohm) ExaOhm = Exa(Ohm) ZettaOhm = Zetta(Ohm) YottaOhm = Yotta(Ohm) DeciOhm = Deci(Ohm) CentiOhm = Centi(Ohm) MilliOhm = Milli(Ohm) MicroOhm = Micro(Ohm) NanoOhm = Nano(Ohm) PicoOhm = Pico(Ohm) FemtoOhm = Femto(Ohm) AttoOhm = Atto(Ohm) ZeptoOhm = Zepto(Ohm) YoctoOhm = Yocto(Ohm) )
var ( Energy = Quantity("energy") // metric Joule = newUnit("joule", "J", Energy, SI) KiloJoule = Kilo(Joule) MegaJoule = Mega(Joule) GigaJoule = Giga(Joule) TeraJoule = Tera(Joule) PetaJoule = Peta(Joule) ExaJoule = Exa(Joule) ZettaJoule = Zetta(Joule) YottaJoule = Yotta(Joule) MilliJoule = Milli(Joule) MicroJoule = Micro(Joule) NanoJoule = Nano(Joule) PicoJoule = Pico(Joule) FemtoJoule = Femto(Joule) AttoJoule = Atto(Joule) WattHour = newUnit( "watt-hour", "Wh", Energy, SI, Aliases("volt ampere hour", "volt ampere reactive hour", "volt ampere hour (reactive)"), Symbols("VAh", "varh", "V⋅A⋅hr", "V.A.h", "V.A{reactive}.h", "V⋅A{reactive}⋅hr"), ) KiloWattHour = Kilo(WattHour) MegaWattHour = Mega(WattHour) GigaWattHour = Giga(WattHour) TeraWattHour = Tera(WattHour) PetaWattHour = Peta(WattHour) // other ElectronVolt = newUnit("electronvolt", "eV", Energy) KiloElectronVolt = Kilo(ElectronVolt) MegaElectronVolt = Mega(ElectronVolt) GigaElectronVolt = Giga(ElectronVolt) Calorie = newUnit("calorie", "cal", Energy) KiloCalorie = Kilo(Calorie) )
var ( Force = Quantity("force") Newton = newUnit("newton", "N", Force, SI) CentiNewton = Centi(Newton) DeciNewton = Deci(Newton) MilliNewton = Milli(Newton) MicroNewton = Micro(Newton) NanoNewton = Nano(Newton) PicoNewton = Pico(Newton) FemtoNewton = Femto(Newton) AttoNewton = Atto(Newton) ZeptoNewton = Zepto(Newton) YoctoNewton = Yocto(Newton) DecaNewton = Deca(Newton) HectoNewton = Hecto(Newton) KiloNewton = Kilo(Newton) MegaNewton = Mega(Newton) GigaNewton = Giga(Newton) TeraNewton = Tera(Newton) PetaNewton = Peta(Newton) ExaNewton = Exa(Newton) ZettaNewton = Zetta(Newton) YottaNewton = Yotta(Newton) PoundForce = newUnit("pound force", "lbf", Force, BI, Plural(PluralNone)) Dyne = newUnit("dyne", "dyn", Force, CGS) Poundal = newUnit("poundal", "pdl", Force, US) KilogramForce = newUnit("kilogram-force", "kgf", Force, MKpS) TonneForce = newUnit("tonne-force", "tf", Force, MKpS) )
var ( Frequency = Quantity("frequency") Hertz = newUnit("hertz", "Hz", Frequency, SI) DecaHertz = Deca(Hertz) HectoHertz = Hecto(Hertz) KiloHertz = Kilo(Hertz) MegaHertz = Mega(Hertz) GigaHertz = Giga(Hertz) TeraHertz = Tera(Hertz) PetaHertz = Peta(Hertz) ExaHertz = Exa(Hertz) ZettaHertz = Zetta(Hertz) YottaHertz = Yotta(Hertz) DeciHertz = Deci(Hertz) CentiHertz = Centi(Hertz) MilliHertz = Milli(Hertz) MicroHertz = Micro(Hertz) NanoHertz = Nano(Hertz) PicoHertz = Pico(Hertz) FemtoHertz = Femto(Hertz) AttoHertz = Atto(Hertz) ZeptoHertz = Zepto(Hertz) YoctoHertz = Yocto(Hertz) RadianPerSecond = newUnit("radian per second", "rad/s", Frequency, SI) RadianPerMinute = newUnit("radian per minute", "rad/min", Frequency, SI) RadianPerHour = newUnit("radian per hour", "rad/h", Frequency, SI) RadianPerDay = newUnit("radian per day", "rad/d", Frequency, SI) DegreePerSecond = newUnit("degree per second", "°/s", Frequency, BI) DegreePerMinute = newUnit("degree per minute", "°/min", Frequency, BI) DegreePerHour = newUnit("degree per hour", "°/h", Frequency, BI) DegreePerDay = newUnit("degree per day", "°/d", Frequency, BI) RevolutionPerSecond = newUnit("revolution per second", "rev/s", Frequency) RevolutionPerMinute = newUnit("revolution per minute", "rev/min", Frequency) RevolutionPerHour = newUnit("revolution per hour", "rev/h", Frequency) RevolutionPerDay = newUnit("revolution per day", "rev/d", Frequency) )
var ( Length = Quantity("length") // metric Meter = newUnit("meter", "m", Length, SI) ExaMeter = Exa(Meter) PetaMeter = Peta(Meter) TeraMeter = Tera(Meter) GigaMeter = Giga(Meter) MegaMeter = Mega(Meter) KiloMeter = Kilo(Meter) HectoMeter = Hecto(Meter) DecaMeter = Deca(Meter) DeciMeter = Deci(Meter) CentiMeter = Centi(Meter) MilliMeter = Milli(Meter) MicroMeter = Micro(Meter) NanoMeter = Nano(Meter) PicoMeter = Pico(Meter) FemtoMeter = Femto(Meter) AttoMeter = Atto(Meter) Angstrom = newUnit("angstrom", "Å", Length, BI) Inch = newUnit("inch", "in", Length, BI, Plural("inches")) Foot = newUnit("foot", "ft", Length, BI, Plural("feet")) Yard = newUnit("yard", "yd", Length, BI) Mile = newUnit("mile", "mi", Length, BI) League = newUnit("league", "lea", Length, BI) Furlong = newUnit("furlong", "fur", Length, BI) )
var ( Mass = Quantity("mass") // metric Gram = newUnit("gram", "g", Mass, SI) ExaGram = Exa(Gram) PetaGram = Peta(Gram) TeraGram = Tera(Gram) GigaGram = Giga(Gram) MegaGram = Mega(Gram) KiloGram = Kilo(Gram) HectoGram = Hecto(Gram) DecaGram = Deca(Gram) DeciGram = Deci(Gram) CentiGram = Centi(Gram) MilliGram = Milli(Gram) MicroGram = Micro(Gram) NanoGram = Nano(Gram) PicoGram = Pico(Gram) FemtoGram = Femto(Gram) AttoGram = Atto(Gram) // imperial Grain = newUnit("grain", "gr", Mass, BI) Drachm = newUnit("drachm", "dr", Mass, BI) Ounce = newUnit("ounce", "oz", Mass, BI) Pound = newUnit("pound", "lb", Mass, BI) Stone = newUnit("stone", "st", Mass, BI) Ton = newUnit("ton", "LT", Mass, BI) Slug = newUnit("slug", "", Mass, BI) )
var ( Power = Quantity("power") // metric Watt = newUnit("watt", "W", Power, SI) DeciWatt = Deci(Watt) CentiWatt = Centi(Watt) MilliWatt = Milli(Watt) MicroWatt = Micro(Watt) NanoWatt = Nano(Watt) PicoWatt = Pico(Watt) FemtoWatt = Femto(Watt) AttoWatt = Atto(Watt) ZeptoWatt = Zepto(Watt) YoctoWatt = Yocto(Watt) DecaWatt = Deca(Watt) HectoWatt = Hecto(Watt) KiloWatt = Kilo(Watt) MegaWatt = Mega(Watt) GigaWatt = Giga(Watt) TeraWatt = Tera(Watt) PetaWatt = Peta(Watt) ExaWatt = Exa(Watt) ZettaWatt = Zetta(Watt) YottaWatt = Yotta(Watt) VoltAmpere = newUnit("volt-ampere", "V⋅A", Power, SI) KiloVoltAmpere = Kilo(VoltAmpere) MegaVoltAmpere = Mega(VoltAmpere) VoltAmpereReactive = newUnit("volt-ampere reactive", "var", Power, SI) KiloVoltAmpereReactive = Kilo(VoltAmpereReactive) MegaVoltAmpereReactive = Mega(VoltAmpereReactive) )
var ( Pressure = Quantity("pressure") // SI unit metric Pascal = newUnit("pascal", "Pa", Pressure, SI) ExaPascal = Exa(Pascal) PetaPascal = Peta(Pascal) TeraPascal = Tera(Pascal) GigaPascal = Giga(Pascal) MegaPascal = Mega(Pascal) KiloPascal = Kilo(Pascal) HectoPascal = Hecto(Pascal) DecaPascal = Deca(Pascal) DeciPascal = Deci(Pascal) CentiPascal = Centi(Pascal) MilliPascal = Milli(Pascal) MicroPascal = Micro(Pascal) NanoPascal = Nano(Pascal) PicoPascal = Pico(Pascal) FemtoPascal = Femto(Pascal) AttoPascal = Atto(Pascal) // Other At = newUnit("technical atmosphere", "at", Pressure, BI) Atm = newUnit("standard atmosphere", "atm", Pressure, BI) Bar = newUnit("bar", "bar", Pressure, BI) CentiBar = Centi(Bar, BI) MilliBar = Milli(Bar, BI) MicroBar = Micro(Bar, BI) Barye = newUnit("barye", "Ba", Pressure, BI) InH2O = newUnit( "inch of Water Column", "inH2O", Pressure, BI, Plural("inches of Water Column"), ) InHg = newUnit("inch of Mercury", "inHg", Pressure, BI, Plural("inches of Mercury")) MH2O = newUnit( "meter of Water Column", "mmH2O", Pressure, BI, Plural("meters of Water Column"), ) MilliMH2O = Milli(MH2O, BI, Plural("millimeters of Water Column")) CentiMH2O = Centi(MH2O, BI, Plural("centimeters of Water Column")) MHg = newUnit("meter of Mercury", "mmHg", Pressure, BI, Plural("meters of Mercury")) MilliMHg = Milli(MHg, BI, Plural("millimeters of Mercury")) CentiMHg = Centi(MHg, BI, Plural("centimeters of Mercury")) NewtonSqm = newUnit("newton per square meter", "N/m²", Pressure, BI) KiloNewtonSqm = Kilo(NewtonSqm) Psi = newUnit("pound-force per square inch", "psi", Pressure, BI) Torr = newUnit("torr", "Torr", Pressure, BI) )
var ( // Slope is a unit option for slope units, also known as gradient. Slope = Quantity("slope") // SlopeValue m = rise (delta h) / run (distance) = y/x = tan(alpha) // In the case of a vertical line, the slope is infinite. // In the case of a horizontal line, the slope is zero. SlopeValue = newUnit("slope value", "", Slope, Plural(PluralNone)) // SlopeRatio is a ratio of one part rise to so many parts run (e.g. 1:10). == SlopeInverseValue SlopeRatio = newUnit("slope ratio", "", Slope, Plural(PluralNone)) // SlopeInverseRatio is a ratio of many parts run to one part rise (e.g. 10:1). SlopeInverseRatio = newUnit("inverse slope ratio", "", Slope, Plural(PluralNone)) // SlopeDegree is the angle of inclination in degrees (e.g. 45°). SlopeDegree = newUnit("slope degree", "", Slope, Plural(PluralNone)) // SlopePercent 100 * m = 100 * (rise/run) = 100 * tan(α) SlopePercent = newUnit("slope percent", "", Slope, Plural(PluralNone)) // SlopePermille 1000 * m = 1000 * (rise/run) = 1000 * tan(α) SlopePermille = newUnit("slope permille", "", Slope, Plural(PluralNone)) )
var ( Temperature = Quantity("temperature") Celsius = newUnit("celsius", "°C", Temperature, Plural(PluralNone), SI) Fahrenheit = newUnit("fahrenheit", "°F", Temperature, Plural(PluralNone), US) Kelvin = newUnit("kelvin", "°K", Temperature, Plural(PluralNone), SI) Rankine = newUnit("rankine", "°R", Temperature, Plural(PluralNone), US) )
var ( ThermalInsulance = Quantity("thermal insulance") KelvinSquareMeterPerWatt = newUnit( "kelvin square-metre per watt", "K·m²/W", ThermalInsulance, SI, Aliases("R-value"), Symbols("K*m2/W", "°C⋅m²/W", "°C*m2/W", "m2.K.W-1", "m²·K/W", "m2*K/W"), ) DegreeFahrenheitHourSquareFootPerBtu = newUnit( "degree Fahrenheit hour square foot per British thermal unitIT", "°F⋅hr⋅ft²/Btu", ThermalInsulance, BI, Aliases( "degree Fahrenheit hour square foot per British thermal unit", "°F · h · ft2/BtuIT", "°F*hr*ft2/Btu", "°F⋅ft²⋅h/BTU", "°F⋅ft2⋅h/BTU", "°F*ft2*h/BTU", ), ) )
var ( Time = Quantity("time") Second = newUnit("second", "s", Time, SI) ExaSecond = Exa(Second) PetaSecond = Peta(Second) TeraSecond = Tera(Second) GigaSecond = Giga(Second) MegaSecond = Mega(Second) KiloSecond = Kilo(Second) HectoSecond = Hecto(Second) DecaSecond = Deca(Second) DeciSecond = Deci(Second) CentiSecond = Centi(Second) MilliSecond = Milli(Second) MicroSecond = Micro(Second) NanoSecond = Nano(Second) PicoSecond = Pico(Second) FemtoSecond = Femto(Second) AttoSecond = Atto(Second) Minute = newUnit("minute", "min", Time) Hour = newUnit("hour", "hr", Time) Day = newUnit("day", "d", Time) Month = newUnit("month", "", Time) Year = newUnit("year", "yr", Time) Decade = newUnit("decade", "", Time) Century = newUnit("century", "", Time) Millennium = newUnit("millennium", "", Time) // more esoteric time units PlanckTime = newUnit("planck time", "𝑡ₚ", Time) Fortnight = newUnit("fortnight", "", Time) Score = newUnit("score", "", Time) )
var ( // SI is the International System of Units SI = System(SiSystem) // BI is the British Imperial system of units BI = System(BiSystem) // US is the United States customary system of units US = System(UsSystem) // IEC is the International Electrotechnical Commission system of units IEC = System(IecSystem) // CGS is the centimeter-gram-second system of units CGS = System(CgsSystem) // MKpS is the MKpS system of units (from French mètre–kilogramme-poids–seconde) MKpS = System(MKpSSystem) )
var ( Voltage = Quantity("voltage") // metric Volt = newUnit("volt", "V", Voltage, SI) YottaVolt = Yotta(Volt) ZettaVolt = Zetta(Volt) ExaVolt = Exa(Volt) PetaVolt = Peta(Volt) TeraVolt = Tera(Volt) GigaVolt = Giga(Volt) MegaVolt = Mega(Volt) KiloVolt = Kilo(Volt) HectoVolt = Hecto(Volt) DecaVolt = Deca(Volt) DeciVolt = Deci(Volt) CentiVolt = Centi(Volt) MilliVolt = Milli(Volt) MicroVolt = Micro(Volt) NanoVolt = Nano(Volt) PicoVolt = Pico(Volt) )
var ( VolumeFlowRate = Quantity("volume flow rate") CubicMeterPerSecond = newUnit( "cubic meter per second", "m³/s", VolumeFlowRate, SI, Aliases("cubic metre per second"), Symbols("m3/s", "m3s-1"), ) CubicMeterPerMinute = newUnit( "cubic meter per minute", "m³/min", VolumeFlowRate, SI, Aliases("cubic metre per minute"), Symbols("m3/min", "m3m-1"), ) CubicMeterPerHour = newUnit( "cubic meter per hour", "m³/h", VolumeFlowRate, SI, Aliases("cubic metre per hour"), Symbols("m3/h", "m3h-1"), ) CubicMeterPerDay = newUnit( "cubic meter per day", "m³/d", VolumeFlowRate, SI, Aliases("cubic metre per day"), Symbols("m3/d", "m3d-1"), ) CubicDecimeterPerSecond = newUnit( "cubic decimeter per second", "dm³/s", VolumeFlowRate, SI, Aliases("cubic decimetre per second"), Symbols("dm3/s", "dm3s-1"), ) CubicDecimeterPerMinute = newUnit( "cubic decimeter per minute", "dm³/min", VolumeFlowRate, SI, Aliases("cubic decimetre per minute"), Symbols("dm3/min", "dm3m-1"), ) CubicDecimeterPerHour = newUnit( "cubic decimeter per hour", "dm³/h", VolumeFlowRate, SI, Aliases("cubic decimetre per hour"), Symbols("dm3/h", "dm3h-1"), ) CubicDecimeterPerDay = newUnit( "cubic decimeter per day", "dm³/d", VolumeFlowRate, SI, Aliases("cubic decimetre per day"), Symbols("dm3/d", "dm3d-1"), ) CubicCentimeterPerSecond = newUnit( "cubic centimeter per second", "cm³/s", VolumeFlowRate, SI, Aliases("cubic centimetre per second"), Symbols("cm3/s", "cm3s-1"), ) CubicCentimeterPerMinute = newUnit( "cubic centimeter per minute", "cm³/min", VolumeFlowRate, SI, Aliases("cubic centimetre per minute"), Symbols("cm3/min", "cm3m-1"), ) CubicCentimeterPerHour = newUnit( "cubic centimeter per hour", "cm³/h", VolumeFlowRate, SI, Aliases("cubic centimetre per hour"), Symbols("cm3/h", "cm3h-1"), ) CubicCentimeterPerDay = newUnit( "cubic centimeter per day", "cm³/d", VolumeFlowRate, SI, Aliases("cubic centimetre per day"), Symbols("cm3/d", "cm3d-1"), ) CubicInchPerSecond = newUnit("cubic inch per second", "in³/s", VolumeFlowRate) CubicInchPerMinute = newUnit("cubic inch per minute", "in³/min", VolumeFlowRate) CubicInchPerHour = newUnit("cubic inch per hour", "in³/h", VolumeFlowRate) CubicInchPerDay = newUnit("cubic inch per day", "in³/d", VolumeFlowRate) CubicFootPerSecond = newUnit("cubic foot per second", "ft³/s", VolumeFlowRate) CubicFootPerMinute = newUnit("cubic foot per minute", "ft³/min", VolumeFlowRate) CubicFootPerHour = newUnit("cubic foot per hour", "ft³/h", VolumeFlowRate) CubicFootPerDay = newUnit("cubic foot per day", "ft³/d", VolumeFlowRate) CubicYardPerSecond = newUnit("cubic yard per second", "yd³/s", VolumeFlowRate) CubicYardPerMinute = newUnit("cubic yard per minute", "yd³/min", VolumeFlowRate) CubicYardPerHour = newUnit("cubic yard per hour", "yd³/h", VolumeFlowRate) CubicYardPerDay = newUnit("cubic yard per day", "yd³/d", VolumeFlowRate) )
var ( Volume = Quantity("volume") Liter = newUnit("liter", "l", Volume, SI, Aliases("litre")) ExaLiter = Exa(Liter) PetaLiter = Peta(Liter) TeraLiter = Tera(Liter) GigaLiter = Giga(Liter) MegaLiter = Mega(Liter) KiloLiter = Kilo(Liter) HectoLiter = Hecto(Liter) DecaLiter = Deca(Liter) DeciLiter = Deci(Liter) CentiLiter = Centi(Liter) MilliLiter = Milli(Liter) MicroLiter = Micro(Liter) NanoLiter = Nano(Liter) PicoLiter = Pico(Liter) FemtoLiter = Femto(Liter) AttoLiter = Atto(Liter) CubicMeter = newUnit("cubic meter", "m³", Volume, SI) CubicKiloMeter = newUnit("cubic kilometer", "km³", Volume, SI) CubicHectoMeter = newUnit("cubic hectometer", "hm³", Volume, SI) CubicDecaMeter = newUnit("cubic decameter", "dam³", Volume, SI) CubicDeciMeter = newUnit("cubic decimeter", "dm³", Volume, SI) CubicCentiMeter = newUnit("cubic centimeter", "cm³", Volume, SI) CubicMilliMeter = newUnit("cubic millimeter", "mm³", Volume, SI) // imperial Quart = newUnit("quart", "qt", Volume, BI) Pint = newUnit("pint", "pt", Volume, BI) Gallon = newUnit("gallon", "gal", Volume, BI) FluidOunce = newUnit("fluid ounce", "fl oz", Volume, BI) CubicFoot = newUnit("cubic foot", "ft³", Volume, BI) CubicYard = newUnit("cubic yard", "yd³", Volume, BI) CubicInch = newUnit("cubic inch", "in³", Volume, BI) CubicMile = newUnit("cubic mile", "mi³", Volume, BI) AcreFoot = newUnit("acre foot", "ac ft", Volume, BI) // US FluidQuart = newUnit("fluid quart", "fl qt", Volume, US) FluidPint = newUnit("fluid pint", "fl pt", Volume, US) FluidGallon = newUnit("fluid gallon", "", Volume, US) CustomaryFluidOunce = newUnit("customary fluid ounce", "", Volume, US) )
var DefaultFmtOptions = FmtOptions{true, false, 6}
Functions ¶
func NewConversion ¶
NewConversion registers a new conversion formula from one Unit to another
func NewConversionFromFn ¶
func NewConversionFromFn(from, to *Unit, f ConversionFn, formula string)
NewConversionFromFn registers a new conversion formula from one Unit to another.
NOTE:
- When using `NewConversionFromFn` directly, you must define conversions in both directions!
Example:
NewConversionFromFn(SlopeValue, SlopeDegree, slopeValueToDegree, "math.Atan(x) * 180 / math.Pi") NewConversionFromFn(SlopeDegree, SlopeValue, slopeDegreeToValue, "math.Tan(x * math.Pi / 180)")
func NewRatioConversion ¶
NewRatioConversion registers a conversion formula and the _inverse_, given a ratio of from Unit in to Unit
Types ¶
type AddResult ¶
type AddResult struct { What string // "Aliases" or "Symbols", depending on what was added Unit *Unit // the unit to which the aliases or symbols were added Added []string // the aliases or symbols that were added Failures map[string]error // the aliases or symbols that failed to be added, and the reason why Err error // the overall error that occurred, if any Summary string // a summary of the result }
AddResult is the result of adding aliases or symbols to a unit
type Conversion ¶
type Conversion struct { Fn ConversionFn Formula string // contains filtered or unexported fields }
func ResolveConversion ¶
func ResolveConversion(from, to *Unit) (cpath []Conversion, err error)
ResolveConversion resolves a path of one or more Conversions between two units
func (Conversion) From ¶
func (c Conversion) From() string
From returns the name of the unit to convert from
func (Conversion) String ¶
func (c Conversion) String() string
String representation of conversion formula
func (Conversion) To ¶
func (c Conversion) To() string
To returns the name of the unit to convert to
type ConversionFn ¶
type FmtOptions ¶
type Unit ¶
type Unit struct { // Name is the (english) name of this unit. The name is mandatory and case-insensitive. Name string // Symbol is the (main) symbol for this unit, e.g. "m" for meters. The symbol is mandatory and case-sensitive. Symbol string // Quantity is the quantity label for which this unit belongs, e.g. "length" or "area" Quantity UnitQuantity // contains filtered or unexported fields }
Unit represents a unit of measurement
func Atto ¶
func Atto(b *Unit, o ...UnitOption) *Unit
func Centi ¶
func Centi(b *Unit, o ...UnitOption) *Unit
func Deca ¶
func Deca(b *Unit, o ...UnitOption) *Unit
func Deci ¶
func Deci(b *Unit, o ...UnitOption) *Unit
func Exa ¶
func Exa(b *Unit, o ...UnitOption) *Unit
func Femto ¶
func Femto(b *Unit, o ...UnitOption) *Unit
func Giga ¶
func Giga(b *Unit, o ...UnitOption) *Unit
func Hecto ¶
func Hecto(b *Unit, o ...UnitOption) *Unit
func Kilo ¶
func Kilo(b *Unit, o ...UnitOption) *Unit
func Mega ¶
func Mega(b *Unit, o ...UnitOption) *Unit
func Micro ¶
func Micro(b *Unit, o ...UnitOption) *Unit
func Milli ¶
func Milli(b *Unit, o ...UnitOption) *Unit
func Nano ¶
func Nano(b *Unit, o ...UnitOption) *Unit
func NewUnit ¶
func NewUnit(name, symbol string, opts ...UnitOption) (*Unit, error)
NewUnit registers a new Unit within the package, returning the newly created Unit. Returns an error if the unit already exists. The name is mandatory and must be unique. The symbol is optional, but if provided, must be unique.
func Peta ¶
func Peta(b *Unit, o ...UnitOption) *Unit
func Pico ¶
func Pico(b *Unit, o ...UnitOption) *Unit
func Quecto ¶
func Quecto(b *Unit, o ...UnitOption) *Unit
func Quetta ¶
func Quetta(b *Unit, o ...UnitOption) *Unit
Magnitude prefix methods create and return a new Unit, while automatically registering conversions to and from the provided base Unit
func Ronna ¶
func Ronna(b *Unit, o ...UnitOption) *Unit
func Ronto ¶
func Ronto(b *Unit, o ...UnitOption) *Unit
func Tera ¶
func Tera(b *Unit, o ...UnitOption) *Unit
func Yocto ¶
func Yocto(b *Unit, o ...UnitOption) *Unit
func Yotta ¶
func Yotta(b *Unit, o ...UnitOption) *Unit
func Zepto ¶
func Zepto(b *Unit, o ...UnitOption) *Unit
func Zetta ¶
func Zetta(b *Unit, o ...UnitOption) *Unit
func (*Unit) AddAliases ¶
AddAliases adds aliases that this unit may be referred to
func (*Unit) AddSymbols ¶
AddSymbols adds symbols that this unit may be referred to
func (*Unit) CsvLine ¶
CsvLine returns a CSV line for this unit The line contains the following fields: Name, Symbol, PluralName, Quantity, System, Aliases, Symbols
func (*Unit) HasName ¶
HasName returns true if the provided string matches the provided Unit's Name or Aliases
func (*Unit) HasSymbol ¶
HasSymbol returns true if the provided string matches the provided Unit's Symbol or Symbols
func (*Unit) Names ¶
Names returns all names and aliases this unit may be referred to. The main name is always the first in the list. Names and aliases are NOT case-sensitive!
func (*Unit) PluralName ¶
PluralName returns the plural name for this unit
func (*Unit) Symbols ¶
Symbols returns all symbols this unit may be referred to. The main symbol is always the first in the list. Symbols are case-sensitive!
func (*Unit) System ¶
func (u *Unit) System() UnitSystem
System returns the system of units this Unit belongs to, if any
type UnitList ¶
type UnitList []*Unit
UnitList is a slice of Units. UnitList implements sort.Interface
type UnitOption ¶
UnitOption defines an option that may be passed to newUnit
func Plural ¶
func Plural(s string) UnitOption
Plural sets the plural name for this unit, either PluralNone, PluralAuto, or a custom plural unit name
- PluralNone - labels will use the unmodified unit name in a plural context
- PluralAuto - labels for this unit will be created with a plural suffix when appropriate (default)
func Quantity ¶
func Quantity(s UnitQuantity) UnitOption
Quantity sets a quantity label for which this Unit belongs
func System ¶
func System(s UnitSystem) UnitOption
System sets the system of units for which this Unit belongs
type UnitQuantity ¶
type UnitQuantity string
UnitQuantity is a quantity label for which a unit belongs
func (UnitQuantity) String ¶
func (q UnitQuantity) String() string
Quantity labels for which units may belong
type UnitSystem ¶
type UnitSystem string
UnitSystem is a system of units
const ( // SiSystem provides the internal name for International System of Units SiSystem UnitSystem = "metric" // BiSystem provides the internal name the British Imperial system of units BiSystem UnitSystem = "imperial" // UsSystem provides the internal name the United States customary system of units UsSystem UnitSystem = "us" // IecSystem provides the internal name the International Electrotechnical Commission system of units IecSystem UnitSystem = "iec" // CgsSystem provides the internal name the centimeter-gram-second system of units CgsSystem UnitSystem = "cgs" // MKpSSystem provides the internal name the MKpS system of units (from French mètre–kilogramme-poids–seconde) MKpSSystem UnitSystem = "MKpS" )
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
func ConvertFloat ¶
ConvertFloat converts a provided float from one Unit to another
func MustConvertFloat ¶
MustConvertFloat converts a provided float from one Unit to another, PANICKING on error
func (Value) Fmt ¶
func (v Value) Fmt(opts FmtOptions) string
Fmt returns a string representation of this Value, using the provided FmtOptions
func (Value) MustConvert ¶
MustConvert converts this Value to another Unit, PANICKING on error
Source Files
¶
- angle_units.go
- area_units.go
- conversion.go
- conversion_valuate.go
- data_units.go
- density_units.go
- dimensionlessRatio_units.go
- electric_charge_units.go
- electric_current_units.go
- electrical_resistance_units.go
- energy_units.go
- force_units.go
- frequency_units.go
- length_units.go
- lookup_test_helpers.go
- mass_units.go
- metric.go
- power_units.go
- pressure_units.go
- slope_units.go
- temperature_units.go
- thermal_insulance_units.go
- time_units.go
- unit.go
- units.go
- value.go
- voltage_units.go
- volume_flow_rate_units.go
- volume_units.go
Directories
¶
Path | Synopsis |
---|---|
Package numericstring provides constants with numeric strings for conversion tests
|
Package numericstring provides constants with numeric strings for conversion tests |