From: Kevin Olbrich Date: 2006-08-24T04:38:23+09:00 Subject: Re: Ruby Units On Thursday, August 24, 2006, at 3:47 AM, Calamitas wrote: >On 8/23/06, Paul Lutus wrote: >> Peter Vanbroekhoven wrote: >> >> / ... >> >> >> 3. Facet Units doesn't seem to do temperature conversions. Maybe it >> >> does, but I can't find any documentation on it. >> > >> > It doesn't as temperature conversions are ill-defined. >> >> No, actually, temperature conversions are perfectly well-defined. >> Unfortunately, absolute temperature conversions require two mathematical >> operations instead of one (a multiplier and an offset), which sets them >> apart from nearly all other conversions. It even sets them apart from >> temperature differential conversions. >> >> > As you know, >> > both absolute temperatures and temperature differences have the same >> > unit. Any operation on two temperatures expressed in different units >> > cannot be correct for absolute temperatures and temperature >> > differences. >> >> That is because converting a temperature differential is not the same as >> converting a temperature. But each of the operations is clearly defined. >> >> > This is an inherent problem, so we had three choices: do >> > no conversions, use the conversion for absolute temperatures, or use >> > the conversion for temperature differences. >> >> There is a third choice -- convert temperatures and temperature >> differentials separately. Name one absolute temperatures, and the other >> delta-t or something similar. >> >> It is basically a Calculus issue. You may know that taking a differential >> (or a derivative) involves the loss of information, and when the converse >> operation (integration, a term only loosely applicable here) is >>performed, >> a constant (usually unknown) is included to remind the practitioner about >> the lost information. In the same way, moving from a temperature to a >> differential of temperature loses information, so the reciprocal >>operation >> (difference to absolute) must be carefully handled (when it can be >> performed at all). >> >> Someone versed in Calculus wouldn't think of mixing functions and their >> derivatives without being vigilant that they represent different things. >> The temperature conversion problem should be looked on in the same way. >> >> > We chose the first of >> > these three. We're open to additional ideas on this. >> >> Well, this is just something to think about. I've written a lot of unit >> conversion routines over the years and I haven't considered handling >> temperatures and temperature differentials separately, but it's an >>obvious >> solution. > >We have considered this option too, but because I started by saying >that both temperatures and temperature differentials have the same >units, I didn't arrive at that option in my reasoning. If I remember >correctly, we discarded this option because it was a bit weird for a >simple units library. This actually goes beyond the units part, it is >about interpretation. It's like you say, it's a calculus-y issue (I >think it's actually an algebra issue as it is not differentiation, but >that's not important), and we felt that that belongs in a >calculus/algebra/scientific library. So let me refine my statement >above: conversions of temperatures consisting only of a value and a >temperature unit are ill-defined. More information is needed, and we >felt back then that it should not be part of a units library. Of >course, this means we can do no conversion, so I'm considering >changing my opinion on this. > >> I just noticed something. The Linux utility "units" handles both >>temperature >> and temperature differences, and they are distinguished by syntax: >> >> $ units "tempC(0)" tempF # absolute temperature >> 32 >> >> $ units "32 degF" degC # temperature difference >> * 17.777778 >> / 0.05625 >> >> So it seems it has been done. > >We considered something like this too, but what bothers me is that >tempC, tempF, degC and degF are no actual units. > >I think this is an issue with the people who started this library both >being perfectionists. None of the solutions we could think of, are >perfect. > >I'll see if I can get a tempC-degC like scheme to work, and then we >can still decide this afterwards. > >Peter > After thinking about this a bit, here are a few things that might be handy. 1. Temperature is not a unit, it's a property that is measured in degrees. 2. That measurement is always relative to a fixed value, so really all temperature values are differences 3. The number of real calculations in which you would want to use the absolute temperature instead of some delta of temperature is exceedingly small. Consequently, the approach I am currently taking is to * represent all temperatures as differences. * provide a helper function that does the conversion from one temperature scale to another for those times when you really need it. * document the heck out of this So far it seems to work pretty well _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.