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=-1.3 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1dd28d5040ded1f8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-15 03:02:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: "Grein, Christoph" Newsgroups: comp.lang.ada Subject: Re: Announce: Grace project site operational Date: Wed, 15 May 2002 11:58:56 +0200 (MET DST) Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii X-Trace: avanie.enst.fr 1021456923 62729 137.194.161.2 (15 May 2002 10:02:03 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Wed, 15 May 2002 10:02:03 +0000 (UTC) Return-Path: X-Authentication-Warning: mail.eurocopter.com: uucp set sender to using -f Content-MD5: LCPy3QLEbeGtKPT1JU/COA== X-Mailer: dtmail 1.2.1 CDE Version 1.2.1 SunOS 5.6 sun4u sparc Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.8 Precedence: bulk X-Reply-To: "Grein, Christoph" List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:24081 Date: 2002-05-15T11:58:56+02:00 From: "Martin Dowie" > "Hyman Rosen" wrote in message > news:3CE15D0A.3050100@mail.com... > [snip] > > I first saw this idiom in _Scientific and Engineering C++_ > > by Bartion & Nackman. > > > > template > > struct Unit > > { > > RepType value; > > explicit Unit(value) : value(value) { } > > Unit operator+(Unit other) > > { return Unit(value + other.value); } > > Unit operator-(Unit other) > > { return Unit(value - other.value); } > > }; > [snip] > > Didn't someone post an Ada units package similar to > this a while back (> 1 year)?.. This is a theme that at least once a year re-appears. There is somewhere in Dabid Botton's AdaPower a paper by me about these physical types with a reference to a more detailed paper how my company handles this in several ebedded real-time avionics projects. All "solutions" to this problem I've seen so far can be split into three methods: 1. Use subtypes with proper names like Meter, Kilogramm, Ohm just for documentation, i.e. no type checking. 2. Use strong types with separate types and operator overloading. This only works (except for broken exponents like 1/2 as in sqrt (Meter); yes, these occur quite often with rational values 1/2, 1/3, 3/2, 4/3 just to name some) for limited subsets of SI units (two or three). 3. Discrimiated types with dimensions carried as discriminants. This is the most general method which, if rational (not integer) arithmetic is applied to exponents, but is run-time intensive, so possibly not applicable to real-time. There is a fourth method, preprocessors. And a fifth, if you create a language that can handle dimensions. My feeling is that method 1 should be the preferred one. two is out (expontial explosion of number of operations, rational exponents cannot be handled), 3 if execution time does not matter. In theoretical phycial work, dimensionless forms of the equations are preferred after all.