units

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2021 License: MIT Imports: 4 Imported by: 3

Documentation

Overview

Package units represents valid units of measure (the Unit type) and families of related units (the Family type).

The Unit type can be used to convert between a value expressed in the base unit and some other chosen unit. The Unit values show how many of the base unit are in the alternative unit. To convert a value held in the base units into a value expressed in the alternative units you should call the ConvertFromBaseUnits func.

Index

Examples

Constants

View Source
const (
	Dimensionless = "dimensionless"
	Time          = "time"
	Data          = "data"
	Distance      = "distance"
	Length        = "distance" // synonym
	Area          = "area"
	Volume        = "volume"
	Velocity      = "velocity"
	Speed         = "velocity" // synonym
	Mass          = "mass"
	Temperature   = "temperature"
	Angle         = "angle"
	Energy        = "energy"
)

These constants should be used when retrieving unit details

View Source
const (

	// Note that there are many different variants of the British thermal
	// unit with conversion ratios to Joules varying between 1054.3503 (for
	// the Thermochemical variant) and 1059.67 (using the calorie value of
	// water at its maximum density, when it is at 3.9 ℃)
	BtuToJoule = 1055.06 // International Standard ISO 31-4
)

Variables

View Source
var AngleNames = map[string]Unit{

	"radian": AngularUnitRadian,
	"milliradian": {
		0, 0, m,
		UnitOfAngle,
		"mrad", "milliradian", "milliradians",
		"a unit in which angles are measured.",
		"",
	},

	"degree": {
		0, 0, degreePerRadian,
		UnitOfAngle,
		"°", "degree", "degrees",
		"a unit in which angles are measured.",
		"",
	},
	"minute": {
		0, 0, degreePerRadian / 60,
		UnitOfAngle,
		"′", "arc minute", "arc minutes",
		"a unit in which angles are measured.",
		"",
	},
	"second": {
		0, 0, degreePerRadian / 3600,
		UnitOfAngle,
		"″", "arc second", "arc seconds",
		"a unit in which angles are measured.",
		"",
	},
}

AngleNames maps names to units of anglular measure

View Source
var AngularUnitRadian = Unit{
	0, 0, 1,
	UnitOfAngle,
	"rad", UnitOfAngle.BaseUnitName, "radians",
	"a unit in which angles are measured.",
	"",
}

AngularUnitRadian is a suitable default value for a UnitOfAngle

View Source
var AreaNames = map[string]Unit{

	"square metre": SquareMetreUnit,
	"are": {
		0, 0, 1e2,
		UnitOfArea,
		"are", "are", "ares",
		"a non-SI metric measure of area.",
		"",
	},
	"decare": {
		0, 0, 1e3,
		UnitOfArea,
		"decare", "decare", "decares",
		"a non-SI metric measure of area.",
		"",
	},
	"hectare": {
		0, 0, 1e4,
		UnitOfArea,
		"ha", "hectare", "hectares",
		"a non-SI metric measure of area.",
		"",
	},
	"square kilometre": {
		0, 0, 1e6,
		UnitOfArea,
		"km\u00B2", "square kilometre", "square kilometres",
		"a metric measure of area.",
		"",
	},

	"square yard": {
		0, 0, yard2ToMetre2,
		UnitOfArea,
		"yd\u00B2", "square yard", "square yards",
		"an imperial measure of area.",
		"",
	},
	"square mile": {
		0, 0, yard2ToMetre2 * 1760 * 1760,
		UnitOfArea,
		"mi\u00B2", "square mile", "square miles",
		"an imperial measure of area.",
		"",
	},
	"perch": {
		0, 0, yard2ToMetre2 * 30.25,
		UnitOfArea,
		"square perch", "square perch", "square perches",
		"an imperial measure of area. It is equal to one square rod." +
			" Note that a perch can also be a" +
			" measure of length or volume.",
		"",
	},
	"rood": {
		0, 0, acreToMetre2 * 0.25,
		UnitOfArea,
		"ro", "rood", "roods",
		"an imperial measure of area. It may also be called a rod" +
			" though a rod is typically a measure of length. Note" +
			" however that a rood is not a square rod but is 40" +
			" square rods (one furlong by one rod).",
		"",
	},
	"acre": {
		0, 0, acreToMetre2,
		UnitOfArea,
		"acre", "acre", "acres",
		"an imperial measure of area.",
		"",
	},

	"oxgang": {
		0, 0, acreToMetre2 * 15,
		UnitOfArea,
		"oxgang", "oxgang", "oxgangs",
		"an obsolete imperial measure of area. Derived from the" +
			" area of land that could be ploughed by a single ox" +
			" in one season." +
			" Sometimes known as 'bovate' or, in Scotland, 'damh-imir'." +
			" Sometimes given as 20 acres." +
			" See also 'virgate' and 'carucate'.",
		"",
	},
	"virgate": {
		0, 0, acreToMetre2 * 30,
		UnitOfArea,
		"virgate", "virgate", "virgates",
		"an obsolete imperial measure of area. Derived from the" +
			" area of land that could be ploughed by a team of" +
			" 2 oxen in one season." +
			" See also 'oxgang' and 'carucate'.",
		"",
	},
	"carucate": {
		0, 0, acreToMetre2 * 120,
		UnitOfArea,
		"carucate", "carucate", "carucates",
		"an obsolete imperial measure of area. Derived from the" +
			" area of land that could be ploughed by a team of" +
			" 8 oxen in one season." +
			" See also 'oxgang' and 'virgate'.",
		"",
	},

	"Wales": {
		0, 0, 20779 * 1e6,
		UnitOfArea,
		"times the size of Wales",
		"times the size of Wales", "times the size of Wales",
		"a colloquial measure of area, used primarily to" +
			" give an impression of size.",
		"",
	},
}

AreaNames maps names to units of area

View Source
var ByteUnit = Unit{
	0, 0, 1,
	UnitOfData,
	"B", UnitOfData.BaseUnitName, "bytes",
	"eight bits",
	"",
}

ByteUnit is a suitable default value for a UnitOfData

View Source
var CubicMetreUnit = Unit{
	0, 0, 1,
	UnitOfVolume,
	"m\u00B3", UnitOfVolume.BaseUnitName, "cubic metres",
	"a metric measure of volume.",
	"",
}

CubicMetreUnit is a suitable default value for a UnitOfVolume

View Source
var DataNames = map[string]Unit{
	"bit": {
		0, 0, 0.125,
		UnitOfData,
		"bit", "bit", "bits",
		"a bit is a single binary digit taking a value of either 0 or 1." +
			" It is one eighth of a byte and is indivisible.",
		"",
	},
	"nibble": {
		0, 0, 0.5,
		UnitOfData,
		"nibble", "nibble", "nibbles",
		"a nibble is half a byte (four bits).",
		"",
	},
	"byte": ByteUnit,

	"KB": {
		0, 0, k,
		UnitOfData,
		"KB", "kilobyte", "kilobytes",
		"a metric value (in powers of 10^3).",
		"",
	},
	"MB": {
		0, 0, _M,
		UnitOfData,
		"MB", "megabyte", "megabytes",
		"a metric value (in powers of 10^3).",
		"",
	},
	"GB": {
		0, 0, _G,
		UnitOfData,
		"GB", "gigabyte", "gigabytes",
		"a metric value (in powers of 10^3).",
		"",
	},
	"TB": {
		0, 0, _T,
		UnitOfData,
		"TB", "terabyte", "terabytes",
		"a metric value (in powers of 10^3).",
		"",
	},
	"PB": {
		0, 0, _P,
		UnitOfData,
		"PB", "petabyte", "petabytes",
		"a metric value (in powers of 10^3).",
		"",
	},
	"EB": {
		0, 0, _E,
		UnitOfData,
		"EB", "exabyte", "exabytes",
		"a metric value (in powers of 10^3).",
		"",
	},
	"ZB": {
		0, 0, _Z,
		UnitOfData,
		"ZB", "zettabyte", "zettabytes",
		"a metric value (in powers of 10^3).",
		"",
	},
	"YB": {
		0, 0, _Y,
		UnitOfData,
		"YB", "yottabyte", "yottabytes",
		"a metric value (in powers of 10^3).",
		"",
	},

	"KiB": {
		0, 0, ki,
		UnitOfData,
		"KiB", "kibibyte", "kibibytes",
		"a traditional computing measure (in powers of 2^10).",
		"",
	},
	"MiB": {
		0, 0, mi,
		UnitOfData,
		"MiB", "mebibyte", "mebibytes",
		"a traditional computing measure (in powers of 2^10).",
		"",
	},
	"GiB": {
		0, 0, gi,
		UnitOfData,
		"GiB", "gibibyte", "gibibytes",
		"a traditional computing measure (in powers of 2^10).",
		"",
	},
	"TiB": {
		0, 0, ti,
		UnitOfData,
		"TiB", "tebibyte", "tebibytes",
		"a traditional computing measure (in powers of 2^10).",
		"",
	},
	"PiB": {
		0, 0, pi,
		UnitOfData,
		"PiB", "pebibyte", "pebibytes",
		"a traditional computing measure (in powers of 2^10).",
		"",
	},
	"EiB": {
		0, 0, ei,
		UnitOfData,
		"EiB", "exbibyte", "exbibytes",
		"a traditional computing measure (in powers of 2^10).",
		"",
	},
	"ZiB": {
		0, 0, zi,
		UnitOfData,
		"ZiB", "zebibyte", "zebibytes",
		"a traditional computing measure (in powers of 2^10).",
		"",
	},
	"YiB": {
		0, 0, yi,
		UnitOfData,
		"YiB", "yobibyte", "yobibytes",
		"a traditional computing measure (in powers of 2^10).",
		"",
	},
}

