small integer powers -- use pow() or explicit multiplication?

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.
.
 
K

Keith Thompson

JosephKK said:
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.

Well, for certain values of "better than".

IEEE 754 32-bit floating-point does not meet the range and precision
requirements for double.
 
J

JosephKK

Well, for certain values of "better than".

IEEE 754 32-bit floating-point does not meet the range and precision
requirements for double.

OK, I think it may make the range (10^+/- 37) but does not meet
precision or resolution (10 decimal digits per n1256 para 5.2.4.2.2)
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top