kwikius / pqs

C++ Physical Quantities System
GNU General Public License v3.0
5 stars 1 forks source link

default numeric types are convenient but can be confusing and currently not consistent #10

Closed kwikius closed 3 years ago

kwikius commented 4 years ago

Every model of quantity has an underlying numeric type ( e.g double) and for convenience this is allowed to default to some real_type, which can be theoretically modified in \<pqs/bits/config.hpp>. This is particularly convenient for me when working with contemporary arm microcontrollers which often have hardware floating point support for float or double but not long double, so I can make the default match the optimum for the microcontroller.

However this makes things inconvenient when working with for example std::chrono_duration literals which return a type with a long double numeric value, because conversion to a type with a double is disallowed due to it being a narrowing conversion \<pqs/concepts/associated/basic_quantity.hpp>#L31 https://github.com/kwikius/pqs/blob/master/examples/chrono_duration_support.cpp#L100 Maybe there should not be any default numeric type e.g. for the quantity typedefs \<pqs/systems/si/quantity/quantity_macro.hpp>#L9 , which would be more typing but less confusing

kwikius commented 3 years ago

The answer to this is that std::chrono got this wrong. Since a UDL can figure out the smallest type that can hold its value UDT's should return the smallest type that can hold the value as shown here

TODO flesh out bespoke user defined literal example and make it the way for all UDLs in the example si system

kwikius commented 3 years ago

Fixed