Re: Varaibles with units





cr88192 wrote:

"Malcolm McLean" <regniztar@xxxxxxxxxxxxxx> wrote in message
news:87-dnTj8MrwngyvanZ2dnUVZ8hmdnZ2d@xxxxxxxxx
This shouldn't languish in a subthread.

Many if not most of the variables we use in programming have units
attached to them. For instance distances, amounts of money, time, weight
or temperature.

The question is how to keep the units attached to the numbers, to rule out
any illegal calculations, such as adding a time to a distance. Dividing a
distance by a time interval is of course OK - that leads to a velocity.


one possibility: types.

major detractor: each and every type added to a system increases the
complexity by a factor somewhat larger than the cost of adding the type
itself (due to the interaction between each type and any potentially related
types).

so, though possible, it would lead to a good deal of types.

another posibility is that of defining a basic set of related types (length,
time, mass, volume, ...), with some internally defined "base units", to
which all subtypes are normalized (decimeter, second, kilogram, liter, ...).
this way, we can use a simple set of calculations.

now, when we want the result, we request it in terms of a specific unit
(most common WRT calculations), get it in terms of some default unit, or in
terms of some best-fit unit (usually for something like converting the unit
to a printable string).

this is most computationally practical IMO (though specific-unit
calculations could be useful, they are far less "practical").

I like normalized values for storage and calculations with units conversion
for I / O operations

Regards,

--
Walter Banks
Byte Craft Limited
Tel. (519) 888-6911
Fax (519) 746 6751
http://www.bytecraft.com
walter@xxxxxxxxxxxxx





.



Relevant Pages

  • Re: My New Website
    ... > you wilol get the distance between the centroids ... geometrical construction made up by you without any foundations in physics. ... And did you find any experimental evidence for this electron ... QM calculations are just the oposite of hand waving. ...
    (sci.physics)
  • Re: SR time dilation on remote objects ?
    ... >>How often do I need to tell you that the velocities in cosmology ... which is *not* identical to the distance definitions used in SR! ... > suffices to explain the so-called tiring of light in a stable universe. ... with the data presented in this graph, feel free to show your calculations. ...
    (sci.astro)
  • Re: Varaibles with units
    ... Many if not most of the variables we use in programming have units attached to them. ... The question is how to keep the units attached to the numbers, to rule out any illegal calculations, such as adding a time to a distance. ... to use most physics calculations directly, requires the assumption of a "square" relation between the various units, and if these relations are not maintained, then everything goes wonky, however, externally it is often convinient to use whatever units are most convinient at the time. ...
    (comp.programming)
  • Re: What next when the hyperfocal is wrong?
    ... focusing distance are therefore highly subjective. ... figures of 13.5 feet to 174 feet is a joke. ... there will be no difference in sharpness between the two that anyone ... calculations as if they were definitive, ...
    (rec.photo.equipment.35mm)