DataNames maps names to units of data

View Source
var DegCUnit = Unit{
	0, 0, 1,
	UnitOfTemperature,
	"℃", UnitOfTemperature.BaseUnitName, "degrees Celsius",
	"a measure of temperature." +
		" It is named to honour the Swedish astronomer Anders Celsius." +
		" It was formerly known as the Centigrade scale" +
		" with units of 'centigrade'.",
	"",
}

DegCUnit is a suitable default value for a UnitOfTemperature

View Source
var DegDUnit = Unit{
	-100, 0, -2.0 / 3.0,
	UnitOfTemperature,
	"°D", "degree Delisle", "degrees Delisle",
	"a measure of temperature invented by Joseph-Nicolas Delisle." +
		"\n\n" +
		"No longer used." +
		"\n\n" +
		"It has the unusual property of hotter temperatures" +
		" having a lower value than colder ones. It runs from 0" +
		" at the boiling point of water to 150 at the freezing" +
		" point.",
	"",
}

DegDUnit grows in the opposite direction to all the other units so that the larger the value, the colder it is

View Source
var DegFUnit = Unit{
	0, 32, 5.0 / 9.0,
	UnitOfTemperature,
	"℉", "degree Fahrenheit", "degrees Fahrenheit",
	"a measure of temperature. It is named after the physicist" +
		" Daniel Gabriel Fahrenheit." +
		" It has the freezing point of water at 32 degrees" +
		" and the boiling point of water at 212 degrees." +
		" Both using pure water at sea level.",
	"",
}
View Source
var DegKUnit = Unit{
	0, absZero, 1,
	UnitOfTemperature,
	"K", "kelvin", "kelvin",
	"a measure of temperature based on the Celsius scale but" +
		" having zero at absolute zero (-273.15 on the Celsius" +
		" scale)." +
		" It is named to honour" +
		" the Glasgow university engineer and physicist" +
		" William Thomson, 1st Baron Kelvin.",
	"",
}
View Source
var DegNUnit = Unit{
	0, 0, 100.0 / 33.0,
	UnitOfTemperature,
	"°N", "degree Newton", "degrees Newton",
	"a measure of temperature devised by Isaac Newton." +
		"\n\n" +
		"No longer used." +
		"\n\n" +
		"It has the freezing point of water at 0 degrees" +
		" and the boiling point of water at 33 degrees." +
		" It is poorly defined and no unambiguous" +
		" conversion to other scales is possible but the" +
		" figures used refer to points given by Newton.",
	"",
}
View Source
var DegRaUnit = Unit{
	absZero, 0, 5.0 / 9.0,
	UnitOfTemperature,
	"°R", "degree Rankine", "degrees Rankine",
	"a measure of temperature using degrees Fahrenheit but" +
		" having zero at absolute zero." +
		" It is named to honour" +
		" the Glasgow university engineer and physicist" +
		" William John Macquorn Rankine.",
	"",
}

DegRaUnit (Rankine) is the Fahrenheit equivalent of Kelvin

View Source
var DegReUnit = Unit{
	0, 0, 4.0 / 5.0,
	UnitOfTemperature,
	"°Ré", "degree Réaumur", "degrees Réaumur",
	"a measure of temperature It is named after" +
		" René Antoine Ferchault de Réaumur." +
		"\n\n" +
		"No longer used." +
		"\n\n" +
		"It has the freezing point of water at 0 degrees" +
		" and the boiling point of water at 80 degrees.",
	"",
}
View Source
var DegRoUnit = Unit{
	0, 7.5, 40.0 / 21.0,
	UnitOfTemperature,
	"°Rø", "degree Rømer", "degrees Rømer",
	"a measure of temperature. It is named after the Danish astronomer" +
		"  Ole Christensen Rømer." +
		"\n\n" +
		"No longer used." +
		"\n\n" +
		"It has the freezing point of water at 7.5 degrees" +
		" and the boiling point of water at 60 degrees." +
		" Both using pure water at sea level.",
	"",
}
View Source
var DimensionlessNames = map[string]Unit{
	"y":     {0, 0, y, Numeric, "y", "yocto", "yocto", "", ""},
	"z":     {0, 0, z, Numeric, "z", "zepto", "zepto", "", ""},
	"a":     {0, 0, a, Numeric, "a", "atto", "atto", "", ""},
	"f":     {0, 0, f, Numeric, "f", "femto", "femto", "", ""},
	"p":     {0, 0, p, Numeric, "p", "pico", "pico", "", ""},
	"n":     {0, 0, n, Numeric, "n", "nano", "nano", "", ""},
	"u":     {0, 0, u, Numeric, "u", "micro", "micro", "", ""},
	"m":     {0, 0, m, Numeric, "m", "milli", "milli", "", ""},
	"c":     {0, 0, c, Numeric, "c", "centi", "centi", "", ""},
	"d":     {0, 0, d, Numeric, "d", "deci", "deci", "", ""},
	"1":     DimensionlessUnit,
	"":      DimensionlessUnit,
	"da":    {0, 0, da, Numeric, "da", "deca", "deca", "", ""},
	"dozen": {0, 0, 12, Numeric, "doz", "dozen", "dozen", "", ""},
	"h":     {0, 0, h, Numeric, "h", "hecto", "hecto", "", ""},
	"k":     {0, 0, k, Numeric, "k", "kilo", "kilo", "", ""},
	"M":     {0, 0, _M, Numeric, "M", "mega", "mega", "", ""},
	"G":     {0, 0, _G, Numeric, "G", "giga", "giga", "", ""},
	"T":     {0, 0, _T, Numeric, "T", "tera", "tera", "", ""},
	"P":     {0, 0, _P, Numeric, "P", "peta", "peta", "", ""},
	"E":     {0, 0, _E, Numeric, "E", "exa", "exa", "", ""},
	"Z":     {0, 0, _Z, Numeric, "Z", "zetta", "zetta", "", ""},
	"Y":     {0, 0, _Y, Numeric, "Y", "yotta", "yotta", "", ""},

	"myriad": {
		0, 0, 10000,
		Numeric,
		"myriad", "myriad", "myriads",
		"historically, ten thousand but latterly meaning" +
			" a countless number of things",
		"",
	},

	"million": {
		0, 0, _M,
		Numeric,
		"M", "million", "million", "",
		"",
	},
	"billion": {
		0, 0, _G,
		Numeric,
		"B", "billion", "billion",
		"Note that this reflects the, now universal, meaning of" +
			" 1000 million." +
			" Be aware that some older texts, especially in the UK" +
			" might use this to mean a million squared which was the" +
			" original usage in England. If the text also uses" +
			" milliard then this is most likely to mean a million" +
			" million (what is now generally referred to as a trillion).",
		"",
	},
	"trillion": {
		0, 0, _T,
		Numeric,
		"Tr", "trillion", "trillion",
		"Note that this reflects the, now universal, meaning of" +
			" 1000 billion." +
			" Be aware that some older texts, especially in the UK" +
			" might use this to mean a million cubed which was the" +
			" original usage in England.",
		"",
	},
	"quadrillion": {
		0, 0, _P,
		Numeric,
		"Qu", "quadrillion", "quadrillion",
		"Note that this reflects the, now universal, meaning of" +
			" 1000 trillion." +
			" Be aware that some older texts, especially in the UK" +
			" might use this to mean a million to the power of four" +
			" which was the original usage in England.",
		"",
	},
	"milliard": {
		0, 0, 1e6 * 1000,
		Numeric,
		"milliard", "milliard", "milliard",
		"an English (UK) term for a thousand million," +
			" now obsolete, it has been superseded by" +
			" the US meaning of billion.",
		"",
	},
	"billion (UK)": {
		0, 0, 1e12,
		Numeric,
		"B (UK)", "billion (UK)", "billion (UK)",
		"Note that this reflects the, now obsolete, meaning of" +
			" a million squared." +
			" Be aware that some older texts, especially in the UK" +
			" might use this to mean a million squared which was the" +
			" original usage in England. You will need to judge by" +
			" context whether the original or inflated meaning is" +
			" intended.",
		"",
	},
	"billiard": {
		0, 0, 1e12 * 1000,
		Numeric,
		"billiard", "billiard", "billiard",
		"an English (UK) term for a thousand (UK) billion," +
			" now obsolete, it has been superseded by" +
			" the US meaning of quadrillion.",
		"",
	},
	"trillion (UK)": {
		0, 0, 1e18,
		Numeric,
		"Tr (UK)", "trillion (UK)", "trillion (UK)",
		"Note that this reflects the, now obsolete, meaning of" +
			" a million cubed." +
			" Be aware that some older texts, especially in the UK" +
			" might use trillion to mean a million cubed which was the" +
			" original usage in the UK. You will need to judge by" +
			" context whether the original or inflated meaning is intended.",
		"",
	},
	"trilliard": {
		0, 0, 1e18 * 1000,
		Numeric,
		"trilliard", "trilliard", "trilliard",
		"an English (UK) term for a thousand (UK) trillion," +
			" now obsolete.",
		"",
	},

	"lakh": {
		0, 0, 1e5,
		Numeric,
		"lakh", "lakh", "lakh",
		"Indian: 1,00,000.",
		"",
	},
	"crore": {
		0, 0, 1e7,
		Numeric,
		"crore", "crore", "crore",
		"Indian: 1,00,00,000.",
		"",
	},

	"pony": {
		0, 0, 25,
		Numeric,
		"pony", "pony", "ponies",
		"UK slang: £25.",
		"",
	},
	"monkey": {
		0, 0, 500,
		Numeric,
		"monkey", "monkey", "monkeys",
		"UK slang: £500.",
		"",
	},
	"grand": {
		0, 0, k,
		Numeric,
		"grand", "grand", "grand",
		"UK slang: £1000.",
		"",
	},
}

