Thomas Matthews wrote:
Ravi Uday wrote:
ju**********@yahoo.co.in wrote:
what are lookup tables ? How can they be used to optimise the code ?
Its mainly used for bit fiddling.
See the FAQ's - 20.12 and 20.13
@ http://www.eskimo.com/~scs/C-faq/top.html
- Ravi
Wrong.
Many trigonomy (sp?) functions, such as sine and
tangent are implemented using lookup tables. To
my knowledge, this is not bit twiddling; but a
fast method for obtaining a result.
"Trigonometry." Easy to remember: "metry" is "measurement"
and "trigons" are "three-sided polygons," i.e. "triangles."
"Trigonometry" is "the measurement of triangles."
This is an interesting (or mildly interesting) topic in the
history of computing. In the Very Early Days when computational
power was remote, expensive, and slow, the economically effective
thing to do was to print tables of trigonometric functions, often
with "proportional parts" in the margins to assist more accurate
interpolations. Later, when automatic computers showed up, the
State of the Art switched to approximations by polynomials or
ratios of polynomials: the new machines didn't have much memory
for storing tables, but could grind out the computations at a
good enough rate to make themselves useful. Then memories got
larger, and it was back to the tables again: the computer would
store a fairly coarse table and use second- or even third-degree
methods to interpolate with good accuracy. Today the CPUs are
faster than the memory, so the practice has reverted to purely
computational methods. Tomorrow ... well, "Tomorrow and tomorrow
and tomorrow, creeps!" We do not know what tomorrow's economics
may bring to the practice of computing. What we *do* know is that
the Right Way has switched from A to B and back to A and again
to B -- and hence "conventional wisdom" is not a good predictor.
I personally wrote table-based trig functions as recently as
1979 (using one full circle == 65536 "bam," or "binary angular
measurement"). I would not do so today -- but I might do so
tomorrow; who knows where technological trade-offs may take us?
If the history of computing teaches us anything, it teaches that
we are in a fashion-driven industry -- and we don't know what
tomorrow's hemline lengths will be.
--
Eric Sosman
es*****@acm.org