[units] division with absolute temperature

Hello, I'm trying to use absolute temperature in some expressions. Unfortunately I'm having some issues with the compilation. For instance, if I divide an absolute temperature by itself I would expect to get 1 dimensionless, however that will cause a compilation error. #include <iostream> #include <boost/units/absolute.hpp> #include <boost/units/io.hpp> #include <boost/units/quantity.hpp> #include <boost/units/systems/si.hpp> #include <boost/units/systems/si/io.hpp> int main(int argc, char** argv) { using namespace boost::units; quantity<si::temperature> rT(273.15 * si::kelvin); // relative temperature quantity<si::dimensionless> v; v = rT / rT; std::cout << v << std::endl; // 1 dimensionless quantity<absolute<si::temperature> > aT(273.15 * absolute<si::temperature>()); // absolute temperature //v = aT / aT; // uncommenting this line will cause compilation errors //std::cout << v << std::endl; // 1 dimensionless return 0; } If I uncomment the line with v = aT / aT, in ubuntu 15.10 with boost 1.58 and gcc 5.2.1, I get the error: (...) /usr/include/boost/units/operators.hpp:81:5: error: no match for ‘operator/’ (operand types are ‘boost::units::absolute<boost::units::unit<boost::units::list<boost::units::dim<boost::units::temperature_base_dimension, boost::units::static_rational<1l> >, boost::units::dimensionless_type>, boost::units::homogeneous_system<boost::units::list<boost::units::si::meter_base_unit, boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit, boost::units::scale<10l, boost::units::static_rational<3l> > >, boost::units::list<boost::units::si::second_base_unit, boost::units::list<boost::units::si::ampere_base_unit, boost::units::list<boost::units::si::kelvin_base_unit, boost::units::list<boost::units::si::mole_base_unit, boost::units::list<boost::units::si::candela_base_unit, boost::units::list<boost::units::angle::radian_base_unit, boost::units::list<boost::units::angle::steradian_base_unit, boost::units::dimensionless_type> > > > > > > > > > > >’ and ‘boost::units::absolute<boost::units::unit<boost::units::list<boost::units::dim<boost::units::temperature_base_dimension, boost::units::static_rational<1l> >, boost::units::dimensionless_type>, boost::units::homogeneous_system<boost::units::list<boost::units::si::meter_base_unit, boost::units::list<boost::units::scaled_base_unit<boost::units::cgs::gram_base_unit, boost::units::scale<10l, boost::units::static_rational<3l> > >, boost::units::list<boost::units::si::second_base_unit, boost::units::list<boost::units::si::ampere_base_unit, boost::units::list<boost::units::si::kelvin_base_unit, boost::units::list<boost::units::si::mole_base_unit, boost::units::list<boost::units::si::candela_base_unit, boost::units::list<boost::units::angle::radian_base_unit, boost::units::list<boost::units::angle::steradian_base_unit, boost::units::dimensionless_type> > > > > > > > > > > >’) BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, (typeof_::make<X>()/typeof_::make<Y>())) (...) I could add something like namespace boost { namespace units { template<class Unit, class X, class Y> struct divide_typeof_helper<quantity<absolute<Unit>, X>, quantity<absolute<Unit>, Y> > { typedef typename divide_typeof_helper<X, Y>::type value_type; typedef typename divide_typeof_helper<Unit, Unit>::type unit_type; typedef quantity <unit_type, value_type> type; }; } } but that would not work in more complex examples, e.g.: #include <boost/units/systems/si/codata/physico-chemical_constants.hpp> (...) using namespace boost::units::si::constants::codata; typedef boost::mpl::divides<boost::units::energy_dimension, boost::units::amount_dimension>::type Ea_dimension; typedef boost::units::unit<Ea_dimension, boost::units::si::system> Ea; quantity<Ea> ea(0); auto x = ea / (R * aT); Any help would be most appreciated, João Leal

AMDG On 04/18/2016 03:32 AM, João Leal wrote:
I'm trying to use absolute temperature in some expressions. Unfortunately I'm having some issues with the compilation. For instance, if I divide an absolute temperature by itself I would expect to get 1 dimensionless, however that will cause a compilation error.
This is forbidden by design. Division of absolute temperatures only makes sense for kelvin. If you're only using kelvin, then you don't really need to use absolute. In Christ, Steven Watanabe

Thank you for the reply! I was thinking of using the absolute temperature in a modeling framework. I don't really know which units the user is going to use. The kelvin units were just used in the example to show my difficulties in using absolute temperature dimensions. I am afraid the user can do something like temperature = 20 * celsius while hoping to get (273.15 + 20) * kelvin. Unfortunately, if I use absolute temperature to avoid this problem, then that variable needs to be converted to relative temperature every time it is used in expressions (e.g. ideal gas law: n = PV/(RT)). I'll probably use relative temperatures and document it very well. Best regards, João Leal 2016-04-18 22:10 GMT+01:00 Steven Watanabe <watanabesj@gmail.com>:
AMDG
On 04/18/2016 03:32 AM, João Leal wrote:
I'm trying to use absolute temperature in some expressions. Unfortunately I'm having some issues with the compilation. For instance, if I divide an absolute temperature by itself I would
expect
to get 1 dimensionless, however that will cause a compilation error.
This is forbidden by design. Division of absolute temperatures only makes sense for kelvin. If you're only using kelvin, then you don't really need to use absolute.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
João Leal
-
Steven Watanabe