Boost logo

Boost Users :

Subject: [Boost-users] [units] Dimensionless? expecting length+length
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2015-08-08 18:27:46


Hello,

I am working on some trajectory calculations, and having a strange
compiler error. First, great that I should get a compiler error at
all! Second, what am I missing?

quantity<acceleration> g() {
    static const auto gValue = static_cast<double>(9.812);
    static const auto metersPerSecondPerSecond = meters / second / second;
    static const quantity<acceleration> g = gValue*metersPerSecondPerSecond;
    return g;
}

double Class1::CalculateZeta(double timeMilliseconds, double heightMeters) {

    static const auto two = static_cast<double>(2);
    static const auto milliseconds = milli*seconds;

    const auto t = timeMilliseconds*milliseconds;
    const auto h = heightMeters*meters;

    const auto g_ = g();

    auto result = -(g_ / two)*(t*t) + h;

    return result.value();
}

Just if I did the dimensional analysis, I might expect the time
components (i.e. T^2) to cancel themselves out, which should leave me
with length+length, no?

This is exposed via a C++ CLR (VS2013), but the Boost.Units are done internally.

What am I missing here? I need to normalize the units, say to meters, etc?

Best regards,

Michael Powell

Errors:

Error 4 error C2676: binary '+' :
'boost::units::quantity<boost::units::unit<boost::units::list<boost::units::dim<Derived,boost::units::static_rational<1,1>>,boost::units::dimensionless_type>,boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::meter_base_unit,boost::units::static_rational<1,1>>,boost::units::dimensionless_type>,boost::units::list<boost::units::dim<Derived,boost::units::static_rational<1,1>>,boost::units::dimensionless_type>,boost::units::list<boost::units::scale_list_dim<Scale>,boost::units::dimensionless_type>>>,void>,double>'
does not define this operator or a conversion to a type acceptable to
the predefined operator
I:\Source\Spikes\Kingdom.Physics\src\Kingdom.Physics.Calculators\Class1.cpp
43 1 Kingdom.Physics.Calculators
Error 2 error C2784:
'add_typeof_helper<boost::units::unit<Dim1,System1,void>,boost::units::unit<Dim2,System2,void>>::type
boost::units::operator +(const boost::units::unit<Dim1,System1,void>
&,const boost::units::unit<Dim2,System2,void> &)' : could not deduce
template argument for 'const boost::units::unit<Dim1,System1,void> &'
from 'boost::units::quantity<boost::units::unit<boost::units::list<boost::units::dim<Derived,boost::units::static_rational<1,1>>,boost::units::dimensionless_type>,boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::meter_base_unit,boost::units::static_rational<1,1>>,boost::units::dimensionless_type>,boost::units::list<boost::units::dim<Derived,boost::units::static_rational<1,1>>,boost::units::dimensionless_type>,boost::units::list<boost::units::scale_list_dim<Scale>,boost::units::dimensionless_type>>>,void>,double>'
I:\Source\Spikes\Kingdom.Physics\src\Kingdom.Physics.Calculators\Class1.cpp
43 1 Kingdom.Physics.Calculators
Error 3 error C2893: Failed to specialize function template
'add_typeof_helper<boost::units::quantity<Unit1,X>,boost::units::quantity<Unit2,Y>>::type
boost::units::operator +(const boost::units::quantity<Unit1,X> &,const
boost::units::quantity<Unit2,Y> &)'
I:\Source\Spikes\Kingdom.Physics\src\Kingdom.Physics.Calculators\Class1.cpp
43 1 Kingdom.Physics.Calculators
5 IntelliSense: no operator "+" matches these operands
            operand types are:
boost::units::quantity<boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<1L, 1L>>,
boost::units::dimensionless_type>,
boost::units::heterogeneous_system<boost::units::heterogeneous_system_impl<boost::units::list<boost::units::heterogeneous_system_dim<boost::units::si::meter_base_unit,
boost::units::static_rational<1L, 1L>>,
boost::units::dimensionless_type>,
boost::units::list<boost::units::dim<boost::units::length_base_dimension,
boost::units::static_rational<1L, 1L>>,
boost::units::dimensionless_type>,
boost::units::list<boost::units::scale_list_dim<boost::units::scale<10L,
boost::units::static_rational<-6L, 1L>>>,
boost::units::dimensionless_type>>>, void>, double> + const
boost::units::quantity<boost::units::unit<boost::units::length_dimension,
boost::units::si::system, void>, double>
i:\Source\Spikes\Kingdom.Physics\src\Kingdom.Physics.Calculators\Class1.cpp
43 49 Kingdom.Physics.Calculators


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