
Steven raised some good points about the dimensionless specializations of quantities. The crux of the problem is that sometimes we would like to be able to specify a formally dimensionless quantity as a heterogeneous quantity : e.g. 1.0*CGS::dyne/SI::newton. If we automatically convert, we lose the ability to represent quantities like this and all dimensionless quantities become equivalent. However, in some cases you would like to preserve the information on the unit system; for trig functions, as an example, you would like to have closure so that acos(cos(quantity<some_angular_unit,Y>)) returns the argument passed to cos. If system information is stripped, this becomes impossible without explicitly specifying the return type of acos. Furthermore, now we can't represent dimensionless quantities for which conversion factors haven't been defined. Now, if we preserve this capability, the system resulting from a dimensionless unit such as 1.5*CGS::dyne/SI::newton becomes ambiguous - should it be an SI dimensionless quantity or a CGS dimensionless quantity. So, even though it is a bit ugly, I think Steven is right that users will just need to explicitly cast heterogeneous dimensionless quantities to homogeneous ones which are well-defined and convertible to the underlying value_type... 1.0*CGS::dyne/SI::newton -> quantity< unit<dimensionless_type,[mixed CGS/SI system]> >, not convertible to double quantity<SI::dimensionless>(1.0*CGS::dyne/SI::newton) -> convertible to double At least this is consistent with the treatment of heterogeneous units (which will be better documented any time now...) throughout the remainder of the library... Matthias

Matthias Schabel said: (by the date of Thu, 5 Apr 2007 11:00:00 -0600)
At least this is consistent with the treatment of heterogeneous units (which will be better documented any time now...) throughout the remainder of the library...
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 Kozicki |

At least this is consistent with the treatment of heterogeneous units (which will be better documented any time now...) throughout the remainder of the library...
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.
I'm going to implement a function for getting conversion factors; something like conversion_factor<CGS::dyne,SI::newton>() The syntax Steven described should also work : quantity<SI::dimensionless>(1.0*CGS::dyne/SI::newton) Matthias

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

Matthias Schabel said: (by the date of Thu, 5 Apr 2007 15:49:19 -0600)
std::cout << conversion_factor<double>(CGS::dyne,SI::newton) << std::endl;
great, thanks :)
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.
oh, I prefer conversion_factor<> too. -- Janek Kozicki |
participants (2)
-
Janek Kozicki
-
Matthias Schabel