You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The UnitConcentrationMass offers an initializer for the unit millimolesPerLiter that takes a gramsPerMole parameter. The official documentation states that the coefficient to the base unit (g/L) is 18 * gramsPerMole.
The factor of 18 seems superfluous, and yields an erroneous result when converting a Measurement in millimolesPerLiter to a value in gramsPerLiter. Also, the conversion is off by 3 orders of magnitude (10e3)
A simple dimensional analysis can show that the factor 18 is superfluous and the conversion millimole to mole (* 10e3) is not accounted for.
Example:
NaCl (table salt) has a molecular mass of 58 g/mol (see Wikipedia)
Let's imagine a solution with a concentration of 1 mol/L (i.e. 1000 millimoles per Liter)
With 1 mol/L and 58 g/mol, the same concentration of 1 mol/L is equivalent to 58 g/L
As a result, to conversion coefficient for millimolesPerLiter to the base unit (g/L) should be "gramsPerMole / 1000"
This 18 factor seems to be closely related to Blood sugar conversions (which is the only molecular mass unit added with HealthKit). See here how 1 mmol / l of blood sugar is equal 18 mg / dl.
See attached playground.
The text was updated successfully, but these errors were encountered:
This is a bug in an Apple framework you're using with Swift, rather than a bug in Swift itself, so the Foundation team will handle it through the Apple bug reporter.
brentdax (JIRA User) Thanks for the update!
Just for the sake of clarity, the CONTRIBUTING.md document for Swift Foundation mentions reporting bugs here if I understand correctly?
Attachment: Download
Additional Detail from JIRA
md5: a0022e342c656484de000bb10fc57df6
Issue Description:
The UnitConcentrationMass offers an initializer for the unit millimolesPerLiter that takes a gramsPerMole parameter. The official documentation states that the coefficient to the base unit (g/L) is 18 * gramsPerMole.
The factor of 18 seems superfluous, and yields an erroneous result when converting a Measurement in millimolesPerLiter to a value in gramsPerLiter. Also, the conversion is off by 3 orders of magnitude (10e3)
A simple dimensional analysis can show that the factor 18 is superfluous and the conversion millimole to mole (* 10e3) is not accounted for.
Example:
NaCl (table salt) has a molecular mass of 58 g/mol (see Wikipedia)
Let's imagine a solution with a concentration of 1 mol/L (i.e. 1000 millimoles per Liter)
With 1 mol/L and 58 g/mol, the same concentration of 1 mol/L is equivalent to 58 g/L
As a result, to conversion coefficient for millimolesPerLiter to the base unit (g/L) should be "gramsPerMole / 1000"
This 18 factor seems to be closely related to Blood sugar conversions (which is the only molecular mass unit added with HealthKit). See here how 1 mmol / l of blood sugar is equal 18 mg / dl.
See attached playground.
The text was updated successfully, but these errors were encountered: