Opened 7 years ago
Last modified 7 years ago
#11389 new Bugs
Bug: Unit precision is restricted to double when using conversion constants
Reported by: | Owned by: | Matthias Schabel | |
---|---|---|---|
Milestone: | To Be Determined | Component: | units |
Version: | Boost 1.58.0 | Severity: | Problem |
Keywords: | Cc: |
Description
From BOOST_UNITS_DEFINE_BASE_UNIT_WITH_CONVERSIONS in boost/units/conversions.hpp:
BOOST_UNITS_DEFINE_CONVERSION_FACTOR(namespace_::name_ ## _base_unit, unit, double, factor); \
Note the type of the conversion factor value is forced unconditionally to be double.
It would be nice if the precision of this constant could be either made more flexible, or made as precise as possible with rounding to a lower-precision constant when lower-precision types are used. For example, using long double would allow higher-precision constants and conversions, but this isn't possible at present since even if a quantity<T, long double> is used, the conversions are still being restricted to double precision.
Kind regards, Roger
One thought here would be to define the conversion constants in the same way as the math constants, giving the user separate float, double and long double values (or equivalents via the templates). This would then let the quantity template value type be used to select the constant of the appropriate precision during conversions.