SciNim / Unchained

A fully type safe, compile time only units library.
https://scinim.github.io/Unchained
110 stars 0 forks source link

Add remaining derived SI units #3

Open Vindaar opened 3 years ago

Vindaar commented 3 years ago

A decent summary on Wikipedia: https://en.wikipedia.org/wiki/SI_derived_unit

Definitely have to add all remaining derived SI units (things like Tesla, Radian etc. are still missing).

Maybe a good idea to also add some of the quantities listed in the examples section. While we shouldn't enforce distinctness there maybe (e.g. then m⁻¹ is of an unclear quantity all of a sudden), it would be handy to be able to refer to Wavenumber and have that match anything that is of inverse length.

Vindaar commented 2 years ago

There are still a few missing! Should be added now that it's as trivial as adding a few select new lines.

arkanoid87 commented 1 year ago

I wonder if it's worth rewriting and updating the units

have you ever considered parsing one of these?

frinklang https://frinklang.org/frinkdata/units.txt

gnu-units https://github.com/ryantenney/gnu-units/blob/master/units.dat

Vindaar commented 1 year ago

Yes, one could certainly parse one of them and generate the correct declarative macro code from it.

However, compilation is already not exactly fast. If one had a file of all those units compilation speed would be pretty bad I think. It would be nice to have a submodule "all_units" or something like that, sure.

Generally, the vast, vast majority of these units is simply unnecessary. The point is that unchained already provides the facility to generate your own set of units for users that actually need to deal with different kinds of units than standard SI units (e.g. I saw units for paper sizes and weights in one of your linked files). That's great. Feel free to write your own little file, in the same way as in the example for a custom unit system https://github.com/SciNim/Unchained/blob/master/examples/custom_unit_system.nim.

I'm completely open to even adding useful unit systems (and of course generally regular units) to the repository. Just create a PR! I'm just not (for the time being) going to add an almost infinite number of units that likely no one is ever going to use.

A more important piece of work in my opinion is finishing my local code to handle separate unit systems at the same time and do correct conversions between them.

arkanoid87 commented 8 months ago

I find myself often copypasting the original file just to add a couple of quantities or units.

I tried to import the original file and create a new declareQuantities and declareUnits statements, but it clearly doesn't seem to work that way

What about enabling this "append" pattern to get the best of both words?

Vindaar commented 7 months ago

I'd need to check if "appending" from another module could work correctly. There's a chance the current macro logic would fail in that case.

Otherwise: I'm always open to add actually useful other units! I just would like to avoid to add a huge number of units that hardly anyone will ever use. So if you have a list of things that you consider essential, feel free to tell me / create a PR for them.