From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9d303864ae4c70ad X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-04-13 03:56:07 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!dialin-145-254-039-112.arcor-ip.NET!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Expressing physical units (Was: Reprise: 'in out' parameters for functions) Date: Tue, 13 Apr 2004 12:55:50 +0200 Organization: At home Message-ID: References: <5ad0dd8a.0404090512.15af2908@posting.google.com> <5ad0dd8a.0404100507.729d3577@posting.google.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dialin-145-254-039-112.arcor-ip.net (145.254.39.112) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de 1081853765 1419266 I 145.254.39.112 ([77047]) User-Agent: KNode/0.7.2 Xref: archiver1.google.com comp.lang.ada:7041 Date: 2004-04-13T12:55:50+02:00 List-Id: Russ wrote: > "Dmitry A. Kazakov" wrote in message > news:... >> Russ wrote: >> >> > By the way, I work in the field of air traffic management (ATM), and >> > I'd really like to see a practical way to guarantee units consistency. >> > The general mks system is inappropriate for ATM. The traditional units >> > for ATM are nautical miles (nmi) for horizontal length, and feet (ft) >> > for altitude. That won't change in our lifetimes -- and probably >> > never. As for time, it can be in seconds, minutes, or hours. >> > Horizontal speed in usually given in terms of knots (kn), which is >> > nmi/hr, but altitude rate is usually given in terms of ft/min. Heading >> > is normally given in degrees. >> > >> > In my experience, the most common units problem is confusion between >> > degrees and radians. Radians are preferable for use inside programs, >> > but degrees are preferable for I/O. This problem really needs to be >> > licked once and for all. >> >> It does not differ from [m] vs. [ft]. The dimension of radian is [1] = >> m**0*A**0*s**0... The dimension of degree is [Pi/180]. No magic here. >> More difficult is Celsius degree vs. K, which AFAIK cannot be solved >> using C++ templates. > > I know it can be done in C++, but I thought we were talking about doing it > in Ada. > > By the way, what the heck is "m**0*A**0*s**0..."? Any unit system is built upon some standard set of measures (base units). This set is pretty arbitrary from a physics point of view, but in SI it was selected to be m, A, s, kg, K, cd, mol. A dimension of any derived unit is then a product of powers of the base units. For example, the dimension of acceleration is m*s**(-2). When all powers are 0, we have a "dimensionless" unit, like radian is. Now to templates and C++. You are wrong thinking that units can be properly done in C++. What indeed can be, is a tiny part of what is really necessary. Consider the following issues: 1. Shifted units, like Celsius degree. 2. Dealing with units unknown at compile time. How would you communicate with a data base, or develop a gauge widget, or write a unit calculator? How to write a unit I/O package? 3. Dealing with multiple unit systems. The C++ solution actually works in SI. It means that a measure in [ft] has to be converted to [m]. It is OK as long as: 3.a. There is no range problems. In an emedded system one could use a fixed arithmetics with would overflow if the distance is measured in [m], but work fine for [km]. 3.b. One can ignore inevitable precission loss caused by unit conversions. This might be critical for some applications. 5. How to handle logarithmic units and other non-linear scales? 6. Container problem. Surely a vector, matrix etc of dimensioned values should have a dimension. Possibly it could be handled by templates, but I am afraid it would not be so easy. 7. Any generic (template) solution would make everything based upon it also generic. -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de