Dear all, I have an issue with scaled units. I tried to implement a non-rational scaling of units adapted from scale<> class (all in boost::units namespace): template<class Derived> struct non_rational_scale { static const unsigned long base = 10; typedef boost::units::static_rational<0> exponent; typedef double value_type; static double value() { return Derived::value(); } static std::string name() { return Derived::name(); } static std::string symbol() { return Derived::symbol(); } }; struct electron_volt_scale : non_rational_scale<electron_volt_scale> { static double value() { return 1.60218e-19; } /* elementary charge in Coulombs */ static std::string name() { return "electron volt"; } static std::string symbol() { return "eV"; } }; typedef make_scaled_unit<si::energy, electron_volt_scale>::type electron_volt; This works fine in one direction: quantity<si::energy>(1.*electron_volt()); /* gives 1.60218e-19 J. */ However, in the other direction quantity<electron_volt>(1.*si::joule); /* gives 1 eV */ I guess, that I need some specialization for non_rational_scale to workout the correct scaling factor in the reverse direction. Thank you for your help, Matthias
participants (1)
-
Matthias Wohlgemuth