Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-10050] Millimoles per Liter Unit has an additional factor of 18 added #3520

Closed
swift-ci opened this issue Mar 6, 2019 · 2 comments
Closed

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Mar 6, 2019

Previous ID SR-10050
Radar https://bugreport.apple.com/web/?problemID=48621181
Original Reporter jean-etienne (JIRA User)
Type Bug
Status Resolved
Resolution Invalid

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

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.

@beccadax
Copy link
Contributor

beccadax commented Mar 9, 2019

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.

@swift-ci
Copy link
Contributor Author

swift-ci commented Mar 9, 2019

Comment by Jean-Etienne (JIRA)

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?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants