mirror of
https://github.com/gonum/gonum.git
synced 2025-10-21 22:29:30 +08:00
unit: use SI spelling for SI units
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Acceleration represents an acceleration in meters per second squared.
|
// Acceleration represents an acceleration in metres per second squared.
|
||||||
type Acceleration float64
|
type Acceleration float64
|
||||||
|
|
||||||
// Unit converts the Acceleration to a *Unit
|
// Unit converts the Acceleration to a *Unit
|
||||||
|
@@ -13,7 +13,7 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Area represents and area in square meters.
|
// Area represents and area in square metres.
|
||||||
type Area float64
|
type Area float64
|
||||||
|
|
||||||
// Unit converts the Area to a *Unit
|
// Unit converts the Area to a *Unit
|
||||||
|
20
unit/doc.go
20
unit/doc.go
@@ -17,13 +17,13 @@
|
|||||||
// 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, Meter, Pascal, etc.). For example,
|
// expressed in SI base units (Kilogram, Metre, Pascal, etc.). For example,
|
||||||
//
|
//
|
||||||
// height := 1.6 * unit.Meter
|
// height := 1.6 * unit.Metre
|
||||||
// acc := unit.Acceleration(9.8)
|
// acc := unit.Acceleration(9.8)
|
||||||
//
|
//
|
||||||
// creates a variable named 'height' with a value of 1.6 meters, and
|
// creates a variable named 'height' with a value of 1.6 metres, and
|
||||||
// a variable named 'acc' with a value of 9.8 meters per second squared.
|
// a variable named 'acc' with a value of 9.8 metres per second squared.
|
||||||
// These types can be used to add compile-time safety to code. For
|
// These types can be used to add compile-time safety to code. For
|
||||||
// example,
|
// example,
|
||||||
//
|
//
|
||||||
@@ -50,13 +50,13 @@
|
|||||||
// v := float64Volume(p, t) // no error
|
// v := float64Volume(p, t) // no error
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Many types have constants defined representing named SI units (Meter,
|
// Many types have constants defined representing named SI units (Metre,
|
||||||
// Kilogram, etc. ) or SI derived units (Pascal, Hz, etc.). The unit package
|
// Kilogram, etc. ) or SI derived units (Pascal, Hz, etc.). The unit package
|
||||||
// additionally provides untyped constants for SI prefixes, so the following
|
// additionally provides untyped constants for SI prefixes, so the following
|
||||||
// are all equivalent.
|
// are all equivalent.
|
||||||
//
|
//
|
||||||
// l := 0.001 * unit.Meter
|
// l := 0.001 * unit.Metre
|
||||||
// k := 1 * unit.Milli * unit.Meter
|
// k := 1 * unit.Milli * unit.Metre
|
||||||
// j := unit.Length(0.001)
|
// j := unit.Length(0.001)
|
||||||
//
|
//
|
||||||
// Additional SI-derived static units can also be defined by adding types that
|
// Additional SI-derived static units can also be defined by adding types that
|
||||||
@@ -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.Centimeter).Div(1 * unit.Millivolt)
|
// rate.Mul(1 * unit.Centimetre).Div(1 * unit.Millivolt)
|
||||||
//
|
//
|
||||||
// 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,12 +98,12 @@
|
|||||||
// 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.Microliter
|
// const Slide unit.Volume = 0.1 * unit.Microlitre
|
||||||
//
|
//
|
||||||
// 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
|
||||||
// and unit is incapable of catching these mismatches. For example, energy and
|
// and unit is incapable of catching these mismatches. For example, energy and
|
||||||
// torque are both expressed as force times distance (Newton-meters in SI),
|
// torque are both expressed as force times distance (Newton-metres in SI),
|
||||||
// but it is wrong to say that a torque of 10 N·m is the same as 10 J, even
|
// but it is wrong to say that a torque of 10 N·m is the same as 10 J, even
|
||||||
// though the dimensions agree. Despite this, using the defined types to
|
// though the dimensions agree. Despite this, using the defined types to
|
||||||
// represent units can help to catch errors at compile-time. For example,
|
// represent units can help to catch errors at compile-time. For example,
|
||||||
|
@@ -190,9 +190,9 @@ var Units = []Unit{
|
|||||||
Name: "Length",
|
Name: "Length",
|
||||||
Receiver: "l",
|
Receiver: "l",
|
||||||
PrintString: "m",
|
PrintString: "m",
|
||||||
Suffix: "meter",
|
Suffix: "metre",
|
||||||
Singular: "Meter",
|
Singular: "Metre",
|
||||||
TypeComment: "Length represents a length in meters",
|
TypeComment: "Length represents a length in metres",
|
||||||
Dimensions: []Dimension{
|
Dimensions: []Dimension{
|
||||||
{Name: LengthName, Power: 1},
|
{Name: LengthName, Power: 1},
|
||||||
},
|
},
|
||||||
@@ -277,7 +277,7 @@ var Units = []Unit{
|
|||||||
Name: "Acceleration",
|
Name: "Acceleration",
|
||||||
Receiver: "a",
|
Receiver: "a",
|
||||||
PrintString: "m s^-2",
|
PrintString: "m s^-2",
|
||||||
TypeComment: "Acceleration represents an acceleration in meters per second squared",
|
TypeComment: "Acceleration represents an acceleration in metres per second squared",
|
||||||
Dimensions: []Dimension{
|
Dimensions: []Dimension{
|
||||||
{Name: LengthName, Power: 1},
|
{Name: LengthName, Power: 1},
|
||||||
{Name: TimeName, Power: -2},
|
{Name: TimeName, Power: -2},
|
||||||
@@ -287,7 +287,7 @@ var Units = []Unit{
|
|||||||
Name: "Area",
|
Name: "Area",
|
||||||
Receiver: "a",
|
Receiver: "a",
|
||||||
PrintString: "m^2",
|
PrintString: "m^2",
|
||||||
TypeComment: "Area represents and area in square meters",
|
TypeComment: "Area represents and area in square metres",
|
||||||
Dimensions: []Dimension{
|
Dimensions: []Dimension{
|
||||||
{Name: LengthName, Power: 2},
|
{Name: LengthName, Power: 2},
|
||||||
},
|
},
|
||||||
@@ -484,9 +484,9 @@ var Units = []Unit{
|
|||||||
Name: "Torque",
|
Name: "Torque",
|
||||||
Receiver: "t",
|
Receiver: "t",
|
||||||
PrintString: "N m",
|
PrintString: "N m",
|
||||||
Suffix: "newtonmeter",
|
Suffix: "newtonmetre",
|
||||||
Singular: "Newtonmeter",
|
Singular: "Newtonmetre",
|
||||||
TypeComment: "Torque represents a torque in Newton meters",
|
TypeComment: "Torque represents a torque in Newton metres",
|
||||||
Dimensions: []Dimension{
|
Dimensions: []Dimension{
|
||||||
{Name: LengthName, Power: 2},
|
{Name: LengthName, Power: 2},
|
||||||
{Name: MassName, Power: 1},
|
{Name: MassName, Power: 1},
|
||||||
@@ -498,7 +498,7 @@ var Units = []Unit{
|
|||||||
Name: "Velocity",
|
Name: "Velocity",
|
||||||
Receiver: "v",
|
Receiver: "v",
|
||||||
PrintString: "m s^-1",
|
PrintString: "m s^-1",
|
||||||
TypeComment: "Velocity represents a velocity in meters per second",
|
TypeComment: "Velocity represents a velocity in metres per second",
|
||||||
Dimensions: []Dimension{
|
Dimensions: []Dimension{
|
||||||
{Name: LengthName, Power: 1},
|
{Name: LengthName, Power: 1},
|
||||||
{Name: TimeName, Power: -1},
|
{Name: TimeName, Power: -1},
|
||||||
@@ -524,9 +524,9 @@ var Units = []Unit{
|
|||||||
Receiver: "v",
|
Receiver: "v",
|
||||||
Offset: -3,
|
Offset: -3,
|
||||||
PrintString: "m^3",
|
PrintString: "m^3",
|
||||||
Suffix: "liter",
|
Suffix: "litre",
|
||||||
Singular: "Liter",
|
Singular: "Litre",
|
||||||
TypeComment: "Volume represents a volume in cubic meters",
|
TypeComment: "Volume represents a volume in cubic metres",
|
||||||
Dimensions: []Dimension{
|
Dimensions: []Dimension{
|
||||||
{Name: LengthName, Power: 3},
|
{Name: LengthName, Power: 3},
|
||||||
},
|
},
|
||||||
|
@@ -13,31 +13,31 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Length represents a length in meters.
|
// Length represents a length in metres.
|
||||||
type Length float64
|
type Length float64
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Yottameter Length = 1e24
|
Yottametre Length = 1e24
|
||||||
Zettameter Length = 1e21
|
Zettametre Length = 1e21
|
||||||
Exameter Length = 1e18
|
Exametre Length = 1e18
|
||||||
Petameter Length = 1e15
|
Petametre Length = 1e15
|
||||||
Terameter Length = 1e12
|
Terametre Length = 1e12
|
||||||
Gigameter Length = 1e9
|
Gigametre Length = 1e9
|
||||||
Megameter Length = 1e6
|
Megametre Length = 1e6
|
||||||
Kilometer Length = 1e3
|
Kilometre Length = 1e3
|
||||||
Hectometer Length = 1e2
|
Hectometre Length = 1e2
|
||||||
Decameter Length = 1e1
|
Decametre Length = 1e1
|
||||||
Meter Length = 1.0
|
Metre Length = 1.0
|
||||||
Decimeter Length = 1e-1
|
Decimetre Length = 1e-1
|
||||||
Centimeter Length = 1e-2
|
Centimetre Length = 1e-2
|
||||||
Millimeter Length = 1e-3
|
Millimetre Length = 1e-3
|
||||||
Micrometer Length = 1e-6
|
Micrometre Length = 1e-6
|
||||||
Nanometer Length = 1e-9
|
Nanometre Length = 1e-9
|
||||||
Picometer Length = 1e-12
|
Picometre Length = 1e-12
|
||||||
Femtometer Length = 1e-15
|
Femtometre Length = 1e-15
|
||||||
Attometer Length = 1e-18
|
Attometre Length = 1e-18
|
||||||
Zeptometer Length = 1e-21
|
Zeptometre Length = 1e-21
|
||||||
Yoctometer Length = 1e-24
|
Yoctometre Length = 1e-24
|
||||||
)
|
)
|
||||||
|
|
||||||
// Unit converts the Length to a *Unit
|
// Unit converts the Length to a *Unit
|
||||||
@@ -55,7 +55,7 @@ func (l Length) Length() Length {
|
|||||||
// 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 (l *Length) From(u Uniter) error {
|
func (l *Length) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Meter) {
|
if !DimensionsMatch(u, Metre) {
|
||||||
*l = Length(math.NaN())
|
*l = Length(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("Dimension mismatch")
|
||||||
}
|
}
|
||||||
|
@@ -13,31 +13,31 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Torque represents a torque in Newton meters.
|
// Torque represents a torque in Newton metres.
|
||||||
type Torque float64
|
type Torque float64
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Yottanewtonmeter Torque = 1e24
|
Yottanewtonmetre Torque = 1e24
|
||||||
Zettanewtonmeter Torque = 1e21
|
Zettanewtonmetre Torque = 1e21
|
||||||
Exanewtonmeter Torque = 1e18
|
Exanewtonmetre Torque = 1e18
|
||||||
Petanewtonmeter Torque = 1e15
|
Petanewtonmetre Torque = 1e15
|
||||||
Teranewtonmeter Torque = 1e12
|
Teranewtonmetre Torque = 1e12
|
||||||
Giganewtonmeter Torque = 1e9
|
Giganewtonmetre Torque = 1e9
|
||||||
Meganewtonmeter Torque = 1e6
|
Meganewtonmetre Torque = 1e6
|
||||||
Kilonewtonmeter Torque = 1e3
|
Kilonewtonmetre Torque = 1e3
|
||||||
Hectonewtonmeter Torque = 1e2
|
Hectonewtonmetre Torque = 1e2
|
||||||
Decanewtonmeter Torque = 1e1
|
Decanewtonmetre Torque = 1e1
|
||||||
Newtonmeter Torque = 1.0
|
Newtonmetre Torque = 1.0
|
||||||
Decinewtonmeter Torque = 1e-1
|
Decinewtonmetre Torque = 1e-1
|
||||||
Centinewtonmeter Torque = 1e-2
|
Centinewtonmetre Torque = 1e-2
|
||||||
Millinewtonmeter Torque = 1e-3
|
Millinewtonmetre Torque = 1e-3
|
||||||
Micronewtonmeter Torque = 1e-6
|
Micronewtonmetre Torque = 1e-6
|
||||||
Nanonewtonmeter Torque = 1e-9
|
Nanonewtonmetre Torque = 1e-9
|
||||||
Piconewtonmeter Torque = 1e-12
|
Piconewtonmetre Torque = 1e-12
|
||||||
Femtonewtonmeter Torque = 1e-15
|
Femtonewtonmetre Torque = 1e-15
|
||||||
Attonewtonmeter Torque = 1e-18
|
Attonewtonmetre Torque = 1e-18
|
||||||
Zeptonewtonmeter Torque = 1e-21
|
Zeptonewtonmetre Torque = 1e-21
|
||||||
Yoctonewtonmeter Torque = 1e-24
|
Yoctonewtonmetre Torque = 1e-24
|
||||||
)
|
)
|
||||||
|
|
||||||
// Unit converts the Torque to a *Unit
|
// Unit converts the Torque to a *Unit
|
||||||
@@ -57,7 +57,7 @@ func (t Torque) Torque() Torque {
|
|||||||
// 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 (t *Torque) From(u Uniter) error {
|
func (t *Torque) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Newtonmeter) {
|
if !DimensionsMatch(u, Newtonmetre) {
|
||||||
*t = Torque(math.NaN())
|
*t = Torque(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("Dimension mismatch")
|
||||||
}
|
}
|
||||||
|
@@ -254,7 +254,7 @@ type Unit struct {
|
|||||||
|
|
||||||
// New creates a new variable of type Unit which has the value and dimensions
|
// New creates a new variable of type Unit which has the value and dimensions
|
||||||
// specified by the inputs. The built-in dimensions are always in SI units
|
// specified by the inputs. The built-in dimensions are always in SI units
|
||||||
// (meters, kilograms, etc.).
|
// (metres, kilograms, etc.).
|
||||||
func New(value float64, d Dimensions) *Unit {
|
func New(value float64, d Dimensions) *Unit {
|
||||||
return &Unit{
|
return &Unit{
|
||||||
dimensions: d.clone(),
|
dimensions: d.clone(),
|
||||||
|
@@ -13,7 +13,7 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Velocity represents a velocity in meters per second.
|
// Velocity represents a velocity in metres per second.
|
||||||
type Velocity float64
|
type Velocity float64
|
||||||
|
|
||||||
// Unit converts the Velocity to a *Unit
|
// Unit converts the Velocity to a *Unit
|
||||||
|
@@ -13,31 +13,31 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Volume represents a volume in cubic meters.
|
// Volume represents a volume in cubic metres.
|
||||||
type Volume float64
|
type Volume float64
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Yottaliter Volume = 1e21
|
Yottalitre Volume = 1e21
|
||||||
Zettaliter Volume = 1e18
|
Zettalitre Volume = 1e18
|
||||||
Exaliter Volume = 1e15
|
Exalitre Volume = 1e15
|
||||||
Petaliter Volume = 1e12
|
Petalitre Volume = 1e12
|
||||||
Teraliter Volume = 1e9
|
Teralitre Volume = 1e9
|
||||||
Gigaliter Volume = 1e6
|
Gigalitre Volume = 1e6
|
||||||
Megaliter Volume = 1e3
|
Megalitre Volume = 1e3
|
||||||
Kiloliter Volume = 1.0
|
Kilolitre Volume = 1.0
|
||||||
Hectoliter Volume = 1e-1
|
Hectolitre Volume = 1e-1
|
||||||
Decaliter Volume = 1e-2
|
Decalitre Volume = 1e-2
|
||||||
Liter Volume = 1e-3
|
Litre Volume = 1e-3
|
||||||
Deciliter Volume = 1e-4
|
Decilitre Volume = 1e-4
|
||||||
Centiliter Volume = 1e-5
|
Centilitre Volume = 1e-5
|
||||||
Milliliter Volume = 1e-6
|
Millilitre Volume = 1e-6
|
||||||
Microliter Volume = 1e-9
|
Microlitre Volume = 1e-9
|
||||||
Nanoliter Volume = 1e-12
|
Nanolitre Volume = 1e-12
|
||||||
Picoliter Volume = 1e-15
|
Picolitre Volume = 1e-15
|
||||||
Femtoliter Volume = 1e-18
|
Femtolitre Volume = 1e-18
|
||||||
Attoliter Volume = 1e-21
|
Attolitre Volume = 1e-21
|
||||||
Zeptoliter Volume = 1e-24
|
Zeptolitre Volume = 1e-24
|
||||||
Yoctoliter Volume = 1e-27
|
Yoctolitre Volume = 1e-27
|
||||||
)
|
)
|
||||||
|
|
||||||
// Unit converts the Volume to a *Unit
|
// Unit converts the Volume to a *Unit
|
||||||
@@ -55,7 +55,7 @@ func (v Volume) Volume() Volume {
|
|||||||
// 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 (v *Volume) From(u Uniter) error {
|
func (v *Volume) From(u Uniter) error {
|
||||||
if !DimensionsMatch(u, Liter) {
|
if !DimensionsMatch(u, Litre) {
|
||||||
*v = Volume(math.NaN())
|
*v = Volume(math.NaN())
|
||||||
return errors.New("Dimension mismatch")
|
return errors.New("Dimension mismatch")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user