|
Boost Users : |
Subject: Re: [Boost-users] boost::units - converting from one derived_dimension to another across systems (imperial to metric)
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2018-11-21 02:58:27
AMDG
On 11/20/2018 06:46 PM, Matt Vinson via Boost-users wrote:
> <snip>
> <some reformatting to reduce line wrapping>
> *.h-----------------------------------------------------
>
> namespace dimensional_analysis {
>
> Â Â Â Â typedef length_base_dimension::dimension_type length_dimension;
> Â Â Â Â typedef mass_base_dimension::dimension_type mass_dimension;
>
> typedef make_system<inch_base_unit,pound_base_unit>::type ip_system;
>
This should be pound_force_base_unit.
> Â namespace lineal_force {
> Â Â Â typedef mpl::divides<force_dimension,length_dimension>::type lineal_force_dimension;Â Â Â Â Â Â Â Â Â Â
>
> Â Â Â namespace imperial {
>
> Â Â Â Â Â ////////////////
> Â Â Â Â Â ////lb/in, right?
>
> ////boost::units::force_dimension =pound
> ////boost::units::length_dimension = in
> Â Â Â Â Â ////////////////
> Â Â Â Â Â typedef unit<lineal_force_dimension,lengths::ip_system> lineal_force_unit;
This unit is nonsensical because the ip_system
as written is unable to represent the lineal_force_dimension.
That this doesn't give a hard compiler error is
a bug in the library. Once you fix ip_system,
the conversions should be right.
> Â Â Â }
> Â Â Â namespace si {
> Â Â Â ////////////////
> Â Â Â ////N/m, right?
>
Yep.
> ////boost::units::force_dimension = newton
> ////boost::units::length_dimension = meter
> Â Â Â Â Â ////////////////
> Â Â Â Â Â typedef unit<lineal_force_dimension,si::system> lineal_force_unit;
> Â Â Â }
> Â }//lineal_force
> }//dimensional_analysis
>
> *.cpp-----------------------------------------------------
>
> //Imperiallb/in to SI N/m
>
The following conversion definitions are unnecessary and have no effect:
> BOOST_UNITS_DEFINE_CONVERSION_FACTOR(
> dimensional_analysis::lineal_force::imperial::lineal_force_unit,
> dimensional_analysis::lineal_force::si::lineal_force_unit,
> double,
> 175.1268369864); // exact conversion
>
> BOOST_UNITS_DEFAULT_CONVERSION(
> dimensional_analysis::lineal_force::imperial::lineal_force_unit,
> dimensional_analysis::lineal_force::si::lineal_force_unit);
>
> //SI N/mto Imperial lb/in
>
> BOOST_UNITS_DEFINE_CONVERSION_FACTOR(
> dimensional_analysis::lineal_force::si::lineal_force_unit,
> dimensional_analysis::lineal_force::imperial::lineal_force_unit,
> double,
> 0.1837185501); // exact conversion
>
> BOOST_UNITS_DEFAULT_CONVERSION(
> dimensional_analysis::lineal_force::si::lineal_force_unit,
> dimensional_analysis::lineal_force::imperial::lineal_force_unit);
>
> <snip>
>
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net