unit: remove explicitly prefixed constants

This commit is contained in:
Dan Kortschak
2019-04-09 10:00:29 +09:30
parent e704b2e393
commit 16be42a8a8
29 changed files with 221 additions and 918 deletions

View File

@@ -16,29 +16,7 @@ import (
// AbsorbedRadioactiveDose is a measure of absorbed dose of ionizing radiation in grays. // AbsorbedRadioactiveDose is a measure of absorbed dose of ionizing radiation in grays.
type AbsorbedRadioactiveDose float64 type AbsorbedRadioactiveDose float64
const ( const Gray AbsorbedRadioactiveDose = 1
Yottagray AbsorbedRadioactiveDose = 1e24
Zettagray AbsorbedRadioactiveDose = 1e21
Exagray AbsorbedRadioactiveDose = 1e18
Petagray AbsorbedRadioactiveDose = 1e15
Teragray AbsorbedRadioactiveDose = 1e12
Gigagray AbsorbedRadioactiveDose = 1e9
Megagray AbsorbedRadioactiveDose = 1e6
Kilogray AbsorbedRadioactiveDose = 1e3
Hectogray AbsorbedRadioactiveDose = 1e2
Decagray AbsorbedRadioactiveDose = 1e1
Gray AbsorbedRadioactiveDose = 1.0
Decigray AbsorbedRadioactiveDose = 1e-1
Centigray AbsorbedRadioactiveDose = 1e-2
Milligray AbsorbedRadioactiveDose = 1e-3
Microgray AbsorbedRadioactiveDose = 1e-6
Nanogray AbsorbedRadioactiveDose = 1e-9
Picogray AbsorbedRadioactiveDose = 1e-12
Femtogray AbsorbedRadioactiveDose = 1e-15
Attogray AbsorbedRadioactiveDose = 1e-18
Zeptogray AbsorbedRadioactiveDose = 1e-21
Yoctogray AbsorbedRadioactiveDose = 1e-24
)
// Unit converts the AbsorbedRadioactiveDose to a *Unit // Unit converts the AbsorbedRadioactiveDose to a *Unit
func (a AbsorbedRadioactiveDose) Unit() *Unit { func (a AbsorbedRadioactiveDose) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Angle represents an angle in radians. // Angle represents an angle in radians.
type Angle float64 type Angle float64
const ( const Rad Angle = 1
Yottarad Angle = 1e24
Zettarad Angle = 1e21
Exarad Angle = 1e18
Petarad Angle = 1e15
Terarad Angle = 1e12
Gigarad Angle = 1e9
Megarad Angle = 1e6
Kilorad Angle = 1e3
Hectorad Angle = 1e2
Decarad Angle = 1e1
Rad Angle = 1.0
Decirad Angle = 1e-1
Centirad Angle = 1e-2
Millirad Angle = 1e-3
Microrad Angle = 1e-6
Nanorad Angle = 1e-9
Picorad Angle = 1e-12
Femtorad Angle = 1e-15
Attorad Angle = 1e-18
Zeptorad Angle = 1e-21
Yoctorad Angle = 1e-24
)
// Unit converts the Angle to a *Unit // Unit converts the Angle to a *Unit
func (a Angle) Unit() *Unit { func (a Angle) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Capacitance represents an electrical capacitance in Farads. // Capacitance represents an electrical capacitance in Farads.
type Capacitance float64 type Capacitance float64
const ( const Farad Capacitance = 1
Yottafarad Capacitance = 1e24
Zettafarad Capacitance = 1e21
Exafarad Capacitance = 1e18
Petafarad Capacitance = 1e15
Terafarad Capacitance = 1e12
Gigafarad Capacitance = 1e9
Megafarad Capacitance = 1e6
Kilofarad Capacitance = 1e3
Hectofarad Capacitance = 1e2
Decafarad Capacitance = 1e1
Farad Capacitance = 1.0
Decifarad Capacitance = 1e-1
Centifarad Capacitance = 1e-2
Millifarad Capacitance = 1e-3
Microfarad Capacitance = 1e-6
Nanofarad Capacitance = 1e-9
Picofarad Capacitance = 1e-12
Femtofarad Capacitance = 1e-15
Attofarad Capacitance = 1e-18
Zeptofarad Capacitance = 1e-21
Yoctofarad Capacitance = 1e-24
)
// Unit converts the Capacitance to a *Unit // Unit converts the Capacitance to a *Unit
func (cp Capacitance) Unit() *Unit { func (cp Capacitance) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Charge represents an electric charge in Coulombs. // Charge represents an electric charge in Coulombs.
type Charge float64 type Charge float64
const ( const Coulomb Charge = 1
Yottacoulomb Charge = 1e24
Zettacoulomb Charge = 1e21
Exacoulomb Charge = 1e18
Petacoulomb Charge = 1e15
Teracoulomb Charge = 1e12
Gigacoulomb Charge = 1e9
Megacoulomb Charge = 1e6
Kilocoulomb Charge = 1e3
Hectocoulomb Charge = 1e2
Decacoulomb Charge = 1e1
coulomb Charge = 1.0
Decicoulomb Charge = 1e-1
Centicoulomb Charge = 1e-2
Millicoulomb Charge = 1e-3
Microcoulomb Charge = 1e-6
Nanocoulomb Charge = 1e-9
Picocoulomb Charge = 1e-12
Femtocoulomb Charge = 1e-15
Attocoulomb Charge = 1e-18
Zeptocoulomb Charge = 1e-21
Yoctocoulomb Charge = 1e-24
)
// Unit converts the Charge to a *Unit // Unit converts the Charge to a *Unit
func (ch Charge) Unit() *Unit { func (ch Charge) Unit() *Unit {
@@ -56,7 +34,7 @@ func (ch Charge) Charge() Charge {
// From converts the unit into the receiver. From returns an // From converts the unit into the receiver. From returns an
// error if there is a mismatch in dimension // error if there is a mismatch in dimension
func (ch *Charge) From(u Uniter) error { func (ch *Charge) From(u Uniter) error {
if !DimensionsMatch(u, coulomb) { if !DimensionsMatch(u, Coulomb) {
*ch = Charge(math.NaN()) *ch = Charge(math.NaN())
return errors.New("Dimension mismatch") return errors.New("Dimension mismatch")
} }

View File

@@ -16,29 +16,7 @@ import (
// Conductance represents an electrical conductance in Siemens. // Conductance represents an electrical conductance in Siemens.
type Conductance float64 type Conductance float64
const ( const Siemens Conductance = 1
Yottasiemens Conductance = 1e24
Zettasiemens Conductance = 1e21
Exasiemens Conductance = 1e18
Petasiemens Conductance = 1e15
Terasiemens Conductance = 1e12
Gigasiemens Conductance = 1e9
Megasiemens Conductance = 1e6
Kilosiemens Conductance = 1e3
Hectosiemens Conductance = 1e2
Decasiemens Conductance = 1e1
Siemens Conductance = 1.0
Decisiemens Conductance = 1e-1
Centisiemens Conductance = 1e-2
Millisiemens Conductance = 1e-3
Microsiemens Conductance = 1e-6
Nanosiemens Conductance = 1e-9
Picosiemens Conductance = 1e-12
Femtosiemens Conductance = 1e-15
Attosiemens Conductance = 1e-18
Zeptosiemens Conductance = 1e-21
Yoctosiemens Conductance = 1e-24
)
// Unit converts the Conductance to a *Unit // Unit converts the Conductance to a *Unit
func (co Conductance) Unit() *Unit { func (co Conductance) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Current represents a current in Amperes. // Current represents a current in Amperes.
type Current float64 type Current float64
const ( const Ampere Current = 1
Yottaampere Current = 1e24
Zettaampere Current = 1e21
Exaampere Current = 1e18
Petaampere Current = 1e15
Teraampere Current = 1e12
Gigaampere Current = 1e9
Megaampere Current = 1e6
Kiloampere Current = 1e3
Hectoampere Current = 1e2
Decaampere Current = 1e1
Ampere Current = 1.0
Deciampere Current = 1e-1
Centiampere Current = 1e-2
Milliampere Current = 1e-3
Microampere Current = 1e-6
Nanoampere Current = 1e-9
Picoampere Current = 1e-12
Femtoampere Current = 1e-15
Attoampere Current = 1e-18
Zeptoampere Current = 1e-21
Yoctoampere Current = 1e-24
)
// Unit converts the Current to a *Unit // Unit converts the Current to a *Unit
func (i Current) Unit() *Unit { func (i Current) Unit() *Unit {

View File

@@ -17,7 +17,7 @@
// unit or a common combination of base units, named for the physical quantity // unit or a common combination of base units, named for the physical quantity
// it represents (Length, Mass, Pressure, etc.). Each type is defined from // it represents (Length, Mass, Pressure, etc.). Each type is defined from
// float64. The value of the float64 represents the quantity of that unit as // float64. The value of the float64 represents the quantity of that unit as
// expressed in SI base units (Kilogram, Metre, Pascal, etc.). For example, // expressed in SI base units (kilogram, metre, Pascal, etc.). For example,
// //
// height := 1.6 * unit.Metre // height := 1.6 * unit.Metre
// acc := unit.Acceleration(9.8) // acc := unit.Acceleration(9.8)
@@ -33,7 +33,7 @@
// //
// func main(){ // func main(){
// t := 300 * unit.Kelvin // t := 300 * unit.Kelvin
// p := 500 * unit.Kilopascal // p := 500 * unit.Kilo * unit.Pascal
// v := unitVolume(p, t) // compile-time error // v := unitVolume(p, t) // compile-time error
// } // }
// //
@@ -75,7 +75,7 @@
// creates a variable "rate" which has a value of 1e-3 mol/s. Methods of // creates a variable "rate" which has a value of 1e-3 mol/s. Methods of
// unit can be used to modify this value, for example: // unit can be used to modify this value, for example:
// //
// rate.Mul(1 * unit.Centimetre).Div(1 * unit.Millivolt) // rate.Mul(1 * unit.Centi * unit.Metre).Div(1 * unit.Milli * unit.Volt)
// //
// To convert the unit back into a typed float64 value, the From methods // To convert the unit back into a typed float64 value, the From methods
// of the dimensional types should be used. From will return an error if the // of the dimensional types should be used. From will return an error if the
@@ -98,7 +98,7 @@
// because in this case slide is just a measurement of liquid volume. Instead, // because in this case slide is just a measurement of liquid volume. Instead,
// a constant could be defined. // a constant could be defined.
// //
// const Slide unit.Volume = 0.1 * unit.Microlitre // const Slide unit.Volume = 0.1 * unit.Micro * unit.Litre
// //
// Note that unit cannot catch all errors related to dimensionality. // Note that unit cannot catch all errors related to dimensionality.
// Different physical ideas are sometimes expressed with the same dimensions // Different physical ideas are sometimes expressed with the same dimensions

View File

@@ -16,29 +16,7 @@ import (
// Energy represents a quantity of energy in Joules. // Energy represents a quantity of energy in Joules.
type Energy float64 type Energy float64
const ( const Joule Energy = 1
Yottajoule Energy = 1e24
Zettajoule Energy = 1e21
Exajoule Energy = 1e18
Petajoule Energy = 1e15
Terajoule Energy = 1e12
Gigajoule Energy = 1e9
Megajoule Energy = 1e6
Kilojoule Energy = 1e3
Hectojoule Energy = 1e2
Decajoule Energy = 1e1
Joule Energy = 1.0
Decijoule Energy = 1e-1
Centijoule Energy = 1e-2
Millijoule Energy = 1e-3
Microjoule Energy = 1e-6
Nanojoule Energy = 1e-9
Picojoule Energy = 1e-12
Femtojoule Energy = 1e-15
Attojoule Energy = 1e-18
Zeptojoule Energy = 1e-21
Yoctojoule Energy = 1e-24
)
// Unit converts the Energy to a *Unit // Unit converts the Energy to a *Unit
func (e Energy) Unit() *Unit { func (e Energy) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// EquivalentRadioactiveDose is a measure of equivalent dose of ionizing radiation in sieverts. // EquivalentRadioactiveDose is a measure of equivalent dose of ionizing radiation in sieverts.
type EquivalentRadioactiveDose float64 type EquivalentRadioactiveDose float64
const ( const Sievert EquivalentRadioactiveDose = 1
Yottasievert EquivalentRadioactiveDose = 1e24
Zettasievert EquivalentRadioactiveDose = 1e21
Exasievert EquivalentRadioactiveDose = 1e18
Petasievert EquivalentRadioactiveDose = 1e15
Terasievert EquivalentRadioactiveDose = 1e12
Gigasievert EquivalentRadioactiveDose = 1e9
Megasievert EquivalentRadioactiveDose = 1e6
Kilosievert EquivalentRadioactiveDose = 1e3
Hectosievert EquivalentRadioactiveDose = 1e2
Decasievert EquivalentRadioactiveDose = 1e1
Sievert EquivalentRadioactiveDose = 1.0
Decisievert EquivalentRadioactiveDose = 1e-1
Centisievert EquivalentRadioactiveDose = 1e-2
Millisievert EquivalentRadioactiveDose = 1e-3
Microsievert EquivalentRadioactiveDose = 1e-6
Nanosievert EquivalentRadioactiveDose = 1e-9
Picosievert EquivalentRadioactiveDose = 1e-12
Femtosievert EquivalentRadioactiveDose = 1e-15
Attosievert EquivalentRadioactiveDose = 1e-18
Zeptosievert EquivalentRadioactiveDose = 1e-21
Yoctosievert EquivalentRadioactiveDose = 1e-24
)
// Unit converts the EquivalentRadioactiveDose to a *Unit // Unit converts the EquivalentRadioactiveDose to a *Unit
func (a EquivalentRadioactiveDose) Unit() *Unit { func (a EquivalentRadioactiveDose) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Force represents a force in Newtons. // Force represents a force in Newtons.
type Force float64 type Force float64
const ( const Newton Force = 1
Yottanewton Force = 1e24
Zettanewton Force = 1e21
Exanewton Force = 1e18
Petanewton Force = 1e15
Teranewton Force = 1e12
Giganewton Force = 1e9
Meganewton Force = 1e6
Kilonewton Force = 1e3
Hectonewton Force = 1e2
Decanewton Force = 1e1
Newton Force = 1.0
Decinewton Force = 1e-1
Centinewton Force = 1e-2
Millinewton Force = 1e-3
Micronewton Force = 1e-6
Nanonewton Force = 1e-9
Piconewton Force = 1e-12
Femtonewton Force = 1e-15
Attonewton Force = 1e-18
Zeptonewton Force = 1e-21
Yoctonewton Force = 1e-24
)
// Unit converts the Force to a *Unit // Unit converts the Force to a *Unit
func (f Force) Unit() *Unit { func (f Force) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Frequency represents a frequency in Hertz. // Frequency represents a frequency in Hertz.
type Frequency float64 type Frequency float64
const ( const Hertz Frequency = 1
Yottahertz Frequency = 1e24
Zettahertz Frequency = 1e21
Exahertz Frequency = 1e18
Petahertz Frequency = 1e15
Terahertz Frequency = 1e12
Gigahertz Frequency = 1e9
Megahertz Frequency = 1e6
Kilohertz Frequency = 1e3
Hectohertz Frequency = 1e2
Decahertz Frequency = 1e1
Hertz Frequency = 1.0
Decihertz Frequency = 1e-1
Centihertz Frequency = 1e-2
Millihertz Frequency = 1e-3
Microhertz Frequency = 1e-6
Nanohertz Frequency = 1e-9
Picohertz Frequency = 1e-12
Femtohertz Frequency = 1e-15
Attohertz Frequency = 1e-18
Zeptohertz Frequency = 1e-21
Yoctohertz Frequency = 1e-24
)
// Unit converts the Frequency to a *Unit // Unit converts the Frequency to a *Unit
func (f Frequency) Unit() *Unit { func (f Frequency) Unit() *Unit {

View File

@@ -18,13 +18,12 @@ import (
) )
type Unit struct { type Unit struct {
Name string DimensionName string
Receiver string Receiver string
Offset int // From normal (for example, mass base unit is kg, not kg) PowerOffset int // From normal (for example, mass base unit is kg, not kg)
PrintString string // print string for the unit (kg for mass) PrintString string // print string for the unit (kg for mass)
ExtraConstant []Constant ExtraConstant []Constant
Suffix string Name string
Singular string
TypeComment string // Text to comment the type TypeComment string // Text to comment the type
Dimensions []Dimension Dimensions []Dimension
ErForm string // For Xxxer interface ErForm string // For Xxxer interface
@@ -75,168 +74,77 @@ type Prefix struct {
Power int Power int
} }
var Prefixes = []Prefix{
{
Name: "Yotta",
Power: 24,
},
{
Name: "Zetta",
Power: 21,
},
{
Name: "Exa",
Power: 18,
},
{
Name: "Peta",
Power: 15,
},
{
Name: "Tera",
Power: 12,
},
{
Name: "Giga",
Power: 9,
},
{
Name: "Mega",
Power: 6,
},
{
Name: "Kilo",
Power: 3,
},
{
Name: "Hecto",
Power: 2,
},
{
Name: "Deca",
Power: 1,
},
{
Name: "",
Power: 0,
},
{
Name: "Deci",
Power: -1,
},
{
Name: "Centi",
Power: -2,
},
{
Name: "Milli",
Power: -3,
},
{
Name: "Micro",
Power: -6,
},
{
Name: "Nano",
Power: -9,
},
{
Name: "Pico",
Power: -12,
},
{
Name: "Femto",
Power: -15,
},
{
Name: "Atto",
Power: -18,
},
{
Name: "Zepto",
Power: -21,
},
{
Name: "Yocto",
Power: -24,
},
}
var Units = []Unit{ var Units = []Unit{
// Base units. // Base units.
{ {
Name: "Angle", DimensionName: "Angle",
Receiver: "a", Receiver: "a",
PrintString: "rad", PrintString: "rad",
Suffix: "rad", Name: "Rad",
Singular: "Rad",
TypeComment: "Angle represents an angle in radians", TypeComment: "Angle represents an angle in radians",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: AngleName, Power: 1}, {Name: AngleName, Power: 1},
}, },
}, },
{ {
Name: "Current", DimensionName: "Current",
Receiver: "i", Receiver: "i",
PrintString: "A", PrintString: "A",
Suffix: "ampere", Name: "Ampere",
Singular: "Ampere",
TypeComment: "Current represents a current in Amperes", TypeComment: "Current represents a current in Amperes",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: CurrentName, Power: 1}, {Name: CurrentName, Power: 1},
}, },
}, },
{ {
Name: "Length", DimensionName: "Length",
Receiver: "l", Receiver: "l",
PrintString: "m", PrintString: "m",
Suffix: "metre", Name: "Metre",
Singular: "Metre",
TypeComment: "Length represents a length in metres", TypeComment: "Length represents a length in metres",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: LengthName, Power: 1}, {Name: LengthName, Power: 1},
}, },
}, },
{ {
Name: "LuminousIntensity", DimensionName: "LuminousIntensity",
Receiver: "j", Receiver: "j",
PrintString: "cd", PrintString: "cd",
Suffix: "candela", Name: "Candela",
Singular: "Candela",
TypeComment: "Candela represents a luminous intensity in candela", TypeComment: "Candela represents a luminous intensity in candela",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: LuminousIntensityName, Power: 1}, {Name: LuminousIntensityName, Power: 1},
}, },
}, },
{ {
Name: "Mass", DimensionName: "Mass",
Receiver: "m", Receiver: "m",
Offset: -3, PowerOffset: -3,
PrintString: "kg", PrintString: "kg",
Suffix: "gram", Name: "Gram",
Singular: "Gram",
TypeComment: "Mass represents a mass in kilograms", TypeComment: "Mass represents a mass in kilograms",
ExtraConstant: []Constant{
{Name: "Kilogram", Value: "Kilo * Gram"},
},
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: MassName, Power: 1}, {Name: MassName, Power: 1},
}, },
}, },
{ {
Name: "Mole", DimensionName: "Mole",
Receiver: "n", Receiver: "n",
PrintString: "mol", PrintString: "mol",
Suffix: "mol", Name: "Mol",
Singular: "mol",
TypeComment: "Mole represents an amount in moles", TypeComment: "Mole represents an amount in moles",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: MoleName, Power: 1}, {Name: MoleName, Power: 1},
}, },
}, },
{ {
Name: "Temperature", DimensionName: "Temperature",
Receiver: "t", Receiver: "t",
PrintString: "K", PrintString: "K",
Suffix: "kelvin", Name: "Kelvin",
Singular: "Kelvin",
TypeComment: "Temperature represents a temperature in Kelvin", TypeComment: "Temperature represents a temperature in Kelvin",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: TemperatureName, Power: 1}, {Name: TemperatureName, Power: 1},
@@ -244,15 +152,14 @@ var Units = []Unit{
ErForm: "Temperaturer", ErForm: "Temperaturer",
}, },
{ {
Name: "Time", DimensionName: "Time",
Receiver: "t", Receiver: "t",
PrintString: "s", PrintString: "s",
Suffix: "second", Name: "Second",
Singular: "Second", TypeComment: "Time represents a duration in seconds",
TypeComment: "Time represents a time in seconds",
ExtraConstant: []Constant{ ExtraConstant: []Constant{
{Name: "Hour", Value: "3600"}, {Name: "Minute", Value: "60 * Second"},
{Name: "Minute", Value: "60"}, {Name: "Hour", Value: "60 * Minute"},
}, },
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: TimeName, Power: 1}, {Name: TimeName, Power: 1},
@@ -262,11 +169,10 @@ var Units = []Unit{
// Derived units. // Derived units.
{ {
Name: "AbsorbedRadioactiveDose", DimensionName: "AbsorbedRadioactiveDose",
Receiver: "a", Receiver: "a",
PrintString: "Gy", PrintString: "Gy",
Suffix: "gray", Name: "Gray",
Singular: "Gray",
TypeComment: "AbsorbedRadioactiveDose is a measure of absorbed dose of ionizing radiation in grays", TypeComment: "AbsorbedRadioactiveDose is a measure of absorbed dose of ionizing radiation in grays",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: LengthName, Power: 2}, {Name: LengthName, Power: 2},
@@ -274,7 +180,7 @@ var Units = []Unit{
}, },
}, },
{ {
Name: "Acceleration", DimensionName: "Acceleration",
Receiver: "a", Receiver: "a",
PrintString: "m s^-2", PrintString: "m s^-2",
TypeComment: "Acceleration represents an acceleration in metres per second squared", TypeComment: "Acceleration represents an acceleration in metres per second squared",
@@ -284,7 +190,7 @@ var Units = []Unit{
}, },
}, },
{ {
Name: "Area", DimensionName: "Area",
Receiver: "a", Receiver: "a",
PrintString: "m^2", PrintString: "m^2",
TypeComment: "Area represents and area in square metres", TypeComment: "Area represents and area in square metres",
@@ -293,22 +199,20 @@ var Units = []Unit{
}, },
}, },
{ {
Name: "Radioactivity", DimensionName: "Radioactivity",
Receiver: "r", Receiver: "r",
PrintString: "Bq", PrintString: "Bq",
Suffix: "becquerel", Name: "Becquerel",
Singular: "Becquerel",
TypeComment: "Radioactivity represents a rate of radioactive decay in becquerels", TypeComment: "Radioactivity represents a rate of radioactive decay in becquerels",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: TimeName, Power: -1}, {Name: TimeName, Power: -1},
}, },
}, },
{ {
Name: "Capacitance", DimensionName: "Capacitance",
Receiver: "cp", Receiver: "cp",
PrintString: "F", PrintString: "F",
Suffix: "farad", Name: "Farad",
Singular: "Farad",
TypeComment: "Capacitance represents an electrical capacitance in Farads", TypeComment: "Capacitance represents an electrical capacitance in Farads",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: CurrentName, Power: 2}, {Name: CurrentName, Power: 2},
@@ -319,11 +223,10 @@ var Units = []Unit{
ErForm: "Capacitancer", ErForm: "Capacitancer",
}, },
{ {
Name: "Charge", DimensionName: "Charge",
Receiver: "ch", Receiver: "ch",
PrintString: "C", PrintString: "C",
Suffix: "coulomb", Name: "Coulomb",
Singular: "coulomb",
TypeComment: "Charge represents an electric charge in Coulombs", TypeComment: "Charge represents an electric charge in Coulombs",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: CurrentName, Power: 1}, {Name: CurrentName, Power: 1},
@@ -332,11 +235,10 @@ var Units = []Unit{
ErForm: "Charger", ErForm: "Charger",
}, },
{ {
Name: "Conductance", DimensionName: "Conductance",
Receiver: "co", Receiver: "co",
PrintString: "S", PrintString: "S",
Suffix: "siemens", Name: "Siemens",
Singular: "Siemens",
TypeComment: "Conductance represents an electrical conductance in Siemens", TypeComment: "Conductance represents an electrical conductance in Siemens",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: CurrentName, Power: 2}, {Name: CurrentName, Power: 2},
@@ -347,11 +249,10 @@ var Units = []Unit{
ErForm: "Conductancer", ErForm: "Conductancer",
}, },
{ {
Name: "EquivalentRadioactiveDose", DimensionName: "EquivalentRadioactiveDose",
Receiver: "a", Receiver: "a",
PrintString: "Sy", PrintString: "Sy",
Suffix: "sievert", Name: "Sievert",
Singular: "Sievert",
TypeComment: "EquivalentRadioactiveDose is a measure of equivalent dose of ionizing radiation in sieverts", TypeComment: "EquivalentRadioactiveDose is a measure of equivalent dose of ionizing radiation in sieverts",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: LengthName, Power: 2}, {Name: LengthName, Power: 2},
@@ -359,11 +260,10 @@ var Units = []Unit{
}, },
}, },
{ {
Name: "Energy", DimensionName: "Energy",
Receiver: "e", Receiver: "e",
PrintString: "J", PrintString: "J",
Suffix: "joule", Name: "Joule",
Singular: "Joule",
TypeComment: "Energy represents a quantity of energy in Joules", TypeComment: "Energy represents a quantity of energy in Joules",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: LengthName, Power: 2}, {Name: LengthName, Power: 2},
@@ -372,22 +272,20 @@ var Units = []Unit{
}, },
}, },
{ {
Name: "Frequency", DimensionName: "Frequency",
Receiver: "f", Receiver: "f",
PrintString: "Hz", PrintString: "Hz",
Suffix: "hertz", Name: "Hertz",
Singular: "Hertz",
TypeComment: "Frequency represents a frequency in Hertz", TypeComment: "Frequency represents a frequency in Hertz",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: TimeName, Power: -1}, {Name: TimeName, Power: -1},
}, },
}, },
{ {
Name: "Force", DimensionName: "Force",
Receiver: "f", Receiver: "f",
PrintString: "N", PrintString: "N",
Suffix: "newton", Name: "Newton",
Singular: "Newton",
TypeComment: "Force represents a force in Newtons", TypeComment: "Force represents a force in Newtons",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: LengthName, Power: 1}, {Name: LengthName, Power: 1},
@@ -397,11 +295,10 @@ var Units = []Unit{
ErForm: "Forcer", ErForm: "Forcer",
}, },
{ {
Name: "Inductance", DimensionName: "Inductance",
Receiver: "i", Receiver: "i",
PrintString: "H", PrintString: "H",
Suffix: "henry", Name: "Henry",
Singular: "Henry",
TypeComment: "Inductance represents an electrical inductance in Henry", TypeComment: "Inductance represents an electrical inductance in Henry",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: CurrentName, Power: -2}, {Name: CurrentName, Power: -2},
@@ -412,11 +309,10 @@ var Units = []Unit{
ErForm: "Inductancer", ErForm: "Inductancer",
}, },
{ {
Name: "Power", DimensionName: "Power",
Receiver: "pw", Receiver: "pw",
PrintString: "W", PrintString: "W",
Suffix: "watt", Name: "Watt",
Singular: "Watt",
TypeComment: "Power represents a power in Watts", TypeComment: "Power represents a power in Watts",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: LengthName, Power: 2}, {Name: LengthName, Power: 2},
@@ -425,11 +321,10 @@ var Units = []Unit{
}, },
}, },
{ {
Name: "Resistance", DimensionName: "Resistance",
Receiver: "r", Receiver: "r",
PrintString: "Ω", PrintString: "Ω",
Suffix: "ohm", Name: "Ohm",
Singular: "Ohm",
TypeComment: "Resistance represents an electrical resistance, impedance or reactance in Ohms", TypeComment: "Resistance represents an electrical resistance, impedance or reactance in Ohms",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: CurrentName, Power: -2}, {Name: CurrentName, Power: -2},
@@ -440,11 +335,10 @@ var Units = []Unit{
ErForm: "Resistancer", ErForm: "Resistancer",
}, },
{ {
Name: "MagneticFlux", DimensionName: "MagneticFlux",
Receiver: "m", Receiver: "m",
PrintString: "Wb", PrintString: "Wb",
Suffix: "weber", Name: "Weber",
Singular: "Weber",
TypeComment: "MagneticFlux represents a magnetic flux in Weber", TypeComment: "MagneticFlux represents a magnetic flux in Weber",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: CurrentName, Power: -1}, {Name: CurrentName, Power: -1},
@@ -454,11 +348,10 @@ var Units = []Unit{
}, },
}, },
{ {
Name: "MagneticFluxDensity", DimensionName: "MagneticFluxDensity",
Receiver: "m", Receiver: "m",
PrintString: "T", PrintString: "T",
Suffix: "tesla", Name: "Tesla",
Singular: "Tesla",
TypeComment: "MagneticFluxDensity represents a magnetic flux density in Tesla", TypeComment: "MagneticFluxDensity represents a magnetic flux density in Tesla",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: CurrentName, Power: -1}, {Name: CurrentName, Power: -1},
@@ -467,11 +360,10 @@ var Units = []Unit{
}, },
}, },
{ {
Name: "Pressure", DimensionName: "Pressure",
Receiver: "pr", Receiver: "pr",
PrintString: "Pa", PrintString: "Pa",
Suffix: "pascal", Name: "Pascal",
Singular: "Pascal",
TypeComment: "Pressure represents a pressure in Pascals", TypeComment: "Pressure represents a pressure in Pascals",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: LengthName, Power: -1}, {Name: LengthName, Power: -1},
@@ -481,11 +373,10 @@ var Units = []Unit{
ErForm: "Pressurer", ErForm: "Pressurer",
}, },
{ {
Name: "Torque", DimensionName: "Torque",
Receiver: "t", Receiver: "t",
PrintString: "N m", PrintString: "N m",
Suffix: "newtonmetre", Name: "Newtonmetre",
Singular: "Newtonmetre",
TypeComment: "Torque represents a torque in Newton metres", TypeComment: "Torque represents a torque in Newton metres",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: LengthName, Power: 2}, {Name: LengthName, Power: 2},
@@ -495,7 +386,7 @@ var Units = []Unit{
ErForm: "Torquer", ErForm: "Torquer",
}, },
{ {
Name: "Velocity", DimensionName: "Velocity",
Receiver: "v", Receiver: "v",
PrintString: "m s^-1", PrintString: "m s^-1",
TypeComment: "Velocity represents a velocity in metres per second", TypeComment: "Velocity represents a velocity in metres per second",
@@ -505,11 +396,10 @@ var Units = []Unit{
}, },
}, },
{ {
Name: "Voltage", DimensionName: "Voltage",
Receiver: "v", Receiver: "v",
PrintString: "V", PrintString: "V",
Suffix: "volt", Name: "Volt",
Singular: "Volt",
TypeComment: "Voltage represents a voltage in Volts", TypeComment: "Voltage represents a voltage in Volts",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: CurrentName, Power: -1}, {Name: CurrentName, Power: -1},
@@ -520,12 +410,11 @@ var Units = []Unit{
ErForm: "Voltager", ErForm: "Voltager",
}, },
{ {
Name: "Volume", DimensionName: "Volume",
Receiver: "v", Receiver: "v",
Offset: -3, PowerOffset: -3,
PrintString: "m^3", PrintString: "m^3",
Suffix: "litre", Name: "Litre",
Singular: "Litre",
TypeComment: "Volume represents a volume in cubic metres", TypeComment: "Volume represents a volume in cubic metres",
Dimensions: []Dimension{ Dimensions: []Dimension{
{Name: LengthName, Power: 3}, {Name: LengthName, Power: 3},
@@ -557,46 +446,44 @@ import (
) )
// {{.TypeComment}}. // {{.TypeComment}}.
type {{.Name}} float64 type {{.DimensionName}} float64
` `
var header = template.Must(template.New("header").Parse(headerTemplate)) var header = template.Must(template.New("header").Parse(headerTemplate))
const constTemplate = ` const constTemplate = `
const( const {{if .ExtraConstant}}({{end}}
{{$unit := .Unit}} {{.Name}} {{.DimensionName}} = {{if .PowerOffset}} 1e{{.PowerOffset}} {{else}} 1 {{end}}
{{range $unit.ExtraConstant}} {{.Name}} {{$unit.Name}} = {{.Value}} {{$name := .Name}}
{{range .ExtraConstant}} {{.Name}} = {{.Value}}
{{end}} {{end}}
{{$prefixes := .Prefixes}} {{if .ExtraConstant}}){{end}}
{{range $prefixes}} {{if .Name}} {{.Name}}{{$unit.Suffix}} {{else}} {{$unit.Singular}} {{end}} {{$unit.Name}} = {{if .Power}} 1e{{.Power}} {{else}} 1.0 {{end}}
{{end}}
)
` `
var prefix = template.Must(template.New("prefix").Parse(constTemplate)) var prefix = template.Must(template.New("prefix").Parse(constTemplate))
const methodTemplate = ` const methodTemplate = `
// Unit converts the {{.Name}} to a *Unit // Unit converts the {{.DimensionName}} to a *Unit
func ({{.Receiver}} {{.Name}}) Unit() *Unit { func ({{.Receiver}} {{.DimensionName}}) Unit() *Unit {
return New(float64({{.Receiver}}), Dimensions{ return New(float64({{.Receiver}}), Dimensions{
{{range .Dimensions}} {{.Name}}: {{.Power}}, {{range .Dimensions}} {{.Name}}: {{.Power}},
{{end}} {{end}}
}) })
} }
// {{.Name}} allows {{.Name}} to implement a {{if .ErForm}}{{.ErForm}}{{else}}{{.Name}}er{{end}} interface // {{.DimensionName}} allows {{.DimensionName}} to implement a {{if .ErForm}}{{.ErForm}}{{else}}{{.DimensionName}}er{{end}} interface
func ({{.Receiver}} {{.Name}}) {{.Name}}() {{.Name}} { func ({{.Receiver}} {{.DimensionName}}) {{.DimensionName}}() {{.DimensionName}} {
return {{.Receiver}} return {{.Receiver}}
} }
// From converts the unit into the receiver. From returns an // From converts the unit into the receiver. From returns an
// error if there is a mismatch in dimension // error if there is a mismatch in dimension
func ({{.Receiver}} *{{.Name}}) From(u Uniter) error { func ({{.Receiver}} *{{.DimensionName}}) From(u Uniter) error {
if !DimensionsMatch(u, {{if .Singular}}{{.Singular}}{{else}}{{.Name}}(0){{end}}){ if !DimensionsMatch(u, {{if .Name}}{{.Name}}{{else}}{{.DimensionName}}(0){{end}}){
*{{.Receiver}} = {{.Name}}(math.NaN()) *{{.Receiver}} = {{.DimensionName}}(math.NaN())
return errors.New("Dimension mismatch") return errors.New("Dimension mismatch")
} }
*{{.Receiver}} = {{.Name}}(u.Unit().Value()) *{{.Receiver}} = {{.DimensionName}}(u.Unit().Value())
return nil return nil
} }
` `
@@ -604,7 +491,7 @@ func ({{.Receiver}} *{{.Name}}) From(u Uniter) error {
var methods = template.Must(template.New("methods").Parse(methodTemplate)) var methods = template.Must(template.New("methods").Parse(methodTemplate))
const formatTemplate = ` const formatTemplate = `
func ({{.Receiver}} {{.Name}}) Format(fs fmt.State, c rune) { func ({{.Receiver}} {{.DimensionName}}) Format(fs fmt.State, c rune) {
switch c { switch c {
case 'v': case 'v':
if fs.Flag('#') { if fs.Flag('#') {
@@ -636,7 +523,7 @@ func ({{.Receiver}} {{.Name}}) Format(fs fmt.State, c rune) {
var form = template.Must(template.New("format").Parse(formatTemplate)) var form = template.Must(template.New("format").Parse(formatTemplate))
func generate(unit Unit) { func generate(unit Unit) {
lowerName := strings.ToLower(unit.Name) lowerName := strings.ToLower(unit.DimensionName)
filename := lowerName + ".go" filename := lowerName + ".go"
f, err := os.Create(filename) f, err := os.Create(filename)
if err != nil { if err != nil {
@@ -644,43 +531,26 @@ func generate(unit Unit) {
} }
defer f.Close() defer f.Close()
// Need to define new prefixes because text/template can't do math. var buf bytes.Buffer
// Need to do math because kilogram = 1 not 10^3
prefixes := make([]Prefix, len(Prefixes)) err = header.Execute(&buf, unit)
for i, p := range Prefixes {
prefixes[i].Name = p.Name
prefixes[i].Power = p.Power + unit.Offset
}
data := struct {
Prefixes []Prefix
Unit Unit
}{
prefixes,
unit,
}
buf := bytes.NewBuffer(make([]byte, 0))
err = header.Execute(buf, unit)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
if unit.Singular != "" { if unit.Name != "" {
err = prefix.Execute(buf, data) err = prefix.Execute(&buf, unit)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
err = methods.Execute(buf, unit) err = methods.Execute(&buf, unit)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
err = form.Execute(buf, unit) err = form.Execute(&buf, unit)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -688,7 +558,7 @@ func generate(unit Unit) {
b, err := format.Source(buf.Bytes()) b, err := format.Source(buf.Bytes())
if err != nil { if err != nil {
f.Write(buf.Bytes()) // This is here to debug bad format f.Write(buf.Bytes()) // This is here to debug bad format
log.Fatalf("error formatting %q: %s", unit.Name, err) log.Fatalf("error formatting %q: %s", unit.DimensionName, err)
} }
f.Write(b) f.Write(b)
@@ -707,9 +577,9 @@ import (
"testing" "testing"
) )
func Test{{.Name}}Format(t *testing.T) { func Test{{.DimensionName}}Format(t *testing.T) {
for _, test := range []struct{ for _, test := range []struct{
value {{.Name}} value {{.DimensionName}}
format string format string
want string want string
}{ }{
@@ -718,8 +588,8 @@ func Test{{.Name}}Format(t *testing.T) {
{1.23456789, "%20.1v", "{{$s := printf "1 %s" .PrintString}}{{printf "%20s" $s}}"}, {1.23456789, "%20.1v", "{{$s := printf "1 %s" .PrintString}}{{printf "%20s" $s}}"},
{1.23456789, "%20v", "{{$s := printf "1.23456789 %s" .PrintString}}{{printf "%20s" $s}}"}, {1.23456789, "%20v", "{{$s := printf "1.23456789 %s" .PrintString}}{{printf "%20s" $s}}"},
{1.23456789, "%1v", "1.23456789 {{.PrintString}}"}, {1.23456789, "%1v", "1.23456789 {{.PrintString}}"},
{1.23456789, "%#v", "unit.{{.Name}}(1.23456789)"}, {1.23456789, "%#v", "unit.{{.DimensionName}}(1.23456789)"},
{1.23456789, "%s", "%!s(unit.{{.Name}}=1.23456789 {{.PrintString}})"}, {1.23456789, "%s", "%!s(unit.{{.DimensionName}}=1.23456789 {{.PrintString}})"},
} { } {
got := fmt.Sprintf(test.format, test.value) got := fmt.Sprintf(test.format, test.value)
if got != test.want { if got != test.want {
@@ -732,7 +602,7 @@ func Test{{.Name}}Format(t *testing.T) {
var tests = template.Must(template.New("test").Parse(testTemplate)) var tests = template.Must(template.New("test").Parse(testTemplate))
func generateTest(unit Unit) { func generateTest(unit Unit) {
lowerName := strings.ToLower(unit.Name) lowerName := strings.ToLower(unit.DimensionName)
filename := lowerName + "_test.go" filename := lowerName + "_test.go"
f, err := os.Create(filename) f, err := os.Create(filename)
if err != nil { if err != nil {
@@ -740,9 +610,8 @@ func generateTest(unit Unit) {
} }
defer f.Close() defer f.Close()
buf := bytes.NewBuffer(make([]byte, 0)) var buf bytes.Buffer
err = tests.Execute(&buf, unit)
err = tests.Execute(buf, unit)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -750,7 +619,7 @@ func generateTest(unit Unit) {
b, err := format.Source(buf.Bytes()) b, err := format.Source(buf.Bytes())
if err != nil { if err != nil {
f.Write(buf.Bytes()) // This is here to debug bad format. f.Write(buf.Bytes()) // This is here to debug bad format.
log.Fatalf("error formatting test for %q: %s", unit.Name, err) log.Fatalf("error formatting test for %q: %s", unit.DimensionName, err)
} }
f.Write(b) f.Write(b)

View File

@@ -16,29 +16,7 @@ import (
// Inductance represents an electrical inductance in Henry. // Inductance represents an electrical inductance in Henry.
type Inductance float64 type Inductance float64
const ( const Henry Inductance = 1
Yottahenry Inductance = 1e24
Zettahenry Inductance = 1e21
Exahenry Inductance = 1e18
Petahenry Inductance = 1e15
Terahenry Inductance = 1e12
Gigahenry Inductance = 1e9
Megahenry Inductance = 1e6
Kilohenry Inductance = 1e3
Hectohenry Inductance = 1e2
Decahenry Inductance = 1e1
Henry Inductance = 1.0
Decihenry Inductance = 1e-1
Centihenry Inductance = 1e-2
Millihenry Inductance = 1e-3
Microhenry Inductance = 1e-6
Nanohenry Inductance = 1e-9
Picohenry Inductance = 1e-12
Femtohenry Inductance = 1e-15
Attohenry Inductance = 1e-18
Zeptohenry Inductance = 1e-21
Yoctohenry Inductance = 1e-24
)
// Unit converts the Inductance to a *Unit // Unit converts the Inductance to a *Unit
func (i Inductance) Unit() *Unit { func (i Inductance) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Length represents a length in metres. // Length represents a length in metres.
type Length float64 type Length float64
const ( const Metre Length = 1
Yottametre Length = 1e24
Zettametre Length = 1e21
Exametre Length = 1e18
Petametre Length = 1e15
Terametre Length = 1e12
Gigametre Length = 1e9
Megametre Length = 1e6
Kilometre Length = 1e3
Hectometre Length = 1e2
Decametre Length = 1e1
Metre Length = 1.0
Decimetre Length = 1e-1
Centimetre Length = 1e-2
Millimetre Length = 1e-3
Micrometre Length = 1e-6
Nanometre Length = 1e-9
Picometre Length = 1e-12
Femtometre Length = 1e-15
Attometre Length = 1e-18
Zeptometre Length = 1e-21
Yoctometre Length = 1e-24
)
// Unit converts the Length to a *Unit // Unit converts the Length to a *Unit
func (l Length) Unit() *Unit { func (l Length) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Candela represents a luminous intensity in candela. // Candela represents a luminous intensity in candela.
type LuminousIntensity float64 type LuminousIntensity float64
const ( const Candela LuminousIntensity = 1
Yottacandela LuminousIntensity = 1e24
Zettacandela LuminousIntensity = 1e21
Exacandela LuminousIntensity = 1e18
Petacandela LuminousIntensity = 1e15
Teracandela LuminousIntensity = 1e12
Gigacandela LuminousIntensity = 1e9
Megacandela LuminousIntensity = 1e6
Kilocandela LuminousIntensity = 1e3
Hectocandela LuminousIntensity = 1e2
Decacandela LuminousIntensity = 1e1
Candela LuminousIntensity = 1.0
Decicandela LuminousIntensity = 1e-1
Centicandela LuminousIntensity = 1e-2
Millicandela LuminousIntensity = 1e-3
Microcandela LuminousIntensity = 1e-6
Nanocandela LuminousIntensity = 1e-9
Picocandela LuminousIntensity = 1e-12
Femtocandela LuminousIntensity = 1e-15
Attocandela LuminousIntensity = 1e-18
Zeptocandela LuminousIntensity = 1e-21
Yoctocandela LuminousIntensity = 1e-24
)
// Unit converts the LuminousIntensity to a *Unit // Unit converts the LuminousIntensity to a *Unit
func (j LuminousIntensity) Unit() *Unit { func (j LuminousIntensity) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// MagneticFlux represents a magnetic flux in Weber. // MagneticFlux represents a magnetic flux in Weber.
type MagneticFlux float64 type MagneticFlux float64
const ( const Weber MagneticFlux = 1
Yottaweber MagneticFlux = 1e24
Zettaweber MagneticFlux = 1e21
Exaweber MagneticFlux = 1e18
Petaweber MagneticFlux = 1e15
Teraweber MagneticFlux = 1e12
Gigaweber MagneticFlux = 1e9
Megaweber MagneticFlux = 1e6
Kiloweber MagneticFlux = 1e3
Hectoweber MagneticFlux = 1e2
Decaweber MagneticFlux = 1e1
Weber MagneticFlux = 1.0
Deciweber MagneticFlux = 1e-1
Centiweber MagneticFlux = 1e-2
Milliweber MagneticFlux = 1e-3
Microweber MagneticFlux = 1e-6
Nanoweber MagneticFlux = 1e-9
Picoweber MagneticFlux = 1e-12
Femtoweber MagneticFlux = 1e-15
Attoweber MagneticFlux = 1e-18
Zeptoweber MagneticFlux = 1e-21
Yoctoweber MagneticFlux = 1e-24
)
// Unit converts the MagneticFlux to a *Unit // Unit converts the MagneticFlux to a *Unit
func (m MagneticFlux) Unit() *Unit { func (m MagneticFlux) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// MagneticFluxDensity represents a magnetic flux density in Tesla. // MagneticFluxDensity represents a magnetic flux density in Tesla.
type MagneticFluxDensity float64 type MagneticFluxDensity float64
const ( const Tesla MagneticFluxDensity = 1
Yottatesla MagneticFluxDensity = 1e24
Zettatesla MagneticFluxDensity = 1e21
Exatesla MagneticFluxDensity = 1e18
Petatesla MagneticFluxDensity = 1e15
Teratesla MagneticFluxDensity = 1e12
Gigatesla MagneticFluxDensity = 1e9
Megatesla MagneticFluxDensity = 1e6
Kilotesla MagneticFluxDensity = 1e3
Hectotesla MagneticFluxDensity = 1e2
Decatesla MagneticFluxDensity = 1e1
Tesla MagneticFluxDensity = 1.0
Decitesla MagneticFluxDensity = 1e-1
Centitesla MagneticFluxDensity = 1e-2
Millitesla MagneticFluxDensity = 1e-3
Microtesla MagneticFluxDensity = 1e-6
Nanotesla MagneticFluxDensity = 1e-9
Picotesla MagneticFluxDensity = 1e-12
Femtotesla MagneticFluxDensity = 1e-15
Attotesla MagneticFluxDensity = 1e-18
Zeptotesla MagneticFluxDensity = 1e-21
Yoctotesla MagneticFluxDensity = 1e-24
)
// Unit converts the MagneticFluxDensity to a *Unit // Unit converts the MagneticFluxDensity to a *Unit
func (m MagneticFluxDensity) Unit() *Unit { func (m MagneticFluxDensity) Unit() *Unit {

View File

@@ -17,27 +17,9 @@ import (
type Mass float64 type Mass float64
const ( const (
Yottagram Mass = 1e21
Zettagram Mass = 1e18
Exagram Mass = 1e15
Petagram Mass = 1e12
Teragram Mass = 1e9
Gigagram Mass = 1e6
Megagram Mass = 1e3
Kilogram Mass = 1.0
Hectogram Mass = 1e-1
Decagram Mass = 1e-2
Gram Mass = 1e-3 Gram Mass = 1e-3
Decigram Mass = 1e-4
Centigram Mass = 1e-5 Kilogram = Kilo * Gram
Milligram Mass = 1e-6
Microgram Mass = 1e-9
Nanogram Mass = 1e-12
Picogram Mass = 1e-15
Femtogram Mass = 1e-18
Attogram Mass = 1e-21
Zeptogram Mass = 1e-24
Yoctogram Mass = 1e-27
) )
// Unit converts the Mass to a *Unit // Unit converts the Mass to a *Unit

View File

@@ -16,29 +16,7 @@ import (
// Mole represents an amount in moles. // Mole represents an amount in moles.
type Mole float64 type Mole float64
const ( const Mol Mole = 1
Yottamol Mole = 1e24
Zettamol Mole = 1e21
Examol Mole = 1e18
Petamol Mole = 1e15
Teramol Mole = 1e12
Gigamol Mole = 1e9
Megamol Mole = 1e6
Kilomol Mole = 1e3
Hectomol Mole = 1e2
Decamol Mole = 1e1
mol Mole = 1.0
Decimol Mole = 1e-1
Centimol Mole = 1e-2
Millimol Mole = 1e-3
Micromol Mole = 1e-6
Nanomol Mole = 1e-9
Picomol Mole = 1e-12
Femtomol Mole = 1e-15
Attomol Mole = 1e-18
Zeptomol Mole = 1e-21
Yoctomol Mole = 1e-24
)
// Unit converts the Mole to a *Unit // Unit converts the Mole to a *Unit
func (n Mole) Unit() *Unit { func (n Mole) Unit() *Unit {
@@ -55,7 +33,7 @@ func (n Mole) Mole() Mole {
// From converts the unit into the receiver. From returns an // From converts the unit into the receiver. From returns an
// error if there is a mismatch in dimension // error if there is a mismatch in dimension
func (n *Mole) From(u Uniter) error { func (n *Mole) From(u Uniter) error {
if !DimensionsMatch(u, mol) { if !DimensionsMatch(u, Mol) {
*n = Mole(math.NaN()) *n = Mole(math.NaN())
return errors.New("Dimension mismatch") return errors.New("Dimension mismatch")
} }

View File

@@ -16,29 +16,7 @@ import (
// Power represents a power in Watts. // Power represents a power in Watts.
type Power float64 type Power float64
const ( const Watt Power = 1
Yottawatt Power = 1e24
Zettawatt Power = 1e21
Exawatt Power = 1e18
Petawatt Power = 1e15
Terawatt Power = 1e12
Gigawatt Power = 1e9
Megawatt Power = 1e6
Kilowatt Power = 1e3
Hectowatt Power = 1e2
Decawatt Power = 1e1
Watt Power = 1.0
Deciwatt Power = 1e-1
Centiwatt Power = 1e-2
Milliwatt Power = 1e-3
Microwatt Power = 1e-6
Nanowatt Power = 1e-9
Picowatt Power = 1e-12
Femtowatt Power = 1e-15
Attowatt Power = 1e-18
Zeptowatt Power = 1e-21
Yoctowatt Power = 1e-24
)
// Unit converts the Power to a *Unit // Unit converts the Power to a *Unit
func (pw Power) Unit() *Unit { func (pw Power) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Pressure represents a pressure in Pascals. // Pressure represents a pressure in Pascals.
type Pressure float64 type Pressure float64
const ( const Pascal Pressure = 1
Yottapascal Pressure = 1e24
Zettapascal Pressure = 1e21
Exapascal Pressure = 1e18
Petapascal Pressure = 1e15
Terapascal Pressure = 1e12
Gigapascal Pressure = 1e9
Megapascal Pressure = 1e6
Kilopascal Pressure = 1e3
Hectopascal Pressure = 1e2
Decapascal Pressure = 1e1
Pascal Pressure = 1.0
Decipascal Pressure = 1e-1
Centipascal Pressure = 1e-2
Millipascal Pressure = 1e-3
Micropascal Pressure = 1e-6
Nanopascal Pressure = 1e-9
Picopascal Pressure = 1e-12
Femtopascal Pressure = 1e-15
Attopascal Pressure = 1e-18
Zeptopascal Pressure = 1e-21
Yoctopascal Pressure = 1e-24
)
// Unit converts the Pressure to a *Unit // Unit converts the Pressure to a *Unit
func (pr Pressure) Unit() *Unit { func (pr Pressure) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Radioactivity represents a rate of radioactive decay in becquerels. // Radioactivity represents a rate of radioactive decay in becquerels.
type Radioactivity float64 type Radioactivity float64
const ( const Becquerel Radioactivity = 1
Yottabecquerel Radioactivity = 1e24
Zettabecquerel Radioactivity = 1e21
Exabecquerel Radioactivity = 1e18
Petabecquerel Radioactivity = 1e15
Terabecquerel Radioactivity = 1e12
Gigabecquerel Radioactivity = 1e9
Megabecquerel Radioactivity = 1e6
Kilobecquerel Radioactivity = 1e3
Hectobecquerel Radioactivity = 1e2
Decabecquerel Radioactivity = 1e1
Becquerel Radioactivity = 1.0
Decibecquerel Radioactivity = 1e-1
Centibecquerel Radioactivity = 1e-2
Millibecquerel Radioactivity = 1e-3
Microbecquerel Radioactivity = 1e-6
Nanobecquerel Radioactivity = 1e-9
Picobecquerel Radioactivity = 1e-12
Femtobecquerel Radioactivity = 1e-15
Attobecquerel Radioactivity = 1e-18
Zeptobecquerel Radioactivity = 1e-21
Yoctobecquerel Radioactivity = 1e-24
)
// Unit converts the Radioactivity to a *Unit // Unit converts the Radioactivity to a *Unit
func (r Radioactivity) Unit() *Unit { func (r Radioactivity) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Resistance represents an electrical resistance, impedance or reactance in Ohms. // Resistance represents an electrical resistance, impedance or reactance in Ohms.
type Resistance float64 type Resistance float64
const ( const Ohm Resistance = 1
Yottaohm Resistance = 1e24
Zettaohm Resistance = 1e21
Exaohm Resistance = 1e18
Petaohm Resistance = 1e15
Teraohm Resistance = 1e12
Gigaohm Resistance = 1e9
Megaohm Resistance = 1e6
Kiloohm Resistance = 1e3
Hectoohm Resistance = 1e2
Decaohm Resistance = 1e1
Ohm Resistance = 1.0
Deciohm Resistance = 1e-1
Centiohm Resistance = 1e-2
Milliohm Resistance = 1e-3
Microohm Resistance = 1e-6
Nanoohm Resistance = 1e-9
Picoohm Resistance = 1e-12
Femtoohm Resistance = 1e-15
Attoohm Resistance = 1e-18
Zeptoohm Resistance = 1e-21
Yoctoohm Resistance = 1e-24
)
// Unit converts the Resistance to a *Unit // Unit converts the Resistance to a *Unit
func (r Resistance) Unit() *Unit { func (r Resistance) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Temperature represents a temperature in Kelvin. // Temperature represents a temperature in Kelvin.
type Temperature float64 type Temperature float64
const ( const Kelvin Temperature = 1
Yottakelvin Temperature = 1e24
Zettakelvin Temperature = 1e21
Exakelvin Temperature = 1e18
Petakelvin Temperature = 1e15
Terakelvin Temperature = 1e12
Gigakelvin Temperature = 1e9
Megakelvin Temperature = 1e6
Kilokelvin Temperature = 1e3
Hectokelvin Temperature = 1e2
Decakelvin Temperature = 1e1
Kelvin Temperature = 1.0
Decikelvin Temperature = 1e-1
Centikelvin Temperature = 1e-2
Millikelvin Temperature = 1e-3
Microkelvin Temperature = 1e-6
Nanokelvin Temperature = 1e-9
Picokelvin Temperature = 1e-12
Femtokelvin Temperature = 1e-15
Attokelvin Temperature = 1e-18
Zeptokelvin Temperature = 1e-21
Yoctokelvin Temperature = 1e-24
)
// Unit converts the Temperature to a *Unit // Unit converts the Temperature to a *Unit
func (t Temperature) Unit() *Unit { func (t Temperature) Unit() *Unit {

View File

@@ -13,34 +13,14 @@ import (
"unicode/utf8" "unicode/utf8"
) )
// Time represents a time in seconds. // Time represents a duration in seconds.
type Time float64 type Time float64
const ( const (
Hour Time = 3600 Second Time = 1
Minute Time = 60
Yottasecond Time = 1e24 Minute = 60 * Second
Zettasecond Time = 1e21 Hour = 60 * Minute
Exasecond Time = 1e18
Petasecond Time = 1e15
Terasecond Time = 1e12
Gigasecond Time = 1e9
Megasecond Time = 1e6
Kilosecond Time = 1e3
Hectosecond Time = 1e2
Decasecond Time = 1e1
Second Time = 1.0
Decisecond Time = 1e-1
Centisecond Time = 1e-2
Millisecond Time = 1e-3
Microsecond Time = 1e-6
Nanosecond Time = 1e-9
Picosecond Time = 1e-12
Femtosecond Time = 1e-15
Attosecond Time = 1e-18
Zeptosecond Time = 1e-21
Yoctosecond Time = 1e-24
) )
// Unit converts the Time to a *Unit // Unit converts the Time to a *Unit

View File

@@ -16,29 +16,7 @@ import (
// Torque represents a torque in Newton metres. // Torque represents a torque in Newton metres.
type Torque float64 type Torque float64
const ( const Newtonmetre Torque = 1
Yottanewtonmetre Torque = 1e24
Zettanewtonmetre Torque = 1e21
Exanewtonmetre Torque = 1e18
Petanewtonmetre Torque = 1e15
Teranewtonmetre Torque = 1e12
Giganewtonmetre Torque = 1e9
Meganewtonmetre Torque = 1e6
Kilonewtonmetre Torque = 1e3
Hectonewtonmetre Torque = 1e2
Decanewtonmetre Torque = 1e1
Newtonmetre Torque = 1.0
Decinewtonmetre Torque = 1e-1
Centinewtonmetre Torque = 1e-2
Millinewtonmetre Torque = 1e-3
Micronewtonmetre Torque = 1e-6
Nanonewtonmetre Torque = 1e-9
Piconewtonmetre Torque = 1e-12
Femtonewtonmetre Torque = 1e-15
Attonewtonmetre Torque = 1e-18
Zeptonewtonmetre Torque = 1e-21
Yoctonewtonmetre Torque = 1e-24
)
// Unit converts the Torque to a *Unit // Unit converts the Torque to a *Unit
func (t Torque) Unit() *Unit { func (t Torque) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Voltage represents a voltage in Volts. // Voltage represents a voltage in Volts.
type Voltage float64 type Voltage float64
const ( const Volt Voltage = 1
Yottavolt Voltage = 1e24
Zettavolt Voltage = 1e21
Exavolt Voltage = 1e18
Petavolt Voltage = 1e15
Teravolt Voltage = 1e12
Gigavolt Voltage = 1e9
Megavolt Voltage = 1e6
Kilovolt Voltage = 1e3
Hectovolt Voltage = 1e2
Decavolt Voltage = 1e1
Volt Voltage = 1.0
Decivolt Voltage = 1e-1
Centivolt Voltage = 1e-2
Millivolt Voltage = 1e-3
Microvolt Voltage = 1e-6
Nanovolt Voltage = 1e-9
Picovolt Voltage = 1e-12
Femtovolt Voltage = 1e-15
Attovolt Voltage = 1e-18
Zeptovolt Voltage = 1e-21
Yoctovolt Voltage = 1e-24
)
// Unit converts the Voltage to a *Unit // Unit converts the Voltage to a *Unit
func (v Voltage) Unit() *Unit { func (v Voltage) Unit() *Unit {

View File

@@ -16,29 +16,7 @@ import (
// Volume represents a volume in cubic metres. // Volume represents a volume in cubic metres.
type Volume float64 type Volume float64
const ( const Litre Volume = 1e-3
Yottalitre Volume = 1e21
Zettalitre Volume = 1e18
Exalitre Volume = 1e15
Petalitre Volume = 1e12
Teralitre Volume = 1e9
Gigalitre Volume = 1e6
Megalitre Volume = 1e3
Kilolitre Volume = 1.0
Hectolitre Volume = 1e-1
Decalitre Volume = 1e-2
Litre Volume = 1e-3
Decilitre Volume = 1e-4
Centilitre Volume = 1e-5
Millilitre Volume = 1e-6
Microlitre Volume = 1e-9
Nanolitre Volume = 1e-12
Picolitre Volume = 1e-15
Femtolitre Volume = 1e-18
Attolitre Volume = 1e-21
Zeptolitre Volume = 1e-24
Yoctolitre Volume = 1e-27
)
// Unit converts the Volume to a *Unit // Unit converts the Volume to a *Unit
func (v Volume) Unit() *Unit { func (v Volume) Unit() *Unit {