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
488 stars 40 forks source link

documentation #58

Closed GregKon closed 4 years ago

GregKon commented 4 years ago

Dear Dominik

I am evaluating your great work. Before it may be used, it is always good idea to understand how it works. I wonder if you may add to documentation some details how the architecture works, how dimensions analyse works in your implementation, some very basic, may be few words. I suppose detail::unit_t is a most important class.

So far from documentation I know that it is: "type safety at compile time".

bernedom commented 4 years ago

What exactly are you missing? I do not get what you mean by "dimensions analyse"

There is not so much more to say than what is already written in the README.md (A tiny bit more is here https://github.com/bernedom/SI/blob/master/doc/implementation-details.md) and in https://github.com/bernedom/SI/blob/master/CONTRIBUTING.md You can generate the API documentation by running doxygen.

I will try to unify or link those documents a bit better and mention the generation of the API documentation, or maybe generate and upload it to the ghpages for the releases.

GregKon commented 4 years ago

for example:

  1. implicit conversion for different ratio (is a chance of lost precision on integers? it is one of most important issue)
  2. comparison of different ratio units
  3. initialization of quantity (it is a little bit diffrent than boost.units, your library allow construct from scalar, boost.units not). I think most of users try to understand library base of boost.units.

some potentially more, I will try to find it out later.

bernedom commented 4 years ago

Thanks for the hints, I will write some stuff and keep you in the loop for it.

bernedom commented 4 years ago

@GregKon please check out the attached pull request for an attempt to document the issues you brought up.

GregKon commented 4 years ago

Hi Valuable.

  1. Am I correctly understand that: implict conversion is perform on underlaying integer type, e.g. uint16_t? it is importand since boost::units use double.

  2. I wonder why in your implementation is limited to std::is_integral<>, what is true for all built in integers types. I do use non built inteeger type what has all necessary operators (exepct some non obvious implict conversion) and behave like built in integer. For such purposes standard provide std::numeric_limits::is_integer, this allow on specialization user type to true.

bernedom commented 4 years ago
  1. The conversion is performed on whatever type is set in the template. For the literals this is either int64_t or long double. For arbitrarily constructed types whatever you pass. i.e metre_t<uint8_t> would use uint8_t, metre_t<double> would use double

  2. I'm using std::is_integral<> and std::is_floating_point for simplicity. But using std::numeric_limits::is_integer could work as well. This probably would enable compatibility with boost::multiprecision and similar types. I will consider changing that in the future if it does not interfere with SI bein 0-overhead for same-ratio units.