William Vetterling
03-05-2002, 01:42 PM
It has been the practice in creating the Numerical Recipes in C++ never to use integers or floats as though they were logical expressions, as in the following example:
int i=7;
if (i) printf("Hello, World!");
In C, the meaning of "if(i)" is "if (i != 0)", but in C++ the argument of an if-statement is supposed to be a true logical expression.
With that in mind, we notice a line in simplx.cpp, about 25 lines from the end, that reads:
if (kh >= 1 && l3[kh-1]) {
l3[kh-1]=0;
...etc...
This should read:
if (kh >= 1 && l3[kh-1] != 0) {
l3[kh-1]=0;
...etc...
Although the original code functions properly, we shall change it to the correct form. Let us know if you spot any other examples of improperly formed logical expressions.
int i=7;
if (i) printf("Hello, World!");
In C, the meaning of "if(i)" is "if (i != 0)", but in C++ the argument of an if-statement is supposed to be a true logical expression.
With that in mind, we notice a line in simplx.cpp, about 25 lines from the end, that reads:
if (kh >= 1 && l3[kh-1]) {
l3[kh-1]=0;
...etc...
This should read:
if (kh >= 1 && l3[kh-1] != 0) {
l3[kh-1]=0;
...etc...
Although the original code functions properly, we shall change it to the correct form. Let us know if you spot any other examples of improperly formed logical expressions.