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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham 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 09:50:01 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!newsfeed2.telusplanet.net!newsfeed.telus.net!nntp.abs.net!ash.uu.net!spool.news.uu.net!not-for-mail Date: Wed, 14 Apr 2004 12:49:24 -0400 From: Hyman Rosen User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Expressing physical units (Was: Reprise: 'in out' parameters for functions) References: <5ad0dd8a.0404090512.15af2908@posting.google.com> <5ad0dd8a.0404100507.729d3577@posting.google.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1081961393.799312@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1081961393 14641 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:7099 Date: 2004-04-14T12:49:24-04:00 List-Id: Dmitry A. Kazakov wrote: > But C++ does not allow double as a template parameter. That's merely an implementation detail; you simply use a pair of integers to represent a fraction. > Why? It is no matter. Shifted units represent linear scales: > x = a * y + b > The dimension of a and b may have any powers. No matter? What is the meaning of multiplying degrees Celsius by degrees Farenheit, or squaring degrees Celsius? > Because there can be a universal solution with zero-overhead in static case. Zero overhead in space as well? I assume this is another one of those cases which will require object tags to live in the classwide pointers instead of in the objetcs themselves? > (:-)) Why is my unit output procedure funny? > 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. You need to guide the type of the result, since it could be either. So it's simpler to forbid the addition of differently scaled units, and require the user to convert one operand to the type of the other. Or, given that you're doing it in C++, it's easy to write traits templates that would represent rules for preferring one scale over another. > 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. You represent scale and logness as template parameters. Then you just need to be able to convert one type to another (and if we're talking about addition of log-scaled quantities, we have to convert out anyway) for addition, and to write a specialized multiplication routine that takes two log-scaled units and adds their values, for example. I doubt that anyone is going to build such a complicated system of units, but it could be done in principle. > 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? As I have already said, we are relying on knowing a fixed set of units within the program. Then the problem is no different than communicating any other fixed set of record types. > Consider a large finite element library. If that has to be used for > physical values, then the whole library has to be generic. So?