[units] how to use scaled_base_unit?

Hi, at this time I start to understand boost.units. Following the doc http://www.boost.org/doc/libs/1_53_0/doc/html/boost_units/Units.html#boost_u... scaled_units are useful. But I didn't found use cases in the test or examples. E.g. https://svn.boost.org/svn/boost/trunk/libs/units/test/test_output.cpp show how to typedef this, but no usage. I try to map metric/si and imperial/us length to an intrinsic length using integer scale factors to avoid double representation uncertainly. Using BOOST_UNITS_DEFINE_CONVERSION_FACTOR I can convert meter and inch to the intrinsic length. But what about mm/um and thou/mil etc? For this I did consider scaled_base_unit. I like to convert between all of them. Since the dimensions are constant, no runtime conversation are required (as the dollar/euro example it shows). Later area calculations based on the intrinsic length are required, convertible also to metric/si and imperial systems. Thanks, Olaf

AMDG On 04/23/2013 11:55 AM, Olaf Peter wrote:
at this time I start to understand boost.units. Following the doc http://www.boost.org/doc/libs/1_53_0/doc/html/boost_units/Units.html#boost_u... scaled_units are useful. But I didn't found use cases in the test or examples. E.g. https://svn.boost.org/svn/boost/trunk/libs/units/test/test_output.cpp show how to typedef this, but no usage.
scaled_base_unit works exactly like any other base unit. For instance, boost::units::si::kilogram_base_unit is a scaled_base_unit.
I try to map metric/si and imperial/us length to an intrinsic length using integer scale factors to avoid double representation uncertainly. Using BOOST_UNITS_DEFINE_CONVERSION_FACTOR I can convert meter and inch to the intrinsic length. But what about mm/um and thou/mil etc? For this I did consider scaled_base_unit. I like to convert between all of them. Since the dimensions are constant, no runtime conversation are required (as the dollar/euro example it shows). Later area calculations based on the intrinsic length are required, convertible also to metric/si and imperial systems.
In Christ, Steven Watanabe

On 04/23/2013 11:55 AM, Olaf Peter wrote:
at this time I start to understand boost.units. Following the doc http://www.boost.org/doc/libs/1_53_0/doc/html/boost_units/Units.html#boost_u... scaled_units are useful. But I didn't found use cases in the test or examples. E.g. https://svn.boost.org/svn/boost/trunk/libs/units/test/test_output.cpp show how to typedef this, but no usage.
scaled_base_unit works exactly like any other base unit. For instance, boost::units::si::kilogram_base_unit is a scaled_base_unit.
I try to map metric/si and imperial/us length to an intrinsic length using integer scale factors to avoid double representation uncertainly. Using BOOST_UNITS_DEFINE_CONVERSION_FACTOR I can convert meter and inch to the intrinsic length. But what about mm/um and thou/mil etc? For this I did consider scaled_base_unit. I like to convert between all of them. Since the dimensions are constant, no runtime conversation are required (as the dollar/euro example it shows). Later area calculations based on the intrinsic length are required, convertible also to metric/si and imperial systems.
maybe I misuse it? Expect the compile errors I get $ ./units 1000000000 q 0 m

AMDG On 04/24/2013 07:08 AM, Olaf Peter wrote:
maybe I misuse it? Expect the compile errors I get
$ ./units 1000000000 q 0 m
- Don't use integer conversion factors. The library assumes that it can use constructs like x * (1/factor). You don't gain any precision by using int. Anything that can be represented in an int32_t can be represented exactly in a double. - You need to use bu::make_system/bu::unit for millimeter_base_unit, just like for meter_base_unit. - You can define multiple conversion factors. Just add BOOST_UNITS_DEFINE_CONVERSION_FACTOR( clients::units::my::length_base_unit, boost::units::si::meter_base_unit, double, 1000000000); to enable conversion to and from the Boost.Units systems. In Christ, Steven Watanabe
participants (2)
-
Olaf Peter
-
Steven Watanabe