When an expression involving an exponent evaluates consistently to 1 when other values are expected, examine the exponent. If the exponent consists of an expression as in the following example:
aa = expr1 ^ (bb / cc);
If both variables bb and cc have integer values, then the division performed is integer division and the result is an integer. Furthermore, if bb is less than cc, then the result is zero. Thus, irregardless of the value of expr1, the result of the exponentiation is 1. To cure this problem, convert either bb or cc to floating point by adding 0.0:
aa = expr1 ^ (bb + 0.0 / cc);
Print Function
Sometimes you get truncated output from a print function. Since QTAwk follows the Awk convention of allowing the parenthesis enclosing the argument list for the print function to be optional, if the first argument in the print function call is a parenthesized expression QTAwk will parse the first left parenthesis as the opening parenthesis for the print function argument list.
For example, in the following print function, the first argument is chosen depending on the value of aa:
print (aa ? "string 1 true value" : "string 1 false value"),b,c,;
The output consists of either "string 1 true value" or "string 1 false value" only. The values of the variables b and c are not output. QTAwk parses the above statement as:
expr1,expr2,expr3;
With:
expr1 == print (a ? "string 1 true value" : "string 1 false value")
expr2 == b
expr3 == c
To illustrate what is happening, modify the above statement to:
print print (aa ? "string 1 true value" : "string 1 false value"),b,c,;
If a == 1, b == 1 and c == 10, the output from this statement will be:
string 1 true value
19 1 10
The first line is the output from the second "print" function which returns a value of 19, the number of characters output. The second line is then the output from the first "print" function, the value returned by the second "print" function followed by the value of 'b' followed by the value of 'c'.
To correct this problem, do not omit the optional parenthesis enclosing the print function argument list. The solution for the above statement would be:
print ((aa ? "string 1 true value" : "string 1 false value"),b,c,);