Re: TIB: program speed
[Prev][Next][Index][Thread]
Re: TIB: program speed
Yes, when a calculator encounters an If statement with a False boolean,
it ignores the next command completely. When you combine the test and
the function in one line, you run the risk that you can slow the
calculator down. I did something similar to that on Aim with the arrow
keys. The TI-92 does not treat booleans as 1 or 0 like the other
calculator, but as a symbol, so such a command would be impossible. I
used the keycode to do the following:
( -> = store command; (-) = negative symbol)
While keycode=337 or keycode=340
sign(keycode-338) -> t
angle+t -> angle
If abs(angle)>90
b[i,2]-181*t -> angle
PxlText " ",2,37
PxlText string(angle),2,55-6*dim(string(angle))
getKey() -> keycode
EndWhile
Here's what it replaced:
While keycode=337
PxlText " ",2,37
angle-1 -> angle
angle< (-) 90
angle+181 -> angle
PxlText string(angle),2,55-6*dim(string(angle))
getKey() -> t
EndWhile
.
.
.
While keycode=340
PxlText " ",2,37
angle+1 -> angle
If angle>90
angle-181 -> angle
PxlText string(angle),2,55-6*dim(string(angle))
getKey() -> keycode
EndWhile
The numbers 337 and 340 are the keycodes for left and right,
respectively. By subtracting 338 from the keycode, I get a negative
number for left and a positive for right. The calculator then adds t to
the angle, decreasing it if it's negative (left) or increasing if it's
positive (right).
If the angle ever exceeds 90 degrees in either direction, the t is then
used to move the angle 180 degrees in the other direction to correct for
it. Otherwise it is ignored. The resulting angle is then displayed on
the graph as text just before receiving the Getkey command and starting
all over.
This method may be slightly slower than the conventional method, but the
size of the programming is nearly halved. In the conventional method, I
would still have to perform the subtraction or addition, so I thought it
was worth the effort.
In summation, it is better to make the single line conversion if your
calculator must do math in both true and false cases. Otherwise, use
the test and let it ignore any unnecessarily heavy math. This is the
balance all of you program authors must face: speed, power, or
compactness.
Tavis
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
Follow-Ups: