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-20 05:06:17


AMDG

On 11/19/2018 09:09 PM, Matt Vinson via Boost-users wrote:
> Eisuke Kawashima: Thank You.  I'll have a look.  When I saw Boost.Units did not have imperial and we had to create it ourselves, I thought: the US is s 5 trillion dollar market, most of those markets need programming, all are on imperial.  Boost.Units needs imperial and programmers would find and use it.
>
> Steven Watanabe:  Thank You. 
> This solution doesn't seem correct as it does not consider "length"....

How is it wrong? length cancels out. The divides version
will give exactly the same type.

> boost::units::derived_dimension<
>   boost::units::mass_base_dimension, 1,
>   boost::units::time_base_dimension, -2>::typeI thought I'd at it (L M T^-2 L-1) but this didn't do well.:        typedef boost::units::derived_dimension<
>             boost::units::length_base_dimension, 1,
>             boost::units::mass_base_dimension, 1,
>             boost::units::time_base_dimension, -2,
>             boost::units::length_base_dimension, -1
>         >::type
>             lineal_force_dimension;
>

derived_dimension can't handle multiple uses of the
same base dimension. Even if it did, it would just
cancel them out, so this serves to purpose.

> So, I tried the " typedef boost::mpl::divides<...>" solution as it has force and length.  I am closer, I hope.
> *.h------------------------------------------------------------------------------------------------------------------------------------------
> namespace dimensional_analysis {
>       typedef boost::units::length_base_dimension::dimension_type length_dimension;
>       typedef boost::units::mass_base_dimension::dimension_type mass_dimension;
>
>       typedef boost::units::make_system<
>             boost::units::us::inch_base_unit,
>             boost::units::us::pound_base_unit
>         >::type ip_system;
>
>     namespace lineal_force {
>         typedef boost::mpl::divides<
>             boost::units::force_dimension,
>             boost::units::length_dimension>::type
>             lineal_force_dimension;
>         namespace imperial {
>             typedef boost::units::unit<
>                 lineal_force_dimension,
>                 dimensional_analysis ::ip_system
>             > lineal_force_unit;
>             typedef boost::units::quantity<lineal_force_unit, double> pound_per_in_quantity;
>             BOOST_UNITS_STATIC_CONSTANT(pound_per_inch, pound_per_in_quantity);
>         }
>         namespace si {
>             typedef boost::units::unit<
>                 lineal_force_dimension,
>                 boost::units::si::system
>             > lineal_force_unit;

This is not the unit you want. The SI
unit of force is N, not kg. kilogram-force
is not currently provided by Boost.Units
and you'll need to define it yourself.
(As in your previous post.)

>             typedef boost::units::quantity<lineal_force_dimension, double> kg_per_meter_quantity;
>             BOOST_UNITS_STATIC_CONSTANT(kg_per_meter, kg_per_meter_quantity);
>         }
>     }//lineal_force
> }//dimensional_analysis
> <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