mirror of
https://github.com/gonum/gonum.git
synced 2025-10-05 15:16:59 +08:00
unit: remove explicitly prefixed constants
This commit is contained in:
@@ -16,29 +16,7 @@ import (
|
||||
// AbsorbedRadioactiveDose is a measure of absorbed dose of ionizing radiation in grays.
|
||||
type AbsorbedRadioactiveDose float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Gray AbsorbedRadioactiveDose = 1
|
||||
|
||||
// Unit converts the AbsorbedRadioactiveDose to a *Unit
|
||||
func (a AbsorbedRadioactiveDose) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Angle represents an angle in radians.
|
||||
type Angle float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Rad Angle = 1
|
||||
|
||||
// Unit converts the Angle to a *Unit
|
||||
func (a Angle) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Capacitance represents an electrical capacitance in Farads.
|
||||
type Capacitance float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Farad Capacitance = 1
|
||||
|
||||
// Unit converts the Capacitance to a *Unit
|
||||
func (cp Capacitance) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Charge represents an electric charge in Coulombs.
|
||||
type Charge float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Coulomb Charge = 1
|
||||
|
||||
// Unit converts the Charge to a *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
|
||||
// error if there is a mismatch in dimension
|
||||
func (ch *Charge) From(u Uniter) error {
|
||||
if !DimensionsMatch(u, coulomb) {
|
||||
if !DimensionsMatch(u, Coulomb) {
|
||||
*ch = Charge(math.NaN())
|
||||
return errors.New("Dimension mismatch")
|
||||
}
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Conductance represents an electrical conductance in Siemens.
|
||||
type Conductance float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Siemens Conductance = 1
|
||||
|
||||
// Unit converts the Conductance to a *Unit
|
||||
func (co Conductance) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Current represents a current in Amperes.
|
||||
type Current float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Ampere Current = 1
|
||||
|
||||
// Unit converts the Current to a *Unit
|
||||
func (i Current) Unit() *Unit {
|
||||
|
@@ -17,7 +17,7 @@
|
||||
// unit or a common combination of base units, named for the physical quantity
|
||||
// it represents (Length, Mass, Pressure, etc.). Each type is defined from
|
||||
// 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
|
||||
// acc := unit.Acceleration(9.8)
|
||||
@@ -33,7 +33,7 @@
|
||||
//
|
||||
// func main(){
|
||||
// t := 300 * unit.Kelvin
|
||||
// p := 500 * unit.Kilopascal
|
||||
// p := 500 * unit.Kilo * unit.Pascal
|
||||
// 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
|
||||
// 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
|
||||
// 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,
|
||||
// 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.
|
||||
// Different physical ideas are sometimes expressed with the same dimensions
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Energy represents a quantity of energy in Joules.
|
||||
type Energy float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Joule Energy = 1
|
||||
|
||||
// Unit converts the Energy to a *Unit
|
||||
func (e Energy) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// EquivalentRadioactiveDose is a measure of equivalent dose of ionizing radiation in sieverts.
|
||||
type EquivalentRadioactiveDose float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Sievert EquivalentRadioactiveDose = 1
|
||||
|
||||
// Unit converts the EquivalentRadioactiveDose to a *Unit
|
||||
func (a EquivalentRadioactiveDose) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Force represents a force in Newtons.
|
||||
type Force float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Newton Force = 1
|
||||
|
||||
// Unit converts the Force to a *Unit
|
||||
func (f Force) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Frequency represents a frequency in Hertz.
|
||||
type Frequency float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Hertz Frequency = 1
|
||||
|
||||
// Unit converts the Frequency to a *Unit
|
||||
func (f Frequency) Unit() *Unit {
|
||||
|
@@ -18,16 +18,15 @@ import (
|
||||
)
|
||||
|
||||
type Unit struct {
|
||||
Name string
|
||||
DimensionName 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)
|
||||
ExtraConstant []Constant
|
||||
Suffix string
|
||||
Singular string
|
||||
Name string
|
||||
TypeComment string // Text to comment the type
|
||||
Dimensions []Dimension
|
||||
ErForm string //For Xxxer interface
|
||||
ErForm string // For Xxxer interface
|
||||
}
|
||||
|
||||
type Dimension struct {
|
||||
@@ -75,184 +74,92 @@ type Prefix struct {
|
||||
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{
|
||||
// Base units.
|
||||
{
|
||||
Name: "Angle",
|
||||
Receiver: "a",
|
||||
PrintString: "rad",
|
||||
Suffix: "rad",
|
||||
Singular: "Rad",
|
||||
TypeComment: "Angle represents an angle in radians",
|
||||
DimensionName: "Angle",
|
||||
Receiver: "a",
|
||||
PrintString: "rad",
|
||||
Name: "Rad",
|
||||
TypeComment: "Angle represents an angle in radians",
|
||||
Dimensions: []Dimension{
|
||||
{Name: AngleName, Power: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Current",
|
||||
Receiver: "i",
|
||||
PrintString: "A",
|
||||
Suffix: "ampere",
|
||||
Singular: "Ampere",
|
||||
TypeComment: "Current represents a current in Amperes",
|
||||
DimensionName: "Current",
|
||||
Receiver: "i",
|
||||
PrintString: "A",
|
||||
Name: "Ampere",
|
||||
TypeComment: "Current represents a current in Amperes",
|
||||
Dimensions: []Dimension{
|
||||
{Name: CurrentName, Power: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Length",
|
||||
Receiver: "l",
|
||||
PrintString: "m",
|
||||
Suffix: "metre",
|
||||
Singular: "Metre",
|
||||
TypeComment: "Length represents a length in metres",
|
||||
DimensionName: "Length",
|
||||
Receiver: "l",
|
||||
PrintString: "m",
|
||||
Name: "Metre",
|
||||
TypeComment: "Length represents a length in metres",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "LuminousIntensity",
|
||||
Receiver: "j",
|
||||
PrintString: "cd",
|
||||
Suffix: "candela",
|
||||
Singular: "Candela",
|
||||
TypeComment: "Candela represents a luminous intensity in candela",
|
||||
DimensionName: "LuminousIntensity",
|
||||
Receiver: "j",
|
||||
PrintString: "cd",
|
||||
Name: "Candela",
|
||||
TypeComment: "Candela represents a luminous intensity in candela",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LuminousIntensityName, Power: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Mass",
|
||||
Receiver: "m",
|
||||
Offset: -3,
|
||||
PrintString: "kg",
|
||||
Suffix: "gram",
|
||||
Singular: "Gram",
|
||||
TypeComment: "Mass represents a mass in kilograms",
|
||||
DimensionName: "Mass",
|
||||
Receiver: "m",
|
||||
PowerOffset: -3,
|
||||
PrintString: "kg",
|
||||
Name: "Gram",
|
||||
TypeComment: "Mass represents a mass in kilograms",
|
||||
ExtraConstant: []Constant{
|
||||
{Name: "Kilogram", Value: "Kilo * Gram"},
|
||||
},
|
||||
Dimensions: []Dimension{
|
||||
{Name: MassName, Power: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Mole",
|
||||
Receiver: "n",
|
||||
PrintString: "mol",
|
||||
Suffix: "mol",
|
||||
Singular: "mol",
|
||||
TypeComment: "Mole represents an amount in moles",
|
||||
DimensionName: "Mole",
|
||||
Receiver: "n",
|
||||
PrintString: "mol",
|
||||
Name: "Mol",
|
||||
TypeComment: "Mole represents an amount in moles",
|
||||
Dimensions: []Dimension{
|
||||
{Name: MoleName, Power: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Temperature",
|
||||
Receiver: "t",
|
||||
PrintString: "K",
|
||||
Suffix: "kelvin",
|
||||
Singular: "Kelvin",
|
||||
TypeComment: "Temperature represents a temperature in Kelvin",
|
||||
DimensionName: "Temperature",
|
||||
Receiver: "t",
|
||||
PrintString: "K",
|
||||
Name: "Kelvin",
|
||||
TypeComment: "Temperature represents a temperature in Kelvin",
|
||||
Dimensions: []Dimension{
|
||||
{Name: TemperatureName, Power: 1},
|
||||
},
|
||||
ErForm: "Temperaturer",
|
||||
},
|
||||
{
|
||||
Name: "Time",
|
||||
Receiver: "t",
|
||||
PrintString: "s",
|
||||
Suffix: "second",
|
||||
Singular: "Second",
|
||||
TypeComment: "Time represents a time in seconds",
|
||||
DimensionName: "Time",
|
||||
Receiver: "t",
|
||||
PrintString: "s",
|
||||
Name: "Second",
|
||||
TypeComment: "Time represents a duration in seconds",
|
||||
ExtraConstant: []Constant{
|
||||
{Name: "Hour", Value: "3600"},
|
||||
{Name: "Minute", Value: "60"},
|
||||
{Name: "Minute", Value: "60 * Second"},
|
||||
{Name: "Hour", Value: "60 * Minute"},
|
||||
},
|
||||
Dimensions: []Dimension{
|
||||
{Name: TimeName, Power: 1},
|
||||
@@ -262,54 +169,51 @@ var Units = []Unit{
|
||||
|
||||
// Derived units.
|
||||
{
|
||||
Name: "AbsorbedRadioactiveDose",
|
||||
Receiver: "a",
|
||||
PrintString: "Gy",
|
||||
Suffix: "gray",
|
||||
Singular: "Gray",
|
||||
TypeComment: "AbsorbedRadioactiveDose is a measure of absorbed dose of ionizing radiation in grays",
|
||||
DimensionName: "AbsorbedRadioactiveDose",
|
||||
Receiver: "a",
|
||||
PrintString: "Gy",
|
||||
Name: "Gray",
|
||||
TypeComment: "AbsorbedRadioactiveDose is a measure of absorbed dose of ionizing radiation in grays",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 2},
|
||||
{Name: TimeName, Power: -2},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Acceleration",
|
||||
Receiver: "a",
|
||||
PrintString: "m s^-2",
|
||||
TypeComment: "Acceleration represents an acceleration in metres per second squared",
|
||||
DimensionName: "Acceleration",
|
||||
Receiver: "a",
|
||||
PrintString: "m s^-2",
|
||||
TypeComment: "Acceleration represents an acceleration in metres per second squared",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 1},
|
||||
{Name: TimeName, Power: -2},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Area",
|
||||
Receiver: "a",
|
||||
PrintString: "m^2",
|
||||
TypeComment: "Area represents and area in square metres",
|
||||
DimensionName: "Area",
|
||||
Receiver: "a",
|
||||
PrintString: "m^2",
|
||||
TypeComment: "Area represents and area in square metres",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 2},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Radioactivity",
|
||||
Receiver: "r",
|
||||
PrintString: "Bq",
|
||||
Suffix: "becquerel",
|
||||
Singular: "Becquerel",
|
||||
TypeComment: "Radioactivity represents a rate of radioactive decay in becquerels",
|
||||
DimensionName: "Radioactivity",
|
||||
Receiver: "r",
|
||||
PrintString: "Bq",
|
||||
Name: "Becquerel",
|
||||
TypeComment: "Radioactivity represents a rate of radioactive decay in becquerels",
|
||||
Dimensions: []Dimension{
|
||||
{Name: TimeName, Power: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Capacitance",
|
||||
Receiver: "cp",
|
||||
PrintString: "F",
|
||||
Suffix: "farad",
|
||||
Singular: "Farad",
|
||||
TypeComment: "Capacitance represents an electrical capacitance in Farads",
|
||||
DimensionName: "Capacitance",
|
||||
Receiver: "cp",
|
||||
PrintString: "F",
|
||||
Name: "Farad",
|
||||
TypeComment: "Capacitance represents an electrical capacitance in Farads",
|
||||
Dimensions: []Dimension{
|
||||
{Name: CurrentName, Power: 2},
|
||||
{Name: LengthName, Power: -2},
|
||||
@@ -319,12 +223,11 @@ var Units = []Unit{
|
||||
ErForm: "Capacitancer",
|
||||
},
|
||||
{
|
||||
Name: "Charge",
|
||||
Receiver: "ch",
|
||||
PrintString: "C",
|
||||
Suffix: "coulomb",
|
||||
Singular: "coulomb",
|
||||
TypeComment: "Charge represents an electric charge in Coulombs",
|
||||
DimensionName: "Charge",
|
||||
Receiver: "ch",
|
||||
PrintString: "C",
|
||||
Name: "Coulomb",
|
||||
TypeComment: "Charge represents an electric charge in Coulombs",
|
||||
Dimensions: []Dimension{
|
||||
{Name: CurrentName, Power: 1},
|
||||
{Name: TimeName, Power: 1},
|
||||
@@ -332,12 +235,11 @@ var Units = []Unit{
|
||||
ErForm: "Charger",
|
||||
},
|
||||
{
|
||||
Name: "Conductance",
|
||||
Receiver: "co",
|
||||
PrintString: "S",
|
||||
Suffix: "siemens",
|
||||
Singular: "Siemens",
|
||||
TypeComment: "Conductance represents an electrical conductance in Siemens",
|
||||
DimensionName: "Conductance",
|
||||
Receiver: "co",
|
||||
PrintString: "S",
|
||||
Name: "Siemens",
|
||||
TypeComment: "Conductance represents an electrical conductance in Siemens",
|
||||
Dimensions: []Dimension{
|
||||
{Name: CurrentName, Power: 2},
|
||||
{Name: LengthName, Power: -2},
|
||||
@@ -347,24 +249,22 @@ var Units = []Unit{
|
||||
ErForm: "Conductancer",
|
||||
},
|
||||
{
|
||||
Name: "EquivalentRadioactiveDose",
|
||||
Receiver: "a",
|
||||
PrintString: "Sy",
|
||||
Suffix: "sievert",
|
||||
Singular: "Sievert",
|
||||
TypeComment: "EquivalentRadioactiveDose is a measure of equivalent dose of ionizing radiation in sieverts",
|
||||
DimensionName: "EquivalentRadioactiveDose",
|
||||
Receiver: "a",
|
||||
PrintString: "Sy",
|
||||
Name: "Sievert",
|
||||
TypeComment: "EquivalentRadioactiveDose is a measure of equivalent dose of ionizing radiation in sieverts",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 2},
|
||||
{Name: TimeName, Power: -2},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Energy",
|
||||
Receiver: "e",
|
||||
PrintString: "J",
|
||||
Suffix: "joule",
|
||||
Singular: "Joule",
|
||||
TypeComment: "Energy represents a quantity of energy in Joules",
|
||||
DimensionName: "Energy",
|
||||
Receiver: "e",
|
||||
PrintString: "J",
|
||||
Name: "Joule",
|
||||
TypeComment: "Energy represents a quantity of energy in Joules",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 2},
|
||||
{Name: MassName, Power: 1},
|
||||
@@ -372,23 +272,21 @@ var Units = []Unit{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Frequency",
|
||||
Receiver: "f",
|
||||
PrintString: "Hz",
|
||||
Suffix: "hertz",
|
||||
Singular: "Hertz",
|
||||
TypeComment: "Frequency represents a frequency in Hertz",
|
||||
DimensionName: "Frequency",
|
||||
Receiver: "f",
|
||||
PrintString: "Hz",
|
||||
Name: "Hertz",
|
||||
TypeComment: "Frequency represents a frequency in Hertz",
|
||||
Dimensions: []Dimension{
|
||||
{Name: TimeName, Power: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Force",
|
||||
Receiver: "f",
|
||||
PrintString: "N",
|
||||
Suffix: "newton",
|
||||
Singular: "Newton",
|
||||
TypeComment: "Force represents a force in Newtons",
|
||||
DimensionName: "Force",
|
||||
Receiver: "f",
|
||||
PrintString: "N",
|
||||
Name: "Newton",
|
||||
TypeComment: "Force represents a force in Newtons",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 1},
|
||||
{Name: MassName, Power: 1},
|
||||
@@ -397,12 +295,11 @@ var Units = []Unit{
|
||||
ErForm: "Forcer",
|
||||
},
|
||||
{
|
||||
Name: "Inductance",
|
||||
Receiver: "i",
|
||||
PrintString: "H",
|
||||
Suffix: "henry",
|
||||
Singular: "Henry",
|
||||
TypeComment: "Inductance represents an electrical inductance in Henry",
|
||||
DimensionName: "Inductance",
|
||||
Receiver: "i",
|
||||
PrintString: "H",
|
||||
Name: "Henry",
|
||||
TypeComment: "Inductance represents an electrical inductance in Henry",
|
||||
Dimensions: []Dimension{
|
||||
{Name: CurrentName, Power: -2},
|
||||
{Name: LengthName, Power: 2},
|
||||
@@ -412,12 +309,11 @@ var Units = []Unit{
|
||||
ErForm: "Inductancer",
|
||||
},
|
||||
{
|
||||
Name: "Power",
|
||||
Receiver: "pw",
|
||||
PrintString: "W",
|
||||
Suffix: "watt",
|
||||
Singular: "Watt",
|
||||
TypeComment: "Power represents a power in Watts",
|
||||
DimensionName: "Power",
|
||||
Receiver: "pw",
|
||||
PrintString: "W",
|
||||
Name: "Watt",
|
||||
TypeComment: "Power represents a power in Watts",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 2},
|
||||
{Name: MassName, Power: 1},
|
||||
@@ -425,12 +321,11 @@ var Units = []Unit{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Resistance",
|
||||
Receiver: "r",
|
||||
PrintString: "Ω",
|
||||
Suffix: "ohm",
|
||||
Singular: "Ohm",
|
||||
TypeComment: "Resistance represents an electrical resistance, impedance or reactance in Ohms",
|
||||
DimensionName: "Resistance",
|
||||
Receiver: "r",
|
||||
PrintString: "Ω",
|
||||
Name: "Ohm",
|
||||
TypeComment: "Resistance represents an electrical resistance, impedance or reactance in Ohms",
|
||||
Dimensions: []Dimension{
|
||||
{Name: CurrentName, Power: -2},
|
||||
{Name: LengthName, Power: 2},
|
||||
@@ -440,12 +335,11 @@ var Units = []Unit{
|
||||
ErForm: "Resistancer",
|
||||
},
|
||||
{
|
||||
Name: "MagneticFlux",
|
||||
Receiver: "m",
|
||||
PrintString: "Wb",
|
||||
Suffix: "weber",
|
||||
Singular: "Weber",
|
||||
TypeComment: "MagneticFlux represents a magnetic flux in Weber",
|
||||
DimensionName: "MagneticFlux",
|
||||
Receiver: "m",
|
||||
PrintString: "Wb",
|
||||
Name: "Weber",
|
||||
TypeComment: "MagneticFlux represents a magnetic flux in Weber",
|
||||
Dimensions: []Dimension{
|
||||
{Name: CurrentName, Power: -1},
|
||||
{Name: LengthName, Power: 2},
|
||||
@@ -454,12 +348,11 @@ var Units = []Unit{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "MagneticFluxDensity",
|
||||
Receiver: "m",
|
||||
PrintString: "T",
|
||||
Suffix: "tesla",
|
||||
Singular: "Tesla",
|
||||
TypeComment: "MagneticFluxDensity represents a magnetic flux density in Tesla",
|
||||
DimensionName: "MagneticFluxDensity",
|
||||
Receiver: "m",
|
||||
PrintString: "T",
|
||||
Name: "Tesla",
|
||||
TypeComment: "MagneticFluxDensity represents a magnetic flux density in Tesla",
|
||||
Dimensions: []Dimension{
|
||||
{Name: CurrentName, Power: -1},
|
||||
{Name: MassName, Power: 1},
|
||||
@@ -467,12 +360,11 @@ var Units = []Unit{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Pressure",
|
||||
Receiver: "pr",
|
||||
PrintString: "Pa",
|
||||
Suffix: "pascal",
|
||||
Singular: "Pascal",
|
||||
TypeComment: "Pressure represents a pressure in Pascals",
|
||||
DimensionName: "Pressure",
|
||||
Receiver: "pr",
|
||||
PrintString: "Pa",
|
||||
Name: "Pascal",
|
||||
TypeComment: "Pressure represents a pressure in Pascals",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: -1},
|
||||
{Name: MassName, Power: 1},
|
||||
@@ -481,12 +373,11 @@ var Units = []Unit{
|
||||
ErForm: "Pressurer",
|
||||
},
|
||||
{
|
||||
Name: "Torque",
|
||||
Receiver: "t",
|
||||
PrintString: "N m",
|
||||
Suffix: "newtonmetre",
|
||||
Singular: "Newtonmetre",
|
||||
TypeComment: "Torque represents a torque in Newton metres",
|
||||
DimensionName: "Torque",
|
||||
Receiver: "t",
|
||||
PrintString: "N m",
|
||||
Name: "Newtonmetre",
|
||||
TypeComment: "Torque represents a torque in Newton metres",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 2},
|
||||
{Name: MassName, Power: 1},
|
||||
@@ -495,22 +386,21 @@ var Units = []Unit{
|
||||
ErForm: "Torquer",
|
||||
},
|
||||
{
|
||||
Name: "Velocity",
|
||||
Receiver: "v",
|
||||
PrintString: "m s^-1",
|
||||
TypeComment: "Velocity represents a velocity in metres per second",
|
||||
DimensionName: "Velocity",
|
||||
Receiver: "v",
|
||||
PrintString: "m s^-1",
|
||||
TypeComment: "Velocity represents a velocity in metres per second",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 1},
|
||||
{Name: TimeName, Power: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Voltage",
|
||||
Receiver: "v",
|
||||
PrintString: "V",
|
||||
Suffix: "volt",
|
||||
Singular: "Volt",
|
||||
TypeComment: "Voltage represents a voltage in Volts",
|
||||
DimensionName: "Voltage",
|
||||
Receiver: "v",
|
||||
PrintString: "V",
|
||||
Name: "Volt",
|
||||
TypeComment: "Voltage represents a voltage in Volts",
|
||||
Dimensions: []Dimension{
|
||||
{Name: CurrentName, Power: -1},
|
||||
{Name: LengthName, Power: 2},
|
||||
@@ -520,13 +410,12 @@ var Units = []Unit{
|
||||
ErForm: "Voltager",
|
||||
},
|
||||
{
|
||||
Name: "Volume",
|
||||
Receiver: "v",
|
||||
Offset: -3,
|
||||
PrintString: "m^3",
|
||||
Suffix: "litre",
|
||||
Singular: "Litre",
|
||||
TypeComment: "Volume represents a volume in cubic metres",
|
||||
DimensionName: "Volume",
|
||||
Receiver: "v",
|
||||
PowerOffset: -3,
|
||||
PrintString: "m^3",
|
||||
Name: "Litre",
|
||||
TypeComment: "Volume represents a volume in cubic metres",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 3},
|
||||
},
|
||||
@@ -557,46 +446,44 @@ import (
|
||||
)
|
||||
|
||||
// {{.TypeComment}}.
|
||||
type {{.Name}} float64
|
||||
type {{.DimensionName}} float64
|
||||
`
|
||||
|
||||
var header = template.Must(template.New("header").Parse(headerTemplate))
|
||||
|
||||
const constTemplate = `
|
||||
const(
|
||||
{{$unit := .Unit}}
|
||||
{{range $unit.ExtraConstant}} {{.Name}} {{$unit.Name}} = {{.Value}}
|
||||
const {{if .ExtraConstant}}({{end}}
|
||||
{{.Name}} {{.DimensionName}} = {{if .PowerOffset}} 1e{{.PowerOffset}} {{else}} 1 {{end}}
|
||||
{{$name := .Name}}
|
||||
{{range .ExtraConstant}} {{.Name}} = {{.Value}}
|
||||
{{end}}
|
||||
{{$prefixes := .Prefixes}}
|
||||
{{range $prefixes}} {{if .Name}} {{.Name}}{{$unit.Suffix}} {{else}} {{$unit.Singular}} {{end}} {{$unit.Name}} = {{if .Power}} 1e{{.Power}} {{else}} 1.0 {{end}}
|
||||
{{end}}
|
||||
)
|
||||
{{if .ExtraConstant}}){{end}}
|
||||
`
|
||||
|
||||
var prefix = template.Must(template.New("prefix").Parse(constTemplate))
|
||||
|
||||
const methodTemplate = `
|
||||
// Unit converts the {{.Name}} to a *Unit
|
||||
func ({{.Receiver}} {{.Name}}) Unit() *Unit {
|
||||
// Unit converts the {{.DimensionName}} to a *Unit
|
||||
func ({{.Receiver}} {{.DimensionName}}) Unit() *Unit {
|
||||
return New(float64({{.Receiver}}), Dimensions{
|
||||
{{range .Dimensions}} {{.Name}}: {{.Power}},
|
||||
{{end}}
|
||||
})
|
||||
}
|
||||
|
||||
// {{.Name}} allows {{.Name}} to implement a {{if .ErForm}}{{.ErForm}}{{else}}{{.Name}}er{{end}} interface
|
||||
func ({{.Receiver}} {{.Name}}) {{.Name}}() {{.Name}} {
|
||||
// {{.DimensionName}} allows {{.DimensionName}} to implement a {{if .ErForm}}{{.ErForm}}{{else}}{{.DimensionName}}er{{end}} interface
|
||||
func ({{.Receiver}} {{.DimensionName}}) {{.DimensionName}}() {{.DimensionName}} {
|
||||
return {{.Receiver}}
|
||||
}
|
||||
|
||||
// From converts the unit into the receiver. From returns an
|
||||
// error if there is a mismatch in dimension
|
||||
func ({{.Receiver}} *{{.Name}}) From(u Uniter) error {
|
||||
if !DimensionsMatch(u, {{if .Singular}}{{.Singular}}{{else}}{{.Name}}(0){{end}}){
|
||||
*{{.Receiver}} = {{.Name}}(math.NaN())
|
||||
func ({{.Receiver}} *{{.DimensionName}}) From(u Uniter) error {
|
||||
if !DimensionsMatch(u, {{if .Name}}{{.Name}}{{else}}{{.DimensionName}}(0){{end}}){
|
||||
*{{.Receiver}} = {{.DimensionName}}(math.NaN())
|
||||
return errors.New("Dimension mismatch")
|
||||
}
|
||||
*{{.Receiver}} = {{.Name}}(u.Unit().Value())
|
||||
*{{.Receiver}} = {{.DimensionName}}(u.Unit().Value())
|
||||
return nil
|
||||
}
|
||||
`
|
||||
@@ -604,7 +491,7 @@ func ({{.Receiver}} *{{.Name}}) From(u Uniter) error {
|
||||
var methods = template.Must(template.New("methods").Parse(methodTemplate))
|
||||
|
||||
const formatTemplate = `
|
||||
func ({{.Receiver}} {{.Name}}) Format(fs fmt.State, c rune) {
|
||||
func ({{.Receiver}} {{.DimensionName}}) Format(fs fmt.State, c rune) {
|
||||
switch c {
|
||||
case 'v':
|
||||
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))
|
||||
|
||||
func generate(unit Unit) {
|
||||
lowerName := strings.ToLower(unit.Name)
|
||||
lowerName := strings.ToLower(unit.DimensionName)
|
||||
filename := lowerName + ".go"
|
||||
f, err := os.Create(filename)
|
||||
if err != nil {
|
||||
@@ -644,43 +531,26 @@ func generate(unit Unit) {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Need to define new prefixes because text/template can't do math.
|
||||
// Need to do math because kilogram = 1 not 10^3
|
||||
var buf bytes.Buffer
|
||||
|
||||
prefixes := make([]Prefix, len(Prefixes))
|
||||
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)
|
||||
err = header.Execute(&buf, unit)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if unit.Singular != "" {
|
||||
err = prefix.Execute(buf, data)
|
||||
if unit.Name != "" {
|
||||
err = prefix.Execute(&buf, unit)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
err = methods.Execute(buf, unit)
|
||||
err = methods.Execute(&buf, unit)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = form.Execute(buf, unit)
|
||||
err = form.Execute(&buf, unit)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -688,7 +558,7 @@ func generate(unit Unit) {
|
||||
b, err := format.Source(buf.Bytes())
|
||||
if err != nil {
|
||||
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)
|
||||
@@ -707,9 +577,9 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test{{.Name}}Format(t *testing.T) {
|
||||
func Test{{.DimensionName}}Format(t *testing.T) {
|
||||
for _, test := range []struct{
|
||||
value {{.Name}}
|
||||
value {{.DimensionName}}
|
||||
format 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, "%20v", "{{$s := printf "1.23456789 %s" .PrintString}}{{printf "%20s" $s}}"},
|
||||
{1.23456789, "%1v", "1.23456789 {{.PrintString}}"},
|
||||
{1.23456789, "%#v", "unit.{{.Name}}(1.23456789)"},
|
||||
{1.23456789, "%s", "%!s(unit.{{.Name}}=1.23456789 {{.PrintString}})"},
|
||||
{1.23456789, "%#v", "unit.{{.DimensionName}}(1.23456789)"},
|
||||
{1.23456789, "%s", "%!s(unit.{{.DimensionName}}=1.23456789 {{.PrintString}})"},
|
||||
} {
|
||||
got := fmt.Sprintf(test.format, test.value)
|
||||
if got != test.want {
|
||||
@@ -732,7 +602,7 @@ func Test{{.Name}}Format(t *testing.T) {
|
||||
var tests = template.Must(template.New("test").Parse(testTemplate))
|
||||
|
||||
func generateTest(unit Unit) {
|
||||
lowerName := strings.ToLower(unit.Name)
|
||||
lowerName := strings.ToLower(unit.DimensionName)
|
||||
filename := lowerName + "_test.go"
|
||||
f, err := os.Create(filename)
|
||||
if err != nil {
|
||||
@@ -740,9 +610,8 @@ func generateTest(unit Unit) {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
buf := bytes.NewBuffer(make([]byte, 0))
|
||||
|
||||
err = tests.Execute(buf, unit)
|
||||
var buf bytes.Buffer
|
||||
err = tests.Execute(&buf, unit)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -750,7 +619,7 @@ func generateTest(unit Unit) {
|
||||
b, err := format.Source(buf.Bytes())
|
||||
if err != nil {
|
||||
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)
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Inductance represents an electrical inductance in Henry.
|
||||
type Inductance float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Henry Inductance = 1
|
||||
|
||||
// Unit converts the Inductance to a *Unit
|
||||
func (i Inductance) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Length represents a length in metres.
|
||||
type Length float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Metre Length = 1
|
||||
|
||||
// Unit converts the Length to a *Unit
|
||||
func (l Length) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Candela represents a luminous intensity in candela.
|
||||
type LuminousIntensity float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Candela LuminousIntensity = 1
|
||||
|
||||
// Unit converts the LuminousIntensity to a *Unit
|
||||
func (j LuminousIntensity) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// MagneticFlux represents a magnetic flux in Weber.
|
||||
type MagneticFlux float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Weber MagneticFlux = 1
|
||||
|
||||
// Unit converts the MagneticFlux to a *Unit
|
||||
func (m MagneticFlux) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// MagneticFluxDensity represents a magnetic flux density in Tesla.
|
||||
type MagneticFluxDensity float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Tesla MagneticFluxDensity = 1
|
||||
|
||||
// Unit converts the MagneticFluxDensity to a *Unit
|
||||
func (m MagneticFluxDensity) Unit() *Unit {
|
||||
|
24
unit/mass.go
24
unit/mass.go
@@ -17,27 +17,9 @@ import (
|
||||
type Mass float64
|
||||
|
||||
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
|
||||
Decigram Mass = 1e-4
|
||||
Centigram Mass = 1e-5
|
||||
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
|
||||
Gram Mass = 1e-3
|
||||
|
||||
Kilogram = Kilo * Gram
|
||||
)
|
||||
|
||||
// Unit converts the Mass to a *Unit
|
||||
|
26
unit/mole.go
26
unit/mole.go
@@ -16,29 +16,7 @@ import (
|
||||
// Mole represents an amount in moles.
|
||||
type Mole float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Mol Mole = 1
|
||||
|
||||
// Unit converts the Mole to a *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
|
||||
// error if there is a mismatch in dimension
|
||||
func (n *Mole) From(u Uniter) error {
|
||||
if !DimensionsMatch(u, mol) {
|
||||
if !DimensionsMatch(u, Mol) {
|
||||
*n = Mole(math.NaN())
|
||||
return errors.New("Dimension mismatch")
|
||||
}
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Power represents a power in Watts.
|
||||
type Power float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Watt Power = 1
|
||||
|
||||
// Unit converts the Power to a *Unit
|
||||
func (pw Power) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Pressure represents a pressure in Pascals.
|
||||
type Pressure float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Pascal Pressure = 1
|
||||
|
||||
// Unit converts the Pressure to a *Unit
|
||||
func (pr Pressure) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Radioactivity represents a rate of radioactive decay in becquerels.
|
||||
type Radioactivity float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Becquerel Radioactivity = 1
|
||||
|
||||
// Unit converts the Radioactivity to a *Unit
|
||||
func (r Radioactivity) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Resistance represents an electrical resistance, impedance or reactance in Ohms.
|
||||
type Resistance float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Ohm Resistance = 1
|
||||
|
||||
// Unit converts the Resistance to a *Unit
|
||||
func (r Resistance) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Temperature represents a temperature in Kelvin.
|
||||
type Temperature float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Kelvin Temperature = 1
|
||||
|
||||
// Unit converts the Temperature to a *Unit
|
||||
func (t Temperature) Unit() *Unit {
|
||||
|
28
unit/time.go
28
unit/time.go
@@ -13,34 +13,14 @@ import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Time represents a time in seconds.
|
||||
// Time represents a duration in seconds.
|
||||
type Time float64
|
||||
|
||||
const (
|
||||
Hour Time = 3600
|
||||
Minute Time = 60
|
||||
Second Time = 1
|
||||
|
||||
Yottasecond Time = 1e24
|
||||
Zettasecond Time = 1e21
|
||||
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
|
||||
Minute = 60 * Second
|
||||
Hour = 60 * Minute
|
||||
)
|
||||
|
||||
// Unit converts the Time to a *Unit
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Torque represents a torque in Newton metres.
|
||||
type Torque float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Newtonmetre Torque = 1
|
||||
|
||||
// Unit converts the Torque to a *Unit
|
||||
func (t Torque) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Voltage represents a voltage in Volts.
|
||||
type Voltage float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Volt Voltage = 1
|
||||
|
||||
// Unit converts the Voltage to a *Unit
|
||||
func (v Voltage) Unit() *Unit {
|
||||
|
@@ -16,29 +16,7 @@ import (
|
||||
// Volume represents a volume in cubic metres.
|
||||
type Volume float64
|
||||
|
||||
const (
|
||||
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
|
||||
)
|
||||
const Litre Volume = 1e-3
|
||||
|
||||
// Unit converts the Volume to a *Unit
|
||||
func (v Volume) Unit() *Unit {
|
||||
|
Reference in New Issue
Block a user