nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
952 stars 135 forks source link

New Unit: mmhg #147

Closed rsivek closed 6 years ago

rsivek commented 6 years ago

First off, this library is awesome! Thank you for making this available.

I would like to see mmhg (millimeters of mercury) for units of pressure, which is "precisely 133.322387415 pascals".

I believe this would be defined as follows in the pressure namespace:

UNIT_ADD(pressure, mmhg, mmhg, mmHg, unit<std::ratio<26664477483LL, 200000000LL>, pascals>)

Let me know if that looks incorrect though.

JohelEGP commented 6 years ago

Let me know if that looks incorrect though.

The capitalization of the abbreviation (Wikipedia suggests mmHg) and using the LL suffix for the literals of the std::ratio which might overflow an int.

rsivek commented 6 years ago

@johelegp Both excellent points, thank you. I've updated the request above with your suggested changes.

nholthaus commented 6 years ago

Adding it won't be a problem. That conversion factor is rough though, and this unit is going to overflow like crazy if you do anything very complicated with it. As a practical matter, it may be better to approximate mmHg with Torr.

rsivek commented 6 years ago

@nholthaus that's a good point. A close approximation in terms of torrs would be 6178355 : 6178354.

The difference between the two units is so small that I don't think we could effectively reduce the ratio values below that without making them 1 : 1.

nholthaus commented 6 years ago

added to the latest 3.x. I used the original (official) definition because as a design principle no approximations are used in the library.