DimensionlessNames maps names to numeric (dimensionless) units

View Source
var DimensionlessUnit = Unit{
	0, 0, 1,
	Numeric, "", Numeric.BaseUnitName, Numeric.BaseUnitName, "", "",
}

DimensionlessUnit is a suitable default value for a Unit of Numeric

View Source
var DistanceNames = map[string]Unit{

	"ym": {
		0, 0, y,
		UnitOfDistance,
		"ym", "yoctometre", "yoctometres", "a metric measure of distance.",
		"",
	},
	"zm": {
		0, 0, z,
		UnitOfDistance,
		"zm", "zeptometre", "zeptometres", "a metric measure of distance.",
		"",
	},
	"am": {
		0, 0, a,
		UnitOfDistance,
		"am", "attometre", "attometres", "a metric measure of distance.",
		"",
	},
	"fm": {
		0, 0, f,
		UnitOfDistance,
		"fm", "femtometre", "femtometres", "a metric measure of distance.",
		"",
	},
	"pm": {
		0, 0, p,
		UnitOfDistance,
		"pm", "picometre", "picometres", "a metric measure of distance.",
		"",
	},
	"nm": {
		0, 0, n,
		UnitOfDistance,
		"nm", "nanometre", "nanometres", "a metric measure of distance.",
		"",
	},
	"um": {
		0, 0, u,
		UnitOfDistance,
		"µm", "micrometre", "micrometres", "a metric measure of distance.",
		"",
	},
	"mm": {
		0, 0, m,
		UnitOfDistance,
		"mm", "millimetre", "millimetres", "a metric measure of distance.",
		"",
	},
	"cm": {
		0, 0, c,
		UnitOfDistance,
		"cm", "centimetre", "centimetres", "a metric measure of distance.",
		"",
	},
	"dm": {
		0, 0, d,
		UnitOfDistance,
		"dm", "decimetre", "decimetres", "a metric measure of distance.",
		"",
	},
	"metre": MetreUnit,
	"dam": {
		0, 0, da,
		UnitOfDistance,
		"dam", "decametre", "decametres", "a metric measure of distance.",
		"",
	},
	"hm": {
		0, 0, h,
		UnitOfDistance,
		"hm", "hectometre", "hectometres", "a metric measure of distance.",
		"",
	},
	"km": {
		0, 0, k,
		UnitOfDistance,
		"km", "kilometre", "kilometres", "a metric measure of distance.",
		"",
	},
	"mym": {
		0, 0, 10000,
		UnitOfDistance,
		"mym", "myriametre", "myriametres",
		"an obsolete metric measure of distance.",
		"",
	},
	"Mm": {
		0, 0, _M,
		UnitOfDistance,
		"Mm", "megametre", "megametres", "a metric measure of distance.",
		"",
	},
	"Gm": {
		0, 0, _G,
		UnitOfDistance,
		"Gm", "gigametre", "gigametres", "a metric measure of distance.",
		"",
	},
	"Tm": {
		0, 0, _T,
		UnitOfDistance,
		"Tm", "terametre", "terametres", "a metric measure of distance.",
		"",
	},
	"Pm": {
		0, 0, _P,
		UnitOfDistance,
		"Pm", "petametre", "petametres", "a metric measure of distance.",
		"",
	},
	"Em": {
		0, 0, _E,
		UnitOfDistance,
		"Em", "exametre", "exametres", "a metric measure of distance.",
		"",
	},
	"Zm": {
		0, 0, _Z,
		UnitOfDistance,
		"Zm", "zettametre", "zettametres", "a metric measure of distance.",
		"",
	},
	"Ym": {
		0, 0, _Y,
		UnitOfDistance,
		"Ym", "yottametre", "yottametres", "a metric measure of distance.",
		"",
	},

	"barleycorn": {
		0, 0, inchToMetre / 3.0,
		UnitOfDistance,
		"in", "inch", "inches",
		"a non-metric UK measure of distance. This was defined in" +
			" the 'Composition of Yards and Perches' an English" +
			" statute from between 1266-1303.",
		"",
	},
	"inch": {
		0, 0, inchToMetre,
		UnitOfDistance,
		"in", "inch", "inches",
		"imperial/US measure of distance.",
		"",
	},
	"hand": {
		0, 0, inchToMetre * 4,
		UnitOfDistance,
		"hand", "hand", "hands",
		"an imperial measure of length, typically used to measure" +
			" the height of horses.",
		"",
	},
	"link": {
		0, 0, footToMetre * 66 / 100,
		UnitOfDistance,
		"lnk", "link", "links",
		"an imperial measure of length, derived from Gunter's chain" +
			" - a metal chain 66 feet long with 100 links." +
			" Edmund Gunter (1581-1626) was an English clergyman," +
			" mathematician, geometer and astronomer.",
		"",
	},
	"foot": {
		0, 0, footToMetre,
		UnitOfDistance,
		"ft", "foot", "feet",
		"an imperial measure of length, 12 inches.",
		"",
	},
	"foot (North German)": {
		0, 0, footToMetre * 11.0 / 10.0,
		UnitOfDistance,
		"ft (North German)", "foot (North German)", "feet (North German)",
		"a medieval measure of length slightly longer than a standard foot.",
		"",
	},
	"foot (Roman)": {
		0, 0, 0.296,
		UnitOfDistance,
		"ft (Roman)", "foot (Roman)", "feet (Roman)",
		"a Roman measure of length. There are several alternative lengths" +
			" but the one used here is a popular value.",
		"",
	},
	"foot (Parisian)": {
		0, 0, 0.325,
		UnitOfDistance,
		"ft (Parisian)", "foot (Parisian)", "feet (Parisian)",
		"a French measure of length.",
		"",
	},
	"foot (metric)": {
		0, 0, 0.3,
		UnitOfDistance,
		"ft (metric)", "foot (metric)", "feet (metric)",
		"a measure of length - ISO 2848.",
		"",
	},
	"US survey foot": {
		0, 0, 1200.0 / 3937.0,
		UnitOfDistance,
		"ft", "foot", "feet",
		"a US Customary unit of length, longer than a standard foot" +
			" by approximately 2 parts in a million.",
		"",
	},
	"Indian survey foot": {
		0, 0, 0.3047996,
		UnitOfDistance,
		"ft", "foot", "feet",
		"an Indian unit of length.",
		"",
	},
	"yard": {
		0, 0, yardToMetre,
		UnitOfDistance,
		"yd", "yard", "yards",
		"an imperial measure of length, 3 feet.",
		"",
	},
	"rod": {
		0, 0, rodToMetre,
		UnitOfDistance,
		"rod", "rod", "rods",
		"an imperial measure of length, originally equal to 5 yards" +
			" it was redefined as 5.5 yards when England moved from" +
			" the North German to the shorter standard foot in the" +
			" late 13th century" +
			" Note that a rod can also be a measure of area" +
			" under certain circumstances.",
		"",
	},
	"chain": {
		0, 0, rodToMetre * 4,
		UnitOfDistance,
		"ch", "chain", "chains",
		"an imperial measure of length - four rods.",
		"",
	},
	"furlong": {
		0, 0, rodToMetre * 40,
		UnitOfDistance,
		"fur", "furlong", "furlongs",
		"an imperial measure of length - forty rods. Originally a" +
			" furrow's length - the distance a team of oxen" +
			" could plough without resting, later standardised as" +
			" 40 rods.",
		"",
	},
	"mile": {
		0, 0, yardToMetre * 1760,
		UnitOfDistance,
		"mi", "mile", "miles",
		"an imperial measure of length.",
		"",
	},
	"swimming-mile": {
		0, 0, yardToMetre * 1650,
		UnitOfDistance,
		"swim-mi", "swimming mile", "swimming miles",
		"a coloquial and ill-defined distance used by swimmers," +
			" sometimes taken to be 1500 metres.",
		"",
	},
	"league": {
		0, 0, yardToMetre * 1760 * 3,
		UnitOfDistance,
		"lea", "league", "leagues",
		"3 miles (perhaps the distance a person could walk in an hour).",
		"",
	},
	"nautical league": {
		0, 0, 5556,
		UnitOfDistance,
		"lea", "nautical league", "nautical leagues",
		"3 nautical miles.",
		"",
	},

	"fathom": {
		0, 0, yardToMetre * 2,
		UnitOfDistance,
		"ftm", "fathom", "fathoms",
		"an imperial measure of distance equal to two yards.",
		"",
	},
	"nautical-mile": {
		0, 0, 1852,
		UnitOfDistance,
		"M", "nautical mile", "nautical miles",
		"formerly one minute (1/60th of a degree) of latitude" +
			" around any line of latitude, now formally defined" +
			" to have the value given here.",
		"",
	},
	"nautical-mile (US)": {
		0, 0, 6080.2 * footToMetre,
		UnitOfDistance,
		"M", "nautical mile (US)", "nautical miles (US)",
		"one minute (1/60th of a degree) of latitude around" +
			" the Clarke 1866 ellipsoid (6080.210 feet) to 5" +
			" significant figures.",
		"",
	},
	"nautical-mile (Admiralty/UK)": {
		0, 0, 6080 * footToMetre,
		UnitOfDistance,
		"M", "Admiralty nautical mile", "Admiralty nautical miles",
		"an imperial measure of distance equal to" +
			" one minute (1/60th of a degree) of latitude around" +
			" the Clarke 1866 ellipsoid (6080.210 feet) to 4" +
			" significant figures.",
		"",
	},
	"admiralty-fathom": {
		0, 0, 6080 * footToMetre / 1000,
		UnitOfDistance,
		"adm ftm", "Admiralty fathom", "Admiralty fathoms",
		"an imperial measure of distance equal to 1/1000th of" +
			" an Admiralty nautical mile (a little over 2 yards).",
		"",
	},

	"scots mile": {
		0, 0, yardToMetre * 1976,
		UnitOfDistance,
		"Scots mile", "Scots mile", "Scots miles",
		"a measure of distance used in Scotland (slightly" +
			" longer than the English mile), it has not had" +
			" any formal use for over a century.",
		"",
	},
	"irish mile": {
		0, 0, yardToMetre * 2240,
		UnitOfDistance,
		"Irish mile", "Irish mile", "Irish miles",
		"a measure of distance used in Ireland (slightly" +
			" longer than the English mile), no longer" +
			" commonly used.",
		"",
	},

	"astro-unit": {
		0, 0, 1.49597871e11,
		UnitOfDistance,
		"AU", "Astronomical Unit", "Astronomical Units",
		"the mean distance from the centre of the Earth" +
			" to the centre of the sun.",
		"",
	},
	"parsec": {
		0, 0, 3.08567758767931e16,
		UnitOfDistance,
		"pc", "parsec", "parsecs",
		"the distance at which one astronomical unit" +
			" subtends an angle of one second of arc.",
		"",
	},
	"light-year": {
		0, 0, lightSecond * 86400 * 365.25,
		UnitOfDistance,
		"ly", "light year", "light years",
		"the distance travelled by light in a vacuum" +
			" in one year (365.25 days).",
		"",
	},
	"light-second": {
		0, 0, lightSecond,
		UnitOfDistance,
		"ls", "light second", "light seconds",
		"the distance travelled by light in a vacuum" +
			" in one second.",
		"",
	},
	"phoot": {
		0, 0, lightSecond * 1e-9,
		UnitOfDistance,
		"phoot", "phoot", "pheet",
		"the distance travelled by light in a vacuum" +
			" in one nanosecond. Also known as Mermin's foot.",
		"",
	},

	"point": {
		0, 0, pointToMetre,
		UnitOfDistance,
		"pt", "point", "points",
		"a printing term.",
		"",
	},
	"pica": {
		0, 0, 12 * pointToMetre,
		UnitOfDistance,
		"pc", "pica", "pica",
		"a printing term (12 points).",
		"",
	},

	"20ft shipping container": {
		0, 0, (19 * footToMetre) + (10.5 * inchToMetre),
		UnitOfDistance,
		"TEU",
		"length of a 20ft shipping container",
		"lengths of a 20ft shipping container",
		"a colloquial term referencing the length of a standard 20 foot" +
			" shipping container" +
			" presumably to give an impression of scale." +
			" The TEU abbreviation stands for Twenty foot Equivalent Unit." +
			" Note that a 20 foot shipping container is not 20 feet long" +
			" (but a 40 foot container is 40 feet long).",
		"",
	},
	"bus": {
		0, 0, 8.38,
		UnitOfDistance,
		"bus",
		"length of a bus",
		"lengths of a bus",
		"a colloquial term referencing the length of a bus." +
			" The bus used for this value is" +
			" an AEC Routemaster standard, double-decker bus" +
			" as used by London Transport between 1956 and 2005.",
		"",
	},
	"Eiffel Tower": {
		0, 0, 324,
		UnitOfDistance,
		"Eiffel",
		"Eiffel Tower",
		"Eiffel Towers",
		"a colloquial term referencing the height of the Eiffel Tower." +
			" The value given is to the tip of the tower.",
		"",
	},
}

DistanceNames maps names to units of distance

View Source
var EnergyNames = map[string]Unit{

	"yJ": {
		0, 0, y,
		UnitOfEnergy,
		"yJ", "yoctojoule", "yoctojoules",
		"a metric measure of energy.",
		"",
	},
	"zJ": {
		0, 0, z,
		UnitOfEnergy,
		"zJ", "zeptojoule", "zeptojoules",
		"a metric measure of energy.",
		"",
	},
	"aJ": {
		0, 0, a,
		UnitOfEnergy,
		"aJ", "attojoule", "attojoules",
		"a metric measure of energy.",
		"",
	},
	"fJ": {
		0, 0, f,
		UnitOfEnergy,
		"fJ", "femtojoule", "femtojoules",
		"a metric measure of energy.",
		"",
	},
	"pJ": {
		0, 0, p,
		UnitOfEnergy,
		"pJ", "picojoule", "picojoules",
		"a metric measure of energy.",
		"",
	},
	"nJ": {
		0, 0, n,
		UnitOfEnergy,
		"nJ", "nanojoule", "nanojoules",
		"a metric measure of energy.",
		"",
	},
	"uJ": {
		0, 0, u,
		UnitOfEnergy,
		"uJ", "microjoule", "microjoules",
		"a metric measure of energy.",
		"",
	},
	"mJ": {
		0, 0, m,
		UnitOfEnergy,
		"mJ", "millijoule", "millijoules",
		"a metric measure of energy.",
		"",
	},
	"cJ": {
		0, 0, c,
		UnitOfEnergy,
		"cJ", "centijoule", "centijoules",
		"a metric measure of energy.",
		"",
	},
	"dJ": {
		0, 0, d,
		UnitOfEnergy,
		"dJ", "decijoule", "decijoules",
		"a metric measure of energy.",
		"",
	},
	"joule": JouleUnit,
	"daJ": {
		0, 0, da,
		UnitOfEnergy,
		"daJ", "decajoule", "decajoules",
		"a metric measure of energy.",
		"",
	},
	"hJ": {
		0, 0, h,
		UnitOfEnergy,
		"hJ", "hectojoule", "hectojoules",
		"a metric measure of energy.",
		"",
	},
	"kJ": {
		0, 0, k,
		UnitOfEnergy,
		"kJ", "kilojoule", "kilojoules",
		"a metric measure of energy.",
		"",
	},
	"MJ": {
		0, 0, _M,
		UnitOfEnergy,
		"MJ", "megajoule", "megajoules",
		"a metric measure of energy.",
		"",
	},
	"GJ": {
		0, 0, _G,
		UnitOfEnergy,
		"GJ", "gigajoule", "gigajoules",
		"a metric measure of energy.",
		"",
	},
	"TJ": {
		0, 0, _T,
		UnitOfEnergy,
		"TJ", "terajoule", "terajoules",
		"a metric measure of energy.",
		"",
	},
	"PJ": {
		0, 0, _P,
		UnitOfEnergy,
		"PJ", "petajoule", "petajoules",
		"a metric measure of energy.",
		"",
	},
	"EJ": {
		0, 0, _E,
		UnitOfEnergy,
		"EJ", "exajoule", "exajoules",
		"a metric measure of energy.",
		"",
	},
	"ZJ": {
		0, 0, _Z,
		UnitOfEnergy,
		"ZJ", "zettajoule", "zettajoules",
		"a metric measure of energy.",
		"",
	},
	"YJ": {
		0, 0, _Y,
		UnitOfEnergy,
		"YJ", "yottajoule", "yottajoules",
		"a metric measure of energy.",
		"",
	},

	"kWh": {
		0, 0, 3.6e6,
		UnitOfEnergy,
		"kW h", "kilowatt-hour", "killowatt-hours",
		"a measure of energy commonly used as a billing unit" +
			" for energy delivered to consumers by electric utilities.",
		"",
	},

	"erg": {
		0, 0, 1e-7,
		UnitOfEnergy,
		"erg", "erg", "ergs",
		"a measure of energy proposed by" +
			" the German physicist and mathematician Rudolf Clausius.",
		"",
	},
	"foe": {
		0, 0, 1e44,
		UnitOfEnergy,
		"foe", "foe", "foes",
		"a measure of energy equivalent to 10^51 ergs," +
			" the approximate energy released by a supernova." +
			" It was introduced by Gerald E. Brown.",
		"",
	},

	"cal": {
		0, 0, calorieToJoule,
		UnitOfEnergy,
		"cal", "calorie", "calories",
		"a measure of energy (deprecated - use kcal).",
		"",
	},
	"kcal": {
		0, 0, calorieToJoule * 1000,
		UnitOfEnergy,
		"kcal", "kilocalorie", "kilocalories",
		"a measure of energy introduced by Nicolas Clément." +
			" It is widely used in nutrition." +
			" It is the amount of heat energy required to" +
			" raise the temperature of a kilogram of water" +
			" by one degree Celsius." +
			" It is sometimes known as the large calorie.",
		"",
	},

	"electronvolt": {
		0, 0, electronVoltToJoule,
		UnitOfEnergy,
		"eV", "electron volt", "electron volts",
		"The kinetic energy gained by a single electron" +
			" accelerating from rest through" +
			" an electric potential difference of one volt.",
		"",
	},

	"foot-pound": {
		0, 0, footPoundToJoule,
		UnitOfEnergy,
		"ft lb", "foot-pound", "foot-pounds",
		"an imperial measure of energy.",
		"",
	},
	"foot-poundal": {
		0, 0, footPoundalToJoule,
		UnitOfEnergy,
		"ft pdl", "foot-poundal", "foot-poundals",
		"an imperial measure of energy.",
		"",
	},
	"BTU": {
		0, 0, BtuToJoule,
		UnitOfEnergy,
		"Btu", "British thermal unit", "British thermal units",
		"an imperial measure of energy." +
			" This uses the ISO 31-4 conversion to Joules",
		"",
	},
	"therm": {
		0, 0, BtuToJoule * 1e5,
		UnitOfEnergy,
		"therm", "therm", "therms",
		"an imperial measure of energy.",
		"",
	},

	"tonOfTNT": {
		0, 0, calorieToJoule * 1e9,
		UnitOfEnergy,
		"ton of TNT", "ton of TNT", "tons of TNT",
		"a coloquial measure of energy typically used to describe" +
			" the yield of atomic weapons",
		"",
	},
}

