Browse Source

Add molarity example

David Peter 2 years ago
parent
commit
20489794d3
2 changed files with 14 additions and 2 deletions
  1. 9 0
      examples/molarity.nbt
  2. 5 2
      modules/units/misc.nbt

+ 9 - 0
examples/molarity.nbt

@@ -0,0 +1,9 @@
+let molar_mass_NaCl = 58.44 g / mol
+
+fn molarity(mass: Mass, volume: Volume) -> Molarity = (mass / molar_mass_NaCl) / volume
+
+# Isotonic saline
+let salt_mass = 9 g
+let water_volume = 1 L
+
+assert_eq(molarity(salt_mass, water_volume), 154 mmol/l, 0.1 mmol/l)

+ 5 - 2
modules/units/misc.nbt

@@ -40,11 +40,14 @@ unit psi: Pressure = 6.894757 kPa
 @aliases(atmospheres, atm: short)
 unit atmosphere: Pressure = 101_325 pascal
 
+dimension Molarity = AmountOfSubstance / Volume
+dimension Molality = AmountOfSubstance / Mass
+
 @metric_prefixes
-unit molar: AmountOfSubstance / Volume = 1 mol / litre
+unit molar: Molarity = 1 mol / litre
 
 @metric_prefixes
-unit molal: AmountOfSubstance / Mass = 1 mole / kilogram
+unit molal: Molality = 1 mole / kilogram
 
 ### Abbreviations