Re: Elegant way to eliminate large conditional?
Re: Elegant way to eliminate large conditional?
- Subject: Re: Elegant way to eliminate large conditional?
- From: Thomas Hopper <email@hidden>
- Date: Sat, 04 Jan 2003 15:09:47 -0500
On 1/3/03 10:50 PM, "Andrew Merenbach" <email@hidden> wrote:
>
Is there some (elegant) way to use a matrix-like setup (a
>
two-dimensional selector or even an array?) that, given two arguments
>
(a range of five numbers, for each of the temperature scales) will
>
execute a different one of 25 equations or selectors?
There is some code and some papers on the net, if you search for
"dimensional analysis" or "unit conversion."
From what little reading I've done on the subject, there are a number of
ways of going about this, including dimensional analysis. Usually,
dimensional analysis involves some rather ugly parsing, but I've seen one
representation using prime numbers, so all the unit manipulation boils down
to numerical operations.
You can also represent any unit as a vector, where the elements of the
vector are the powers of the units, then apply a transformation matrix
(though I haven't quite figured out how to generate the matrix, I think that
you should only need one for all transformations). The vector for a
temperature in Celsius might look like [1, 0, 0, 0, 0], while the vector
representing acceleration in m^2/s might look like [0, 0, 2, 0, -1].
Probably the simplest way, as was already mentioned, would be to have one
set of conversions to the default unit (C, m, s, kg, etc.) using case
statements, and another set from the default unit to the other possible
units (F, K, T, etc.).
I apologize if this isn't he most helpful reply, but perhaps it will
generate some ideas.
-Tom
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.