EnergyNames maps names to units of energy

View Source
var GramUnit = Unit{
	0, 0, 1,
	UnitOfMass,
	"g", UnitOfMass.BaseUnitName, "grams",
	"a metric measure of mass. Note that the SI unit is the kilogram.",
	"",
}

GramUnit is a suitable default value for a UnitOfMass

View Source
var JouleUnit = Unit{
	0, 0, 1,
	UnitOfEnergy,
	"J", UnitOfEnergy.BaseUnitName, "joules",
	"a metric measure of energy.",
	"",
}

JouleUnit is a suitable default value for a UnitOfEnergy

View Source
var LitreUnit = Unit{
	0, 0, 1e-3,
	UnitOfVolume,
	"l", "litre", "litres",
	"a metric measure of volume.",
	"",
}

LitreUnit is an alternative suitable default value for a UnitOfVolume

View Source
var MassNames = map[string]Unit{

	"yg": {
		0, 0, y,
		UnitOfMass,
		"yg", "yoctogram", "yoctograms", "a metric measure of mass.",
		"",
	},
	"zg": {
		0, 0, z,
		UnitOfMass,
		"zg", "zeptogram", "zeptograms", "a metric measure of mass.",
		"",
	},
	"ag": {
		0, 0, a,
		UnitOfMass,
		"ag", "attogram", "attograms", "a metric measure of mass.",
		"",
	},
	"fg": {
		0, 0, f,
		UnitOfMass,
		"fg", "femtogram", "femtograms", "a metric measure of mass.",
		"",
	},
	"pg": {
		0, 0, p,
		UnitOfMass,
		"pg", "picogram", "picograms", "a metric measure of mass.",
		"",
	},
	"ng": {
		0, 0, n,
		UnitOfMass,
		"ng", "nanogram", "nanograms", "a metric measure of mass.",
		"",
	},
	"ug": {
		0, 0, u,
		UnitOfMass,
		"µg", "microgram", "micrograms", "a metric measure of mass.",
		"",
	},
	"mg": {
		0, 0, m,
		UnitOfMass,
		"mg", "milligram", "milligrams", "a metric measure of mass.",
		"",
	},
	"cg": {
		0, 0, c,
		UnitOfMass,
		"cg", "centigram", "centigrams", "a metric measure of mass.",
		"",
	},
	"dg": {
		0, 0, d,
		UnitOfMass,
		"dg", "decigram", "decigrams", "a metric measure of mass.",
		"",
	},
	"gram": GramUnit,
	"dag": {
		0, 0, da,
		UnitOfMass,
		"dag", "decagram", "decagrams", "a metric measure of mass.",
		"",
	},
	"hg": {
		0, 0, h,
		UnitOfMass,
		"hg", "hectogram", "hectograms", "a metric measure of mass.",
		"",
	},
	"kg": {
		0, 0, k,
		UnitOfMass,
		"kg", "kilogram", "kilograms", "a metric measure of mass.",
		"",
	},
	"myg": {
		0, 0, 10000,
		UnitOfMass,
		"myg", "myriagram", "myriagrams",
		"an obsolete metric measure of mass.",
		"",
	},
	"tonne": {
		0, 0, _M,
		UnitOfMass,
		"T", "tonne", "tonnes",
		"a metric measure of mass." +
			" Also known (in the US as the 'metric ton').",
		"",
	},
	"kilotonne": {
		0, 0, _G,
		UnitOfMass,
		"KT", "kilotonne", "kilotonnes", "a metric measure of mass.",
		"",
	},
	"Tg": {
		0, 0, _T,
		UnitOfMass,
		"Tg", "teragram", "teragrams", "a metric measure of mass.",
		"",
	},
	"megatonne": {
		0, 0, _T,
		UnitOfMass,
		"MT", "megatonne", "megatonnes", "a metric measure of mass.",
		"",
	},
	"Pg": {
		0, 0, _P,
		UnitOfMass,
		"Pg", "petagram", "petagrams", "a metric measure of mass.",
		"",
	},
	"Eg": {
		0, 0, _E,
		UnitOfMass,
		"Eg", "exagram", "exagrams", "a metric measure of mass.",
		"",
	},
	"Zg": {
		0, 0, _Z,
		UnitOfMass,
		"Zg", "zettagram", "zettagrams", "a metric measure of mass.",
		"",
	},
	"Yg": {
		0, 0, _Y,
		UnitOfMass,
		"Yg", "yottagram", "yottagrams", "a metric measure of mass.",
		"",
	},

	"grain": {
		0, 0, grainToGram,
		UnitOfMass,
		"gr", "grain", "grains",
		"an imperial measure of mass (an apothecaries' measure).",
		"",
	},
	"troy-ounce": {
		0, 0, grainToGram * 480,
		UnitOfMass,
		"t oz", "troy ounce", "troy ounces",
		"an imperial measure of mass (an apothecaries' measure).",
		"",
	},
	"scruple": {
		0, 0, grainToGram * 20,
		UnitOfMass,
		"scruple", "scruple", "scruples",
		"an imperial measure of mass (an apothecaries' measure).",
		"",
	},
	"dram": {
		0, 0, grainToGram * 60,
		UnitOfMass,
		"dr", "dram", "drams",
		"an imperial measure of mass (an apothecaries' measure).",
		"",
	},
	"drachm": {
		0, 0, grainToGram * 60,
		UnitOfMass,
		"dr", "drachm", "drachms",
		"an imperial measure of mass (an apothecaries' measure).",
		"",
	},

	"electronvolt": {
		0, 0, electronVoltToJoule / (speedOfLight * speedOfLight),
		UnitOfMass,
		"eV", "electron volt", "electron volts",
		"derived from the unit of energy by" +
			" dividing by the speed of light squared (using e = mc^2).",
		"",
	},
	"gigaelectronvolt": {
		0, 0, _G * electronVoltToJoule / (speedOfLight * speedOfLight),
		UnitOfMass,
		"GeV", "giga electron volt", "giga electron volts",
		"see the description of the electron volt as a unit of mass." +
			" Note that, in general, the masses of all hadrons are" +
			" of the order of one giga electron volt which makes this" +
			" a convenient unit of mass for particle physics.",
		"",
	},

	"ounce": {
		0, 0, ounceToGram,
		UnitOfMass,
		"oz", "ounce", "ounces",
		"an imperial measure of mass.",
		"",
	},
	"pound": {
		0, 0, poundToGram,
		UnitOfMass,
		"lb", "pound", "pounds",
		"an imperial measure of mass.",
		"",
	},
	"stone": {
		0, 0, poundToGram * 14,
		UnitOfMass,
		"st", "stone", "stones",
		"an imperial measure of mass.",
		"",
	},
	"hundredweight": {
		0, 0, poundToGram * 112,
		UnitOfMass,
		"cwt", "hundredweight", "hundredweight",
		"an imperial measure of mass.",
		"",
	},
	"short-hundredweight": {
		0, 0, poundToGram * 100, UnitOfMass,
		"cwt (short)", "short hundredweight", "short hundredweight",
		"a US customary measure of mass.",
		"",
	},
	"imperial-ton": {
		0, 0, poundToGram * 112 * 20,
		UnitOfMass,
		"t", "imperial ton", "imperial tons",
		"an imperial measure of mass." +
			" Also known as a 'long ton' or simply a 'ton'.",
		"",
	},
	"short-ton": {
		0, 0, poundToGram * 100 * 20,
		UnitOfMass,
		"short ton", "short ton", "short tons",
		"an imperial measure of mass.",
		"",
	},

	"earth-mass": {
		0, 0, 5.9722e27,
		UnitOfMass,
		"M⊕", "Earth Mass", "Earth Masses",
		"an astronomical measure of mass, used to give a sense of scale.",
		"",
	},
	"solar-mass": {
		0, 0, 1.98847e33,
		UnitOfMass,
		"M⊙", "Solar Mass", "Solar Masses",
		"an astronomical measure of mass, used to give a sense of scale.",
		"",
	},
	"lunar-mass": {
		0, 0, 7.342e25,
		UnitOfMass,
		"ML", "Lunar Mass", "Lunar Masses",
		"an astronomical measure of mass, used to give a sense of scale.",
		"",
	},
}

MassNames maps names to units of mass

Note that the SI unit of weight is the kilogram not the gram. I have used the gram so as to avoid having to divide all the multiples by 1000 or else having all the multiples offset by one

View Source
var MetrePerSecondUnit = Unit{
	0, 0, 1,
	UnitOfVelocity, "m/s", UnitOfVelocity.BaseUnitName + "/sec", "metres/sec",
	"The base unit of velocity in the metric system.",
	"",
}

MetrePerSecondUnit is a suitable default value for a UnitOfVelocity

View Source
var MetreUnit = Unit{
	0, 0, 1,
	UnitOfDistance, "m", UnitOfDistance.BaseUnitName, "metres",
	"The base unit of distance in the metric system.",
	"",
}

