Mail Archives: djgpp-workers/1999/06/11/10:32:01
Martin Stromberg wrote:
> But the main objection is that mathematically it is undefined. It's not
> good to limit your perpective (which will hinder further exploration and
> letting the next generation grow up with the notion that 0^0=1 because
> the standard says it is).
>
> Finally does it matter? What behaviour does those who use it (in real life
> programming) want? Does it make it easier or more difficult for them if we
> _do_ define it as 1?
The mathematical utility of defining 0^0=1 seems to be mainly in cases where
the exponents range over the integers. Perhaps defining 0^0=1 would allow a
number of badly-coded programs to continue "functioning". However, I would
have a much easier time explaining to a beginner why his clumsy and inefficient
code to evaluate polynomials
poly = 0.;
for (i=0; i<=n; i++) {
poly += a[i]*pow(x, (double) i);
}
failed with a domain error, than I would have explaining to a conscientious
programmer why his check of errno failed to indicate a problem. (Actually, the
most conscientious programmer realizes that it is unwise even to call
pow(0.,0.), exactly because C90 does not guarantee what the return value will
be.)
A compromise would be to return pow(0.,0.)=1., but indicate a domain error.
I did indeed realize that there was a need to evaluate integer powers (since C
lacks FORTRAN's handy X**IY syntax), so I have provided the powi(x, iy)
function for this purpose. It was designed for speed, and (unlike the other
functions) has no explicit error checking. It quietly returns powi(0.,0)=1.
-Eric Rudd
- Raw text -