Boost logo

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