06-25-2003, 10:30 AM
Many times when we're testing, we come across certain instructions that do not do what we want. What's worse is when they work for most data cases, but fail on other data for no apparent reason. Then we normally write the logic a different way and forget the problem. Let's try to warn our friends here of these weird things that happened to us.
I'll start the ball rolling by issuing a warning about Functional Operators, sometimes called Intrinsic Functions, or just called Functions, such as SQR, LOG, TAN, COS, and others.
Sometimes we derive a real neat way of doing something by using the above functional operators. Here's a few warnings:
1) First read the manual regarding the functional operator to find out what is the precision (integer, single, double) that is used in the calculation.
2) Avoid using multiple Functional Operators in the same statement. Because of the precision accuracy, having them in the same statement could give bad results for certain values of the data.
3) Run a complete test in a sample program using the entire range of data values that you intend using, to make sure that the code using these Functional Operators works in every case.
Another pitfall is using exponentiation. Watch out when you use an explicit value like 2^n. It's assuming its own precision. I had a piece of code that worked every time except for the following value:
The result was no.
I fixed it by placing the 2 in a variable called two, and then did
if two^n = 128 .....
*****
I'll start the ball rolling by issuing a warning about Functional Operators, sometimes called Intrinsic Functions, or just called Functions, such as SQR, LOG, TAN, COS, and others.
Sometimes we derive a real neat way of doing something by using the above functional operators. Here's a few warnings:
1) First read the manual regarding the functional operator to find out what is the precision (integer, single, double) that is used in the calculation.
2) Avoid using multiple Functional Operators in the same statement. Because of the precision accuracy, having them in the same statement could give bad results for certain values of the data.
3) Run a complete test in a sample program using the entire range of data values that you intend using, to make sure that the code using these Functional Operators works in every case.
Another pitfall is using exponentiation. Watch out when you use an explicit value like 2^n. It's assuming its own precision. I had a piece of code that worked every time except for the following value:
Code:
defint a-z
n=7
if 2^n = 128 then print "Yes" else print "no"
I fixed it by placing the 2 in a variable called two, and then did
if two^n = 128 .....
*****