Added units of electric current
This commit is contained in:
parent
efd5b63a0d
commit
5371f8d5ac
@ -142,7 +142,7 @@ create_units!(
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
The number associated with a unit is it's "weight". For example, if a second's weight is `1`, then a minute's weight is `1000`.
|
The number associated with a unit is it's "weight". For example, if a second's weight is `1`, then a minute's weight is `60`.
|
||||||
|
|
||||||
I have found [translatorscafe.com](https://www.translatorscafe.com/unit-converter) and [calculateme.com](https://www.calculateme.com/) to be good websites for unit conversion. Wikipedia is worth looking at as well.
|
I have found [translatorscafe.com](https://www.translatorscafe.com/unit-converter) and [calculateme.com](https://www.calculateme.com/) to be good websites for unit conversion. Wikipedia is worth looking at as well.
|
||||||
|
|
||||||
|
|||||||
@ -318,6 +318,11 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) ->
|
|||||||
"hp" | "hps" | "horsepower" | "horsepowers" => tokens.push(Token::Unit(Horsepower)),
|
"hp" | "hps" | "horsepower" | "horsepowers" => tokens.push(Token::Unit(Horsepower)),
|
||||||
"mhp" | "hpm" | "metric hp" | "metric hps" | "metric horsepower" | "metric horsepowers" => tokens.push(Token::Unit(MetricHorsepower)),
|
"mhp" | "hpm" | "metric hp" | "metric hps" | "metric horsepower" | "metric horsepowers" => tokens.push(Token::Unit(MetricHorsepower)),
|
||||||
|
|
||||||
|
"ma" | "milliamp" | "milliampere" => tokens.push(Token::Unit(Milliampere)),
|
||||||
|
"a" | "amp" | "ampere" => tokens.push(Token::Unit(Ampere)),
|
||||||
|
"ka" | "kiloamp" | "Kiloampere" => tokens.push(Token::Unit(Kiloampere)),
|
||||||
|
"bi" | "biot" | "biots" | "aba" | "abampere" => tokens.push(Token::Unit(Abampere)),
|
||||||
|
|
||||||
// for pound-force per square inch
|
// for pound-force per square inch
|
||||||
"lbf" => tokens.push(Token::LexerKeyword(PoundForce)),
|
"lbf" => tokens.push(Token::LexerKeyword(PoundForce)),
|
||||||
"force" => tokens.push(Token::LexerKeyword(Force)),
|
"force" => tokens.push(Token::LexerKeyword(Force)),
|
||||||
|
|||||||
12
src/units.rs
12
src/units.rs
@ -23,6 +23,8 @@ pub enum UnitType {
|
|||||||
Energy,
|
Energy,
|
||||||
/// A unit of power, for example `Watt`
|
/// A unit of power, for example `Watt`
|
||||||
Power,
|
Power,
|
||||||
|
/// A unit of electrical current, for example `Ampere`
|
||||||
|
ElectricCurrent,
|
||||||
/// A unit of pressure, for example `Bar`
|
/// A unit of pressure, for example `Bar`
|
||||||
Pressure,
|
Pressure,
|
||||||
/// A unit of frequency, for example `Hertz`
|
/// A unit of frequency, for example `Hertz`
|
||||||
@ -209,6 +211,11 @@ create_units!(
|
|||||||
Horsepower: (Power, d128!(745.69987158227022)), // exact according to wikipedia
|
Horsepower: (Power, d128!(745.69987158227022)), // exact according to wikipedia
|
||||||
MetricHorsepower: (Power, d128!(735.49875)),
|
MetricHorsepower: (Power, d128!(735.49875)),
|
||||||
|
|
||||||
|
Milliampere: (ElectricCurrent, d128!(1)),
|
||||||
|
Ampere: (ElectricCurrent, d128!(1000)),
|
||||||
|
Kiloampere: (ElectricCurrent, d128!(1000000)),
|
||||||
|
Abampere: (ElectricCurrent, d128!(10000)),
|
||||||
|
|
||||||
Pascal: (Pressure, d128!(1)),
|
Pascal: (Pressure, d128!(1)),
|
||||||
Kilopascal: (Pressure, d128!(1000)),
|
Kilopascal: (Pressure, d128!(1000)),
|
||||||
Atmosphere: (Pressure, d128!(101325)),
|
Atmosphere: (Pressure, d128!(101325)),
|
||||||
@ -653,6 +660,7 @@ mod tests {
|
|||||||
assert_eq!(convert_test(1000.0, GigawattHour, TerawattHour), 1.0);
|
assert_eq!(convert_test(1000.0, GigawattHour, TerawattHour), 1.0);
|
||||||
assert_eq!(convert_test(1000.0, TerawattHour, PetawattHour), 1.0);
|
assert_eq!(convert_test(1000.0, TerawattHour, PetawattHour), 1.0);
|
||||||
|
|
||||||
|
assert_eq!(convert_test(1000.0, Milliwatt, Watt), 1.0);
|
||||||
assert_eq!(convert_test(1000.0, Watt, Kilowatt), 1.0);
|
assert_eq!(convert_test(1000.0, Watt, Kilowatt), 1.0);
|
||||||
assert_eq!(convert_test(1000.0, Kilowatt, Megawatt), 1.0);
|
assert_eq!(convert_test(1000.0, Kilowatt, Megawatt), 1.0);
|
||||||
assert_eq!(convert_test(1000.0, Megawatt, Gigawatt), 1.0);
|
assert_eq!(convert_test(1000.0, Megawatt, Gigawatt), 1.0);
|
||||||
@ -663,6 +671,10 @@ mod tests {
|
|||||||
assert_eq!(convert_test(745.6998715822702, Watt, Horsepower), 1.0);
|
assert_eq!(convert_test(745.6998715822702, Watt, Horsepower), 1.0);
|
||||||
assert_eq!(convert_test(735.49875, Watt, MetricHorsepower), 1.0);
|
assert_eq!(convert_test(735.49875, Watt, MetricHorsepower), 1.0);
|
||||||
|
|
||||||
|
assert_eq!(convert_test(1000.0, Milliampere, Ampere), 1.0);
|
||||||
|
assert_eq!(convert_test(1000.0, Ampere, Kiloampere), 1.0);
|
||||||
|
assert_eq!(convert_test(10.0, Ampere, Biot), 1.0);
|
||||||
|
|
||||||
assert_eq!(convert_test(1000.0, Pascal, Kilopascal), 1.0);
|
assert_eq!(convert_test(1000.0, Pascal, Kilopascal), 1.0);
|
||||||
assert_eq!(convert_test(101325.0, Pascal, Atmosphere), 1.0);
|
assert_eq!(convert_test(101325.0, Pascal, Atmosphere), 1.0);
|
||||||
assert_eq!(convert_test(100.0, Pascal, Millibar), 1.0);
|
assert_eq!(convert_test(100.0, Pascal, Millibar), 1.0);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user