Re: Varaibles with units
- From: Walter Banks <walter@xxxxxxxxxxxxx>
- Date: Sat, 16 Feb 2008 06:32:09 -0500
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
.
- References:
- Varaibles with units
- From: Malcolm McLean
- Re: Varaibles with units
- From: cr88192
- Varaibles with units
- Prev by Date: Re: Varaibles with units
- Next by Date: Re: Varaibles with units
- Previous by thread: Re: Varaibles with units
- Next by thread: Parallelizing the FFT Algorithm?
- Index(es):
Relevant Pages
|