next up previous contents
Next: Using function_cmp Up: Gotchas Previous: Gotchas   Contents

Exponentiation

The exponentiation operator is one of which to be very careful. In all answers which a student provides, there is no difference in whether a caret (^) or ** is used to denote exponentiation. In any FEQ statement it is fine to use ^ instead of **. Within math mode in TEX it is required to use the caret. However, outside of these contexts, you should always use **. This includes generic Perl statements as well as your answers (in the ANS construct). Generally, the PG problem will compile, but the results will be unpredictable.

Also, a standard programming error is being cavalier with non-integral exponents. We all know that $ (-2)^{2/3}$ is a perfectly fine real number, however most programming languages (Perl included) will evaluate this via $ e^{(2/3)\log(-2)}$ leading to certain difficulties.

When using variables for exponents in a TEX expression (i.e within \( ... \) or \[ ...\]) , always use braces around the variable. For example write 3^{$n} instead of 3^$n. In this example if $n = 2, both expressions give what you would expect but if $n=22, the first gives 3^{22} while the second gives 3^22. TEX interprets the latter as ``3 squared times 2'', not as ``3 to the twenty second power''.


next up previous contents
Next: Using function_cmp Up: Gotchas Previous: Gotchas   Contents
Thomas R. Shemanske 2002-03-05