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"
|
||||
)
|
||||
|
||||
// Acceleration represents an acceleration in meters per second squared.
|
||||
// Acceleration represents an acceleration in metres per second squared.
|
||||
type Acceleration float64
|
||||
|
||||
// Unit converts the Acceleration to a *Unit
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Area represents and area in square meters.
|
||||
// Area represents and area in square metres.
|
||||
type Area float64
|
||||
|
||||
// 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
|
||||
// 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, 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)
|
||||
//
|
||||
// creates a variable named 'height' with a value of 1.6 meters, and
|
||||
// a variable named 'acc' with a value of 9.8 meters per second squared.
|
||||
// creates a variable named 'height' with a value of 1.6 metres, and
|
||||
// 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
|
||||
// example,
|
||||
//
|
||||
@@ -50,13 +50,13 @@
|
||||
// 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
|
||||
// additionally provides untyped constants for SI prefixes, so the following
|
||||
// are all equivalent.
|
||||
//
|
||||
// l := 0.001 * unit.Meter
|
||||
// k := 1 * unit.Milli * unit.Meter
|
||||
// l := 0.001 * unit.Metre
|
||||
// k := 1 * unit.Milli * unit.Metre
|
||||
// j := unit.Length(0.001)
|
||||
//
|
||||
// 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
|
||||
// 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
|
||||
// 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,
|
||||
// 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.
|
||||
// Different physical ideas are sometimes expressed with the same dimensions
|
||||
// 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
|
||||
// though the dimensions agree. Despite this, using the defined types to
|
||||
// represent units can help to catch errors at compile-time. For example,
|
||||
|
@@ -190,9 +190,9 @@ var Units = []Unit{
|
||||
Name: "Length",
|
||||
Receiver: "l",
|
||||
PrintString: "m",
|
||||
Suffix: "meter",
|
||||
Singular: "Meter",
|
||||
TypeComment: "Length represents a length in meters",
|
||||
Suffix: "metre",
|
||||
Singular: "Metre",
|
||||
TypeComment: "Length represents a length in metres",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 1},
|
||||
},
|
||||
@@ -277,7 +277,7 @@ var Units = []Unit{
|
||||
Name: "Acceleration",
|
||||
Receiver: "a",
|
||||
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{
|
||||
{Name: LengthName, Power: 1},
|
||||
{Name: TimeName, Power: -2},
|
||||
@@ -287,7 +287,7 @@ var Units = []Unit{
|
||||
Name: "Area",
|
||||
Receiver: "a",
|
||||
PrintString: "m^2",
|
||||
TypeComment: "Area represents and area in square meters",
|
||||
TypeComment: "Area represents and area in square metres",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 2},
|
||||
},
|
||||
@@ -484,9 +484,9 @@ var Units = []Unit{
|
||||
Name: "Torque",
|
||||
Receiver: "t",
|
||||
PrintString: "N m",
|
||||
Suffix: "newtonmeter",
|
||||
Singular: "Newtonmeter",
|
||||
TypeComment: "Torque represents a torque in Newton meters",
|
||||
Suffix: "newtonmetre",
|
||||
Singular: "Newtonmetre",
|
||||
TypeComment: "Torque represents a torque in Newton metres",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 2},
|
||||
{Name: MassName, Power: 1},
|
||||
@@ -498,7 +498,7 @@ var Units = []Unit{
|
||||
Name: "Velocity",
|
||||
Receiver: "v",
|
||||
PrintString: "m s^-1",
|
||||
TypeComment: "Velocity represents a velocity in meters per second",
|
||||
TypeComment: "Velocity represents a velocity in metres per second",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 1},
|
||||
{Name: TimeName, Power: -1},
|
||||
@@ -524,9 +524,9 @@ var Units = []Unit{
|
||||
Receiver: "v",
|
||||
Offset: -3,
|
||||
PrintString: "m^3",
|
||||
Suffix: "liter",
|
||||
Singular: "Liter",
|
||||
TypeComment: "Volume represents a volume in cubic meters",
|
||||
Suffix: "litre",
|
||||
Singular: "Litre",
|
||||
TypeComment: "Volume represents a volume in cubic metres",
|
||||
Dimensions: []Dimension{
|
||||
{Name: LengthName, Power: 3},
|
||||
},
|
||||
|
@@ -13,31 +13,31 @@ import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Length represents a length in meters.
|
||||
// Length represents a length in metres.
|
||||
type Length float64
|
||||
|
||||
const (
|
||||
Yottameter Length = 1e24
|
||||
Zettameter Length = 1e21
|
||||
Exameter Length = 1e18
|
||||
Petameter Length = 1e15
|
||||
Terameter Length = 1e12
|
||||
Gigameter Length = 1e9
|
||||
Megameter Length = 1e6
|
||||
Kilometer Length = 1e3
|
||||
Hectometer Length = 1e2
|
||||
Decameter Length = 1e1
|
||||
Meter Length = 1.0
|
||||
Decimeter Length = 1e-1
|
||||
Centimeter Length = 1e-2
|
||||
Millimeter Length = 1e-3
|
||||
Micrometer Length = 1e-6
|
||||
Nanometer Length = 1e-9
|
||||
Picometer Length = 1e-12
|
||||
Femtometer Length = 1e-15
|
||||
Attometer Length = 1e-18
|
||||
Zeptometer Length = 1e-21
|
||||
Yoctometer Length = 1e-24
|
||||
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
|
||||
@@ -55,7 +55,7 @@ func (l Length) Length() Length {
|
||||
// From converts the unit into the receiver. From returns an
|
||||
// error if there is a mismatch in dimension
|
||||
func (l *Length) From(u Uniter) error {
|
||||
if !DimensionsMatch(u, Meter) {
|
||||
if !DimensionsMatch(u, Metre) {
|
||||
*l = Length(math.NaN())
|
||||
return errors.New("Dimension mismatch")
|
||||
}
|
||||
|
@@ -13,31 +13,31 @@ import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Torque represents a torque in Newton meters.
|
||||
// Torque represents a torque in Newton metres.
|
||||
type Torque float64
|
||||
|
||||
const (
|
||||
Yottanewtonmeter Torque = 1e24
|
||||
Zettanewtonmeter Torque = 1e21
|
||||
Exanewtonmeter Torque = 1e18
|
||||
Petanewtonmeter Torque = 1e15
|
||||
Teranewtonmeter Torque = 1e12
|
||||
Giganewtonmeter Torque = 1e9
|
||||
Meganewtonmeter Torque = 1e6
|
||||
Kilonewtonmeter Torque = 1e3
|
||||
Hectonewtonmeter Torque = 1e2
|
||||
Decanewtonmeter Torque = 1e1
|
||||
Newtonmeter Torque = 1.0
|
||||
Decinewtonmeter Torque = 1e-1
|
||||
Centinewtonmeter Torque = 1e-2
|
||||
Millinewtonmeter Torque = 1e-3
|
||||
Micronewtonmeter Torque = 1e-6
|
||||
Nanonewtonmeter Torque = 1e-9
|
||||
Piconewtonmeter Torque = 1e-12
|
||||
Femtonewtonmeter Torque = 1e-15
|
||||
Attonewtonmeter Torque = 1e-18
|
||||
Zeptonewtonmeter Torque = 1e-21
|
||||
Yoctonewtonmeter Torque = 1e-24
|
||||
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
|
||||
@@ -57,7 +57,7 @@ func (t Torque) Torque() Torque {
|
||||
// From converts the unit into the receiver. From returns an
|
||||
// error if there is a mismatch in dimension
|
||||
func (t *Torque) From(u Uniter) error {
|
||||
if !DimensionsMatch(u, Newtonmeter) {
|
||||
if !DimensionsMatch(u, Newtonmetre) {
|
||||
*t = Torque(math.NaN())
|
||||
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
|
||||
// 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 {
|
||||
return &Unit{
|
||||
dimensions: d.clone(),
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Velocity represents a velocity in meters per second.
|
||||
// Velocity represents a velocity in metres per second.
|
||||
type Velocity float64
|
||||
|
||||
// Unit converts the Velocity to a *Unit
|
||||
|
@@ -13,31 +13,31 @@ import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Volume represents a volume in cubic meters.
|
||||
// Volume represents a volume in cubic metres.
|
||||
type Volume float64
|
||||
|
||||
const (
|
||||
Yottaliter Volume = 1e21
|
||||
Zettaliter Volume = 1e18
|
||||
Exaliter Volume = 1e15
|
||||
Petaliter Volume = 1e12
|
||||
Teraliter Volume = 1e9
|
||||
Gigaliter Volume = 1e6
|
||||
Megaliter Volume = 1e3
|
||||
Kiloliter Volume = 1.0
|
||||
Hectoliter Volume = 1e-1
|
||||
Decaliter Volume = 1e-2
|
||||
Liter Volume = 1e-3
|
||||
Deciliter Volume = 1e-4
|
||||
Centiliter Volume = 1e-5
|
||||
Milliliter Volume = 1e-6
|
||||
Microliter Volume = 1e-9
|
||||
Nanoliter Volume = 1e-12
|
||||
Picoliter Volume = 1e-15
|
||||
Femtoliter Volume = 1e-18
|
||||
Attoliter Volume = 1e-21
|
||||
Zeptoliter Volume = 1e-24
|
||||
Yoctoliter Volume = 1e-27
|
||||
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
|
||||
@@ -55,7 +55,7 @@ func (v Volume) Volume() Volume {
|
||||
// From converts the unit into the receiver. From returns an
|
||||
// error if there is a mismatch in dimension
|
||||
func (v *Volume) From(u Uniter) error {
|
||||
if !DimensionsMatch(u, Liter) {
|
||||
if !DimensionsMatch(u, Litre) {
|
||||
*v = Volume(math.NaN())
|
||||
return errors.New("Dimension mismatch")
|
||||
}
|
||||
|
Reference in New Issue
Block a user