From: González Cuadrado, Miguel (mgcuadrado_at_[hidden])
Date: 2003-10-20 06:06:02
This posting went apparently unnoticed, but it may be of interest to the "Dimensional Analysis" thread. As far as I can tell, the units library I have developed fits pretty well in the discussion. It has a Dimension "metatype", which is a type templatised on the seven fundamental dimensions (length, time, and so on). A magnitude with a dimension is represented as a type templatised on the underlying quantity type (double, float, three-dimensional vector...) and the dimension. Units are simply magnitudes with constant values. I have chosen to use the SI units as fundamental. As has been pointed, it doesn't matter if you use SI or English or any other unit system, since you are not supposed to really "see" the raw value stored. Only fundamental units can be constructed "a priori", and derived units are constructed using fundamental units, as in "Unit<length> inch=.0254*meter;". Magnitudes can only be constructed by using units, as in "Magnitude<double, length> width=3.*inch;". They can only be inspected (by the user) by comparing to units or other magnitudes, as in "double width_in_miles=width/mile;" (a different syntax may be "double width_in_miles=convert(width, mile);").
The temperature issue is dealt with by providing only "temperature difference" units, since these are convertible by factors, like the other units. True temperature quantities are computed with using "scale" types. A scale type is analogous to a unit, but it includes an offset (e.g. 273.15 for degrees C).
Every computation involving magnitudes is checked by the compiler for dimensional soundness. That is, multiplications produce magnitudes with new dimensions, sums and assignments are only allowed if both magnitudes have the same dimension, and so on.
By the way, IMHO the question about mixing gasoline is out of scope, since it is an altogether different problem, with very different semantics: fundamental dimensions are not multiplied as in dimensional analysis, but summed. It doesn't even support the same set of operations (no subtraction, semantics for multiplication is obscure, no division...).
De: González Cuadrado, Miguel
Enviado el: lunes, 21 de julio de 2003 15:18
Para: Boost mailing list
Asunto: [boost] Static compile-time fractions
I have developed a small library that allows to do compile-time computations using rational numbers; it is heavily template-based. I use as a part of a units library (yet another), in which the dimension is encoded as seven rational numbers, one for the exponent of each of length, time, temperature and so on; each of these rational numbers is a template argument for a magnitude with dimension. (Fractional dimension units are used sometimes, for example for turbo engine analysis and simulation.)
The compile-time fractions library supports unary plus and minus, binary plus and minus, multiplication, division, and integer exponents, and always reduces numerator and denominator, i.e. (4/-6) -> (-2/3), which makes it possible to test for equality. If there is interest in this library, I will try and get it into boost's design criteria. Please let me know.
Este correo electrónico y, en su caso, cualquier fichero anexo al mismo, contiene información de carácter confidencial exclusivamente dirigida a su destinatario o destinatarios. Queda prohibida su divulgación, copia o distribución a terceros sin la previa autorización escrita de Indra. En el caso de haber recibido este correo electrónico por error, se ruega notificar inmediatamente esta circunstancia mediante reenvío a la dirección electrónica del remitente.
The information in this e-mail and in any attachments is confidential and solely for the attention and use of the named addressee(s). You are hereby notified that any dissemination, distribution or copy of this communication is prohibited without the prior written consent of Indra. If you have received this communication in error, please, notify the sender by reply e-mail
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk