Boost logo

Boost :

From: Matthias Schabel (boost_at_[hidden])
Date: 2007-04-05 17:49:19


> I'm fine with that. Just make sure that the conversion factor
> is not 1.0 ;) And tell me how that line in my example will
> look like, when you correct the bug.

Janek,

This works as expected, to the best of my knowledge, for extracting
conversion factors between units :

template<class Y,class FromUnit,class ToUnit>
inline
Y
conversion_factor(const FromUnit&,const ToUnit&)
{
     return quantity<ToUnit,Y>(Y(1)*FromUnit()).value();
};

for which

std::cout << conversion_factor<double>(CGS::dyne,SI::newton) <<
std::endl;

gives

1e-05

If no named unit static const is available, you will, of course have
to pass default constructed units :

std::cout << conversion_factor<double>(CGS::momentum(),SI::momentum
()) << std::endl;

I will commit this to the sandbox sometime this afternoon. Otherwise,
for dimensionless heterogeneous quantities (mixed units of the same
dimension), you should also be able to explicitly force the
conversion via

std::cout << quantity<SI::dimensionless>(1.0*CGS::dyne/SI::newton) <<
std::endl;

At the moment this is still broken - we'll work on fixing it. I think
that the conversion_factor<> syntax should be preferred anyway as it
more clearly demonstrates the intent of the code.

Cheers,

Mattthias


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk