bernedom / SI

A header only C++ library that provides type safety and user defined literals for physical units
https://si.dominikberner.ch/doc/
MIT License
486 stars 40 forks source link

Documentation, overloaded operations, compilation issue #115

Closed Lecrapouille closed 11 months ago

Lecrapouille commented 1 year ago

Is your feature request related to a problem? Please describe.

Hi sir ! Make a long time since https://github.com/bernedom/SI/issues/93 I still have not yet converted my float into SI in my personal project :( I'm currently testing your library back and at the same time testing this one https://github.com/nholthaus/units.

To help beginners starting with your lib, I think you could add some concrete some basic examples in your documentation. Here is an attempt of mine concerning tricycle kinematics. https://github.com/Lecrapouille/BacASable/tree/master/LawControl/SI

The code using your lib is here https://github.com/Lecrapouille/BacASable/blob/master/LawControl/SI/si.cpp and the code using units is here https://github.com/Lecrapouille/BacASable/blob/master/LawControl/SI/units.cpp (feel free to use this code).

I'm sorry, time is currently missing for me for writing this ticket (I do it anyway else I'll forget to write it), as well for making a C++ class of si.cpp like done in units.cpp, but currently si.cpp does note compile because (speed / wheelbase) fails compiling (I hope the issue does not come from me). In addition, I noticed some weak points compared to the other lib:

Operators that could be overloaded:

Describe the solution you'd like

Describe alternatives you've considered Implemented in https://github.com/nholthaus/units.

Additional context n/a

bernedom commented 1 year ago

Hi again, thanks for the feedback.

constexpr auto speed = 1_m / 1_s; std::cout << speed << std::endl;



* Adding the math functions like `si::cos` `si::sin` etc. is a good idea. Will add it in one of the next releases. 
* On the usage of `auto` I consider this a matter of code style and if you're using clangd as a language server in vscode you get a nice annotation of the underlying type. 

![image](https://user-images.githubusercontent.com/15666436/208318213-78255a65-7773-49da-9265-d783180c061a.png)
Lecrapouille commented 1 year ago

@bernedom Thanks

bernedom commented 1 year ago

The error is there because you're dividing velocity by distance which is not yet supported. The resulting unit would be Hertz or 1/s. I will add this.

bernedom commented 1 year ago

Sorry for the long wait I had a bit of trouble finding the time. I added angular frequency to this branch here: https://github.com/bernedom/SI/tree/feature/add-v-divided-by-L with this your original example should compile if you set the parentheses correctly. The example is in the file multi_unit_tests.cc

It would be cool if you could check if the calculation indeed works correctly, as I am not really sure there and lack the domain knowledge of your example to determine if the results make sense.