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-14 01:49:57 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!dialin-145-254-044-107.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: Wed, 14 Apr 2004 10:49:45 +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-044-107.arcor-ip.net (145.254.44.107) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de 1081932596 2293558 I 145.254.44.107 ([77047]) User-Agent: KNode/0.7.2 Xref: archiver1.google.com comp.lang.ada:7076 Date: 2004-04-14T10:49:45+02:00 List-Id: Hyman Rosen wrote: > Dmitry A. Kazakov wrote: >> 1. Shifted units, like Celsius degree. > > This can be done by adding an extra shift prameter. But C++ does not allow double as a template parameter. > You would also need > to describe the units system more thoroughly. The standard units can > appear in positive or negative powers, but you obviously cannot do this > with shifted units. Why? It is no matter. Shifted units represent linear scales: x = a * y + b The dimension of a and b may have any powers. >> 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? > > This requires a different solution. But that's OK. If many applications > do not need this dynamic behavior, then they stand to benefit from the > zero-overhead of the given solution. Because there can be a universal solution with zero-overhead in static case. >> How to write a unit I/O package? > > I demonstrated that in another post. You write a bunch of 'if' statements > whose conditions depend on the template parameters, and they are all known > at compile-time for a given unit. (:-)) >> 3. Dealing with multiple unit systems. > > You can add a scale factor template parameter for each dimension, and then > they will be different types, so the compiler will prevent you from adding > mm to cm, say. Not that is the problem. One can add 1 [mm] and 1 [cm], it is legal. The question is in which unit system the arguments are and the result will be. There could be a need to have both m,s,A,... and mm,h,kA,..., for reasons I explained before. >> 5. How to handle logarithmic units and other non-linear scales? > > By specializing the templates for these units to do the appropriate > operations. Ada does not have the concept of specialized templates, but > C++ does. I do not see how you could add x in meters of SI with y in ft of logarithmic scale using specialized templates. To represent scale you will probably need some pointer to the scale descriptor in your template. >> 7. Any generic (template) solution would make everything based upon it >> also generic. > > Modern C++ programmers see that as an opportunity, not a problem! I do not see any way of making a GUI or DB interface based on templates. Consider a distributed system with should have a communication protocol to exchange physical measures. How would you do it using templates? Consider a large finite element library. If that has to be used for physical values, then the whole library has to be generic. -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de