MetreUnit is a suitable default value for a UnitOfDistance

View Source
var Numeric = Family{
	BaseUnitName: "",
	Description:  "dimensionless value",
	Name:         Dimensionless,
}

Numeric represents a dimensionless value

View Source
var SecondUnit = Unit{
	0, 0, 1,
	UnitOfTime,
	"sec", UnitOfTime.BaseUnitName, "seconds", "", "",
}

SecondUnit is a suitable default value for a UnitOfTime

View Source
var SquareMetreUnit = Unit{
	0, 0, 1,
	UnitOfArea,
	"m\u00B2", UnitOfArea.BaseUnitName, "square metres",
	"a metric measure of area.",
	"",
}

SquareMetreUnit is a suitable default value for a UnitOfArea

View Source
var TemperatureNames = map[string]Unit{
	"C":  DegCUnit,
	"F":  DegFUnit,
	"K":  DegKUnit,
	"Ra": DegRaUnit,
	"Ro": DegRoUnit,
	"Re": DegReUnit,
	"N":  DegNUnit,
	"D":  DegDUnit,
}

TemperatureNames maps names to units of temperature

View Source
var TimeNames = map[string]Unit{
	"ysec":   {0, 0, y, UnitOfTime, "ysec", "yoctosecond", "yoctoseconds", "", ""},
	"zsec":   {0, 0, z, UnitOfTime, "zsec", "zeptosecond", "zeptoseconds", "", ""},
	"asec":   {0, 0, a, UnitOfTime, "asec", "attosecond", "attoseconds", "", ""},
	"fsec":   {0, 0, f, UnitOfTime, "fsec", "femtosecond", "femtoseconds", "", ""},
	"psec":   {0, 0, p, UnitOfTime, "psec", "picosecond", "picoseconds", "", ""},
	"nsec":   {0, 0, n, UnitOfTime, "nsec", "nanosecond", "nanoseconds", "", ""},
	"usec":   {0, 0, u, UnitOfTime, "μsec", "microsecond", "microseconds", "", ""},
	"msec":   {0, 0, m, UnitOfTime, "msec", "millisecond", "milliseconds", "", ""},
	"csec":   {0, 0, c, UnitOfTime, "csec", "centisecond", "centiseconds", "", ""},
	"dsec":   {0, 0, d, UnitOfTime, "dsec", "decisecond", "deciseconds", "", ""},
	"second": SecondUnit,
	"minute": {0, 0, 60, UnitOfTime, "min", "minute", "minutes", "", ""},
	"hour":   {0, 0, 60 * 60, UnitOfTime, "hr", "hour", "hours", "", ""},
	"day": {
		0, 0, 60 * 60 * 24,
		UnitOfTime,
		"day", "day", "days",
		"An Ephemeris day." +
			" A solar day varies in length and tends to lengthen" +
			" due to tidal effects.",
		"",
	},
	"week": {
		0, 0, 60 * 60 * 24 * 7,
		UnitOfTime,
		"week", "week", "weeks", "",
		"",
	},
	"fortnight": {
		0, 0, 60 * 60 * 24 * 14,
		UnitOfTime,
		"fortnight", "fortnight", "fortnights", "",
		"",
	},
	"Julian year": {
		0, 0, 365.25 * 86400,
		UnitOfTime,
		"Julian Year", "Julian Year", "Julian Years",
		"365.25 days. A non-SI unit for use in astronomy",
		"",
	},
	"Gregorian year": {
		0, 0, 365.2425 * 86400,
		UnitOfTime,
		"Gregorian Year", "Gregorian Year", "Gregorian Years",
		"Introduced by Pope Gregory XIII in October 1582." +
			" Commonly used as the basis of the Gregorian calendar.",
		"",
	},
	"Siderial year": {
		0, 0, 365.256363004 * 86400,
		UnitOfTime,
		"Siderial Year", "Siderial Year", "Siderial Years",
		"The time taken for the Earth to orbit the Sun" +
			" with respect to the fixed stars",
		"",
	},
	"dasec": {0, 0, da, UnitOfTime, "dasec", "decasecond", "decaseconds", "", ""},
	"hsec":  {0, 0, h, UnitOfTime, "hsec", "hectosecond", "hectoseconds", "", ""},
	"ksec":  {0, 0, k, UnitOfTime, "ksec", "kilosecond", "kiloseconds", "", ""},
	"Msec":  {0, 0, _M, UnitOfTime, "Msec", "megasecond", "megaseconds", "", ""},
	"Gsec":  {0, 0, _G, UnitOfTime, "Gsec", "gigasecond", "gigaseconds", "", ""},
	"Tsec":  {0, 0, _T, UnitOfTime, "Tsec", "terasecond", "teraseconds", "", ""},
	"Psec":  {0, 0, _P, UnitOfTime, "Psec", "petasecond", "petaseconds", "", ""},
	"Esec":  {0, 0, _E, UnitOfTime, "Esec", "exasecond", "exaseconds", "", ""},
	"Zsec":  {0, 0, _Z, UnitOfTime, "Zsec", "zettasecond", "zettaseconds", "", ""},
	"Ysec":  {0, 0, _Y, UnitOfTime, "Ysec", "yottasecond", "yottaseconds", "", ""},
}

TimeNames maps names to units of time

View Source
var UnitOfAngle = Family{
	BaseUnitName: "radian",
	Description:  "unit of angular measure",
	Name:         Angle,
}

UnitOfAngle represents the base unit of angular measure

View Source
var UnitOfArea = Family{
	BaseUnitName: "square metre",
	Description:  "unit of area",
	Name:         Area,
}

UnitOfArea represents the base unit of area

View Source
var UnitOfData = Family{
	BaseUnitName: "byte",
	Description:  "unit of data",
	Name:         Data,
}

UnitOfData represents the base unit of data

For units of data the names follow the metric and IEC naming conventions so MB refers to a megabyte or 1000^2 bytes and MiB refers to a mebibyte or 1024^2 bytes

View Source
var UnitOfDistance = Family{
	BaseUnitName: "metre",
	Description:  "unit of distance",
	Name:         Distance,
}

UnitOfDistance represents the base unit of distance

View Source
var UnitOfEnergy = Family{
	BaseUnitName: "joule",
	Description:  "unit of energy",
	Name:         Energy,
}

UnitOfEnergy represents the base unit of energy

View Source
var UnitOfMass = Family{
	BaseUnitName: "gram",
	Description:  "unit of mass",
	Name:         Mass,
}

UnitOfMass represents the base unit of mass

View Source
var UnitOfTemperature = Family{
	BaseUnitName: "C",
	Description:  "unit of temperature",
	Name:         Temperature,
}

UnitOfTemperature represents the base unit of temperature

View Source
var UnitOfTime = Family{
	BaseUnitName: "second",
	Description:  "unit of time",
	Name:         Time,
}

UnitOfTime represents the base unit of time

View Source
var UnitOfVelocity = Family{
	BaseUnitName: "metrePerSecond",
	Description:  "unit of velocity",
	Name:         Velocity,
}

UnitOfVelocity represents the base unit of Velocity

View Source
var UnitOfVolume = Family{
	BaseUnitName: "cubic metre",
	Description:  "unit of volume",
	Name:         Volume,
}

UnitOfVolume represents the base unit of volume

View Source
var VelocityNames = map[string]Unit{

	"metresPerSecond": MetrePerSecondUnit,
	"kilometresPerHour": {
		0, 0, 1000.0 / 3600.0,
		UnitOfVelocity,
		"km/h", "kilometre/hour", "kilometres/hour",
		"a metric measure of velocity.",
		"",
	},
	"feetPerSecond": {
		0, 0, footToMetre,
		UnitOfVelocity,
		"ft/s", "foot/sec", "feet/sec",
		"an imperial measure of velocity.",
		"",
	},
	"milesPerHour": {
		0, 0, (yardToMetre * 1760) / 3600,
		UnitOfVelocity,
		"mph", "mile/hour", "miles/hour",
		"an imperial measure of velocity.",
		"",
	},
	"percentOfSpeedOfLight": {
		0, 0, lightSecond / 100,
		UnitOfVelocity,
		"%c", "%c", "%c",
		"as a percentage of the speed of light.",
		"",
	},
}

VelocityNames maps names to units of velocity

