Boost logo

Boost Users :

Subject: Re: [Boost-users] Flow rate dimensional analysis
From: Michael Powell (mwpowellnm_at_[hidden])
Date: 2011-09-19 15:01:05


On Mon, Sep 19, 2011 at 12:57 PM, Steven Watanabe <watanabesj_at_[hidden]>wrote:

> AMDG
>
> On 09/19/2011 11:29 AM, Michael Powell wrote:
> > On Mon, Sep 19, 2011 at 12:10 PM, Michael Powell <mwpowellnm_at_[hidden]
> >wrote:
> >
> > The only thing I can figure is that sqrt() is buggering things up. When I
> do
> > this I get no compiler error:
> >
> > quantity<cs::units::si::flow_rate> __fr = __C_flow * __a_orifice *
> > boost::units::sqrt(__two * __p_diff / __d);
> >
> > However, when I do this, I do get a compiler error:
> >
> > quantity<cs::units::si::flow_rate, float> __fr = __C_flow * __a_orifice
> *
> > boost::units::sqrt(__two * __p_diff / __d);
> >
> > I haven't dug into sqrt() yet to verify its result, but it seems like
> this
> > is taking some underlying type liberties? Could we do this,
> > boost::units::sqrt<float>(...)?
> >
>
> Ah. I see what's going on:
> The result of sqrt is the same as root<2>(x).
> The result of root<2>(x) is based on typeof(pow(x.value(), 0.5)).
> The constant is always a double, thus float gets
> promoted to double. I'll see what I can do to
> fix this.
>

If it can be fixed from a library perspective, great. It's easy enough to
workaround, however, taking static_cast<float>(x.value()) of the
intermediate result, and so that we don't get too far removed from the
dimensional analysis.

> > I am receiving the following compiler error as my clue...
> >>
> >> Error 1 error C2440: 'initializing' : cannot convert from
> >> 'boost::units::quantity<Unit,Y>' to 'boost::units::quantity<Unit,Y>'
> >> c:\Source\Simulations\CS.Calculations.Managed\Calculators\Calculator.cpp
> >> 461 CS.Calculations.Managed
> >>
>
> In Christ,
> Steven Watanabe
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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