www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/06/11/10:32:01

Date: Fri, 11 Jun 1999 09:29:26 -0500
From: Eric Rudd <rudd AT cyberoptics DOT com>
Subject: Re: libm sources from cyberoptics
To: djgpp-workers AT delorie DOT com
Message-id: <37611D45.CF7E694B@cyberoptics.com>
Organization: CyberOptics
MIME-version: 1.0
X-Mailer: Mozilla 4.05 [en] (Win95; U)
References: <199906110725 DOT JAA09883 AT mars DOT lu DOT erisoft DOT se>
Reply-To: djgpp-workers AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019