View Source
var VolumeNames = map[string]Unit{

	"cubic metre": CubicMetreUnit,

	"yl": {
		0, 0, y * 1e-3,
		UnitOfVolume,
		"yl", "yoctolitre", "yoctolitres", "a metric measure of volume.",
		"",
	},
	"zl": {
		0, 0, z * 1e-3,
		UnitOfVolume,
		"zl", "zeptolitre", "zeptolitres", "a metric measure of volume.",
		"",
	},
	"al": {
		0, 0, a * 1e-3,
		UnitOfVolume,
		"al", "attolitre", "attolitres", "a metric measure of volume.",
		"",
	},
	"fl": {
		0, 0, f * 1e-3,
		UnitOfVolume,
		"fl", "femtolitre", "femtolitres", "a metric measure of volume.",
		"",
	},
	"pl": {
		0, 0, p * 1e-3,
		UnitOfVolume,
		"pl", "picolitre", "picolitres", "a metric measure of volume.",
		"",
	},
	"nl": {
		0, 0, n * 1e-3,
		UnitOfVolume,
		"nl", "nanolitre", "nanolitres", "a metric measure of volume.",
		"",
	},
	"ul": {
		0, 0, u * 1e-3,
		UnitOfVolume,
		"ul", "microlitre", "microlitres", "a metric measure of volume.",
		"",
	},
	"ml": {
		0, 0, m * 1e-3,
		UnitOfVolume,
		"ml", "millilitre", "millilitres", "a metric measure of volume.",
		"",
	},
	"cl": {
		0, 0, c * 1e-3,
		UnitOfVolume,
		"cl", "centilitre", "centilitres", "a metric measure of volume.",
		"",
	},
	"dl": {
		0, 0, d * 1e-3,
		UnitOfVolume,
		"dl", "decilitre", "decilitres", "a metric measure of volume.",
		"",
	},
	"litre": LitreUnit,
	"dal": {
		0, 0, da * 1e-3,
		UnitOfVolume,
		"dal", "decalitre", "decalitres", "a metric measure of volume.",
		"",
	},
	"hl": {
		0, 0, h * 1e-3,
		UnitOfVolume,
		"hl", "hectolitre", "hectolitres", "a metric measure of volume.",
		"",
	},
	"kl": {
		0, 0, k * 1e-3,
		UnitOfVolume,
		"kl", "kilolitre", "kilolitres", "a metric measure of volume.",
		"",
	},
	"Ml": {
		0, 0, _M * 1e-3,
		UnitOfVolume,
		"Ml", "megalitre", "megalitres", "a metric measure of volume.",
		"",
	},
	"Gl": {
		0, 0, _G * 1e-3,
		UnitOfVolume,
		"Gl", "gigalitre", "gigalitres", "a metric measure of volume.",
		"",
	},
	"Tl": {
		0, 0, _T * 1e-3,
		UnitOfVolume,
		"Tl", "teralitre", "teralitres", "a metric measure of volume.",
		"",
	},
	"Pl": {
		0, 0, _P * 1e-3,
		UnitOfVolume,
		"Pl", "petalitre", "petalitres", "a metric measure of volume.",
		"",
	},
	"El": {
		0, 0, _E * 1e-3,
		UnitOfVolume,
		"El", "exalitre", "exalitres", "a metric measure of volume.",
		"",
	},
	"Zl": {
		0, 0, _Z * 1e-3,
		UnitOfVolume,
		"Zl", "zettalitre", "zettalitres", "a metric measure of volume.",
		"",
	},
	"Yl": {
		0, 0, _Y * 1e-3,
		UnitOfVolume,
		"Yl", "yottalitre", "yottalitres", "a metric measure of volume.",
		"",
	},

	"bottle-wine": {
		0, 0, bottleToCubicMetre,
		UnitOfVolume,
		"bottle", "bottle (wine)", "bottles (wine)",
		"a measure of volume typically used in the wine and spirits" +
			" trade. Note that there is a now obsolete bottle size of" +
			" 70cl with corresponding multiples.",
		"",
	},
	"magnum": {
		0, 0, bottleToCubicMetre * 2,
		UnitOfVolume,
		"Magnum", "Magnum (wine)", "Magnums (wine)",
		"a measure of volume typically used in the wine and spirits" +
			" trade.",
		"",
	},
	"marie-jeanne": {
		0, 0, bottleToCubicMetre * 3,
		UnitOfVolume,
		"Marie Jeanne", "Marie Jeanne (wine)", "Marie Jeannes (wine)",
		"a measure of volume typically used in the wine and spirits" +
			" trade.",
		"",
	},
	"tappit-hen": {
		0, 0, bottleToCubicMetre * 3,
		UnitOfVolume,
		"Tappit Hen", "Tappit Hen (port)", "Tappit Hens (port)",
		"a measure of volume typically used in the wine and spirits" +
			" trade. This is specifically for port. The name" +
			" derives from the shape of the bottle which is said to" +
			" resemble a hen.",
		"",
	},
	"tregnum": {
		0, 0, bottleToCubicMetre * 3,
		UnitOfVolume,
		"Tregnum", "Tregnum (port)", "Tregnums (port)",
		"a measure of volume typically used in the wine and spirits" +
			" trade, specifically for port.",
		"",
	},
	"jeroboam": {
		0, 0, bottleToCubicMetre * 4,
		UnitOfVolume,
		"Jeroboam", "Jeroboam (wine)", "Jeroboams (wine)",
		"a measure of volume typically used in the wine and spirits" +
			" trade.",
		"",
	},
	"rehoboam": {
		0, 0, bottleToCubicMetre * 6,
		UnitOfVolume,
		"Rehoboam", "Rehoboam (wine)", "Rehoboams (wine)",
		"a measure of volume typically used in the wine and spirits" +
			" trade.",
		"",
	},
	"methuselah": {
		0, 0, bottleToCubicMetre * 8,
		UnitOfVolume,
		"Methuselah", "Methuselah (wine)", "Methuselahs (wine)",
		"a measure of volume typically used in the wine and spirits" +
			" trade.",
		"",
	},
	"salmanazar": {
		0, 0, bottleToCubicMetre * 12,
		UnitOfVolume,
		"Salmanazar", "Salmanazar (wine)", "Salmanazars (wine)",
		"a measure of volume typically used in the wine and spirits" +
			" trade.",
		"",
	},
	"balthazar": {
		0, 0, bottleToCubicMetre * 16,
		UnitOfVolume,
		"Balthazar", "Balthazar (wine)", "Balthazars (wine)",
		"a measure of volume typically used in the wine and spirits" +
			" trade.",
		"",
	},
	"nebuchadnezzar": {
		0, 0, bottleToCubicMetre * 20,
		UnitOfVolume,
		"Nebuchadnezzar", "Nebuchadnezzar (wine)", "Nebuchadnezzars (wine)",
		"a measure of volume typically used in the wine and spirits" +
			" trade.",
		"",
	},

	"cubic inch": {
		0, 0, cubicInchToCubicMetre,
		UnitOfVolume,
		"in\u00B3", "cubic inch", "cubic inches",
		"an imperial measure of volume.",
		"",
	},
	"cubic foot": {
		0, 0, cubicFootToCubicMetre,
		UnitOfVolume,
		"ft\u00B3", "cubic foot", "cubic feet",
		"an imperial measure of volume.",
		"",
	},
	"cubic yard": {
		0, 0, cubicYardToCubicMetre,
		UnitOfVolume,
		"yd\u00B3", "cubic yard", "cubic yards",
		"an imperial measure of volume.",
		"",
	},

	"perch (masonry)": {
		0, 0, 16.5 * 1.5 * 1 * cubicFootToCubicMetre,
		UnitOfVolume,
		"masonry perch", "masonry perch", "masonry perches",
		"a traditional measure of volume for stone and other" +
			" masonry. Note that this refers to the measure" +
			" for dressed stone, a masonry perch of brickwork" +
			" or rubble is a third smaller being one perch" +
			" long by one foot high by one foot wide." +
			" Note that a perch can also be a" +
			" measure of length or area.",
		"",
	},

	"minim": {
		0, 0, fluidOzToCubicMetre / 480,
		UnitOfVolume,
		"min", "minim", "minims",
		"an imperial measure of volume (an apothecaries' measure).",
		"",
	},
	"fluid-scruple": {
		0, 0, fluidOzToCubicMetre / 24,
		UnitOfVolume,
		"fl s", "fluid scruple", "fluid scruples",
		"an imperial measure of volume (an apothecaries' measure).",
		"",
	},
	"fluid-drachm": {
		0, 0, fluidOzToCubicMetre / 8,
		UnitOfVolume,
		"fl dr", "fluid drachm", "fluid drachms",
		"an imperial measure of volume (an apothecaries' measure).",
		"",
	},

	"fluid-ounce": {
		0, 0, fluidOzToCubicMetre,
		UnitOfVolume,
		"fl oz", "fluid ounce", "fluid ounces",
		"an imperial measure of volume.",
		"",
	},
	"gill": {
		0, 0, fluidOzToCubicMetre * 5,
		UnitOfVolume,
		"gi", "gill", "gills",
		"an imperial measure of volume.",
		"",
	},
	"pint": {
		0, 0, fluidOzToCubicMetre * 20,
		UnitOfVolume,
		"pt", "pint", "pints",
		"an imperial measure of volume. Note that this refers to" +
			" the British pint of 20 fluid ounces." +
			" See also the US pint.",
		"",
	},
	"quart": {
		0, 0, fluidOzToCubicMetre * 40,
		UnitOfVolume,
		"qt", "quart", "quarts",
		"an imperial measure of volume.",
		"",
	},
	"gallon": {
		0, 0, gallonToCubicMetre,
		UnitOfVolume,
		"gal", "gallon", "gallons",
		"an imperial measure of volume.",
		"",
	},

	"pin": {
		0, 0, gallonToCubicMetre * 4.5,
		UnitOfVolume,
		"pin", "pin", "pins",
		"an imperial measure of volume, used in the brewing industry" +
			" for large quantities of beer.",
		"",
	},
	"firkin": {
		0, 0, gallonToCubicMetre * 9,
		UnitOfVolume,
		"firkin", "firkin", "firkins",
		"an imperial measure of volume, used in the brewing industry" +
			" for large quantities of beer.",
		"",
	},
	"kilderkin": {
		0, 0, gallonToCubicMetre * 18,
		UnitOfVolume,
		"kilderkin", "kilderkin", "kilderkins",
		"an imperial measure of volume, used in the brewing industry" +
			" for large quantities of beer.",
		"",
	},
	"barrel": {
		0, 0, gallonToCubicMetre * 36,
		UnitOfVolume,
		"barrel", "barrel", "barrels",
		"an imperial measure of volume, used in the brewing industry" +
			" for large quantities of beer.",
		"",
	},
	"hogshead": {
		0, 0, gallonToCubicMetre * 54,
		UnitOfVolume,
		"hogshead", "hogshead", "hogsheads",
		"an imperial measure of volume, used in the brewing industry" +
			" for large quantities of beer.",
		"",
	},

	"peck": {
		0, 0, gallonToCubicMetre * 2,
		UnitOfVolume,
		"peck", "peck", "pecks",
		"an imperial measure of volume, typically for dry goods.",
		"",
	},
	"bushel": {
		0, 0, gallonToCubicMetre * 8,
		UnitOfVolume,
		"bushel", "bushel", "bushels",
		"an imperial measure of volume, typically for dry goods.",
		"",
	},

	"teaspoon": {
		0, 0, usFluidOzToCubicMetre * 0.5 / 3.0,
		UnitOfVolume,
		"tsp", "teaspoon", "teaspoons",
		"a US Customary measure of volume.",
		"",
	},
	"tablespoon": {
		0, 0, usFluidOzToCubicMetre * 0.5,
		UnitOfVolume,
		"Tbsp", "tablespoon", "tablespoons",
		"a US Customary measure of volume.",
		"",
	},
	"US-fluid-ounce": {
		0, 0, usFluidOzToCubicMetre,
		UnitOfVolume,
		"US fl oz", "US fluid ounce", "US fluid ounces",
		"a US Customary measure of volume.",
		"",
	},
	"US-shot": {
		0, 0, usFluidOzToCubicMetre * 1.5,
		UnitOfVolume,
		"shot", "US shot", "US shots",
		"a US Customary measure of volume.",
		"",
	},
	"US-gill": {
		0, 0, usFluidOzToCubicMetre * 4,
		UnitOfVolume,
		"US gi", "US gill", "US gills",
		"a US Customary measure of volume.",
		"",
	},
	"US-cup": {
		0, 0, usFluidOzToCubicMetre * 8,
		UnitOfVolume,
		"US cp", "US cup", "US cups",
		"a US Customary measure of volume.",
		"",
	},
	"US-pint": {
		0, 0, usFluidOzToCubicMetre * 16,
		UnitOfVolume,
		"US pt", "US pint", "US pints",
		"a US Customary measure of volume.",
		"",
	},
	"US-quart": {
		0, 0, usFluidOzToCubicMetre * 32,
		UnitOfVolume,
		"US qt", "US quart", "US quarts",
		"a US Customary measure of volume.",
		"",
	},
	"US-wet-gallon": {
		0, 0, usFluidOzToCubicMetre * 128,
		UnitOfVolume,
		"US gal", "US wet gallon", "US wet gallons",
		"a US Customary measure of volume.",
		"",
	},
	"barrel-oil": {
		0, 0, usFluidOzToCubicMetre * 128 * 42,
		UnitOfVolume,
		"bbl(oil)", "oil barrel", "oil barrels",
		"a US Customary measure of volume.",
		"",
	},
	"US-dry-gallon": {
		0, 0, usDryGallonToCubicMetre,
		UnitOfVolume,
		"US dry gal", "US dry gallon", "US dry gallons",
		"a US Customary measure of volume, typically for dry goods.",
		"",
	},
	"US-bushel": {
		0, 0, usDryGallonToCubicMetre * 8,
		UnitOfVolume,
		"US bushel", "US bushel", "US bushels",
		"a US Customary measure of volume, typically for dry goods.",
		"",
	},
	"US-dry-pint": {
		0, 0, usDryGallonToCubicMetre * 0.125,
		UnitOfVolume,
		"US dry pint", "US dry pint", "US dry pints",
		"a US Customary measure of volume, typically for dry goods.",
		"",
	},

	"20ft shipping container": {
		0, 0, 33.14,
		UnitOfVolume,
		"vol. of a TEU",
		"volume of a 20ft shipping container",
		"volumes of a 20ft shipping container",
		"a colloquial term referencing the volume of a standard 20 foot" +
			" shipping container" +
			" presumably to give an impression of scale." +
			" The TEU abbreviation stands for Twenty foot Equivalent Unit.",
		"",
	},
}

