J
JosephKK
Following up to my own post rather than to any of the replies,
because they've all been helpful, and it's hard to know which
to single out for follow-up ....
By "small integer powers" here I meant that the exponent was
a small (non-negative!) integer. I didn't have in mind any
particular restrictions on the base (thing being raised to a
power), other than the obvious ones (some sort of integer or
floating-point).
The suggestion to tell students about both (or all) approaches
and let them make their own decisions is a good one. As for
penalizing them for making a different choice from the one I'd
make -- perish the thought! To me that would seem uncomfortably
close to those unpleasant stories I sometimes hear about faculty
in other disciplines who penalize students who aren't willing to
follow some party line, which -- well, no, perhaps best to stay
away from that soapbox.
There is some value in that approach. I would also require that the
students evaluate the potential loss of accuracy by the implicit
conversion(s) to float or double (and back). The pow(x,y) function is
defined on double; but double is not required to be better than IEEE
754 (32-bit) float.
.