mamrhein / quantities.rs

Unit-safe computations with quantities.
BSD 3-Clause "New" or "Revised" License
25 stars 10 forks source link

PR for additional units. #3

Closed 2sugarcubes closed 2 years ago

2sugarcubes commented 2 years ago

Dear Mr Amrhein.

I your project is great and was wondering if I could contribute some additional units for distance, time, and mass, for better functionality with astronomical workloads.

I have a working implementation ready, am open to change or drop it (in part or in full) if it's out of the scope of this repository, and I am still pretty new to contributing to open source software, so I would appreciate any notes or critiques you have.

Units added in the fork:

— Luke.

mamrhein commented 2 years ago

Hi Luke, thanks for your PR. I appreciate your proposal to make this package usable for astronomers. But I'm somewhat reluctant to integrate the new units into the already defined quantities. I think someone dealing with light-years doesn't care about millimeters and vice versa. The currently pre-defined quantities are meant for "earth-bound" measures. Adding units of astronomical scale would raise the range of magnitude between the largest and the smallest unit up to 10^30 or even more. That does far exceed the precision of the types used for the numerical part of quantities. ('f64' has less then 16 significant decimal digits!) Instead, I would prefer to define separate quantities with units of astronomical scale: AstroTime: ref-unit = Day units = your proposed additions AstroLength: ref-unit: astronomical unit? units: your proposed additions, plus kilometer as smallest unit? and Kiloparsec? / Megaparsec? AstroMass: ref-unit = Solar Mass? units = your proposed additions Is there also a unit at galactic scale? For Speed I would add 'Speed of Light' as a unit to the existing quantity. If you agree I would add three modules with the proposed quantities. In any case, I would like you to review and double-check the definitions! Best regards, Michael

mamrhein commented 2 years ago

Hi Luke, the proposal above jumps too short. Having additional quantities for the same base concept would render the derived quantities inconsistent. Dividing AstroLength by AstroTime wouldn't give Speed. Providing quantities with units at a different scale needs to have a consistent set of base and derived quantities. I think this could best be done with a new crate, based on 'quantities', and providing an own definition of 'Length', 'Mass', 'Duration' etc., including all of the derived SI quantities. (A similar approach could be used for example with units at atomic and sub-atomic scale, usable for atomic and quantum physics.) I will start a new package ('astronomical_quantities') and keep you posted. I still would like you to review the definitions and - if possible - provide some real-life test cases. Best regards, Michael

mamrhein commented 2 years ago

Hi Luke, I created the crate 'astronomical-quantities' in a new branch named 'astro'. May I ask you to have a look at the definitions and give me some feedback? Thx in advance, Michael

mamrhein commented 2 years ago

No feedback from OP. Closing this.

2sugarcubes commented 2 years ago

Hey, thanks for taking the time to reviewing my pull request, and I totally understand your rational.

Sorry for not responding sooner. You've been very thorough with the units included in astronomical-quantities and while I am not qualified to speak on behalf of professional astronomers and the like, this is very useful for my use case.

Thank you.