VolumeNames maps names to units of volume

Functions

func ConvertFromBaseUnits

func ConvertFromBaseUnits(v float64, to Unit) (float64, error)

ConvertFromBaseUnits converts a value expressed in the base Units into 'to' Units. It will return a non-nil error if the Units are invalid (have a zero ConvFactor)

func ConvertToBaseUnits

func ConvertToBaseUnits(v float64, from Unit) (float64, error)

ConvertToBaseUnits converts a value expressed in the 'from' Units into base Units. It will return a non-nil error if the Units are invalid (have a zero ConvFactor)

func GetAliases added in v1.4.0

func GetAliases(fName, uName string) []string

GetAliases returns all the aliases for the given family/unit

func GetFamilyNames added in v1.3.0

func GetFamilyNames() []string

GetFamilyNames returns a sorted slice holding the allowed names of unit types

Types

type Alias added in v1.4.0

type Alias struct {
	// UnitName is the name of the unit that this is aliasing
	UnitName string
	// Notes describes the alias itself
	Notes string
}

Alias records details about a particular Alias

type Family

type Family struct {
	BaseUnitName string
	Description  string
	Name         string
	// contains filtered or unexported fields
}

Family records details of a family of units such as units of area or units of mass, it records the name of the base unit and a description. The base unit is the unit in terms of which any conversion factors are defined.

func (Family) String

func (f Family) String() string

String returns a string representation of the Family object

type Unit

type Unit struct {
	ConvPreAdd  float64
	ConvPostAdd float64
	ConvFactor  float64

	Fam        Family
	Abbrev     string
	Name       string
	NamePlural string
	Notes      string
	// contains filtered or unexported fields
}

Unit represents a unit of measure

There are conversion details that allow you to convert to and from the base units for the unit family. There are descriptive strings for display giving abbreviated and full names of the unit.

The aliasName will only be set when the unit has been found through an alias rather than the canonical name.

func GetUnit

func GetUnit(familyName, unitName string) (Unit, error)

GetUnit returns a Unit of the given family and unit name, a non-nil error is returned if the familyName or unitName is not found. It is recommended that the constant values for familyName should be used to reduce the liklihood of runtime errors.

Example

ExampleGetUnit demonstrates the usage of the GetUnit function

package main

import (
	"fmt"

	"github.com/nickwells/units.mod/units"
)

func main() {
	metres := 1

	inch, err := units.GetUnit(units.Length, "inch")
	if err != nil {
		fmt.Printf("Couldn't find a length unit called 'inch': %s\n", err)
	}
	valInInches, err := units.ConvertFromBaseUnits(float64(metres), inch)
	if err != nil {
		fmt.Printf("Couldn't convert to 'inch': %s\n", err)
	}
	fmt.Printf("%d metres == %0.5f %s\n", metres, valInInches, inch.Name)

}
Output:

1 metres == 39.37008 inch

func GetUnitOrPanic added in v1.3.0

func GetUnitOrPanic(familyName, unitName string) Unit

GetUnitOrPanic will call GetUnit and check the error returned. If the error is non-nil it will panic, otherwise it will return the Unit

type UnitDetails

type UnitDetails struct {
	Fam     Family
	AltU    map[string]Unit
	Aliases map[string]Alias
}

UnitDetails bundles together the Family and the associated collection of named alternative units

func GetUnitDetails

func GetUnitDetails(name string) (UnitDetails, error)

GetUnitDetails retrieves the unit details. The error value will be non-nil if the name is not recognised.

func GetUnitDetailsOrPanic added in v1.1.0

func GetUnitDetailsOrPanic(name string) UnitDetails

GetUnitDetailsOrPanic retrieves the unit details. It will panic if the name is not recognised.

func (UnitDetails) GetUnit added in v1.6.0

func (ud UnitDetails) GetUnit(name string) (Unit, error)

GetUnit gets the named unit from the UnitDetails. A non-nil error is returned if the name is not found.

type ValWithUnit

type ValWithUnit struct {
	Val float64
	U   Unit
}

ValWithUnit associates a value with a unit, it is expected that the value is a measure expressed in the given units

func (ValWithUnit) Convert

func (v ValWithUnit) Convert(u Unit) (ValWithUnit, error)

Convert will convert the value from its current units to the new units. If the new units are not in the same unit family as the existing units or are otherwise invalid (have a zero ConvFactor) the value is unchanged and a non-nil error is returned.

Example

ExampleValWithUnit_Convert demonstrates the use of the ValWithUnit.Convert function. Note that we use the ...OrPanic variants to streamline the code. In this example we know that the various units exist and are well-formed - it is a programming error if any of the calls fail (such as a typo in the unit name).

package main

import (
	"fmt"

	"github.com/nickwells/units.mod/units"
)

func main() {
	inch := units.GetUnitOrPanic(units.Length, "inch")
	foot := units.GetUnitOrPanic(units.Length, "foot")

	vInInches := units.ValWithUnit{12.0, inch}

	vInFeet := vInInches.ConvertOrPanic(foot)

	fmt.Printf("%s = %s\n", vInInches, vInFeet)
}
Output:

12 inches = 1 foot

func (ValWithUnit) ConvertOrPanic added in v1.3.0

func (v ValWithUnit) ConvertOrPanic(u Unit) ValWithUnit

ConvertOrPanic will call Convert and if the error returned is not nil it will panic, otherwise it will return the ValWithUnit value

func (ValWithUnit) String

func (v ValWithUnit) String() string

String returns a string form of the ValWithUnit

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL