[Quantity-users] Re: [Quantity-devel] temperature conversion
Brought to you by:
berndspeiser
From: <ber...@t-...> - 2004-07-11 15:20:18
|
Bernd Speiser wrote: > > What possible solutions do we have? > > (1) decide for one of the above - but which one? - and accept the situation > (2) remove DegreeCelsiusTemperature from TemperatureGroup and put it into a > new GT, simultaneously disallow operations between objects of same > dimension > but different variable type. This would require an explicit > conversion if > arithmetics between the types are desired, which would not be > possible with > the present constructors. I tried to solve the problem by separating Temperatures into ThermodynamicTemperature (in K and DegreeRankine, according to the Mills book), CelsiusTemperature, and FahrenheitTemperature, by updating the conversion and assignment operators in Variable (which was good to do anyway; before copy construction and assignment was certainly not strict enough), and by providing explicit conversion methods for the *Temperatures. Now, one can e.g. explicitly convert CelsiusTemperature into ThermodynamicTemperature before performing an addition. Then, of course, addition becomes commutative, although, e.g. the additions in CelsiusTemperature Tc2 (0.); ThermodynamicTemperature Tt3 (298.15); ThermodynamicTemperature Tt4a = Tt3 + Tc2; // prints 298.15 K (wrong) ThermodynamicTemperature Tt4b = Tc2 + Tt3; // prints 571.3 K CelsiusTemperature Tc4a = Tt3 + Tc2; // prints 25 oC CelsiusTemperature Tc4b = Tc2 + Tt3; // prints 298.15 oC (wrong) yield different results! On the other hand, ThermodynamicTemperature Tt5 = Tt3 + ThermodynamicTemperature (Tc2); ThermodynamicTemperature Tt6 = ThermodynamicTemperature (Tc2) + Tt3; yield the same result (571.3 K). So, in my opinion, in lieu of a possibility to disallow mixed expressions completely, there should be extreme care with such mixed cases, and explicit conversion should ALWAYS be used. Bernd -- ======================================================================= Bernd Speiser Institut f"ur Organische Chemie Auf der Morgenstelle 18 D-72076 T"ubingen Germany phone: +49-7071-2976205 (office) +49-7071-2976242 (laboratory) fax: +49-7071-295518 e-mail: ber...@un... Internet: http://www.uni-tuebingen.de/speiser ======================================================================= |