This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: __builtin_cpow((0,0),(0,0))
On 2005-03-09 12:45:57 +0100, Duncan Sands wrote:
> The problem is x^0.0 (real exponent), not x^0 (integer exponent).
Well, mathematically, you can distinguish these two functions:
powrr: RxR -> R (not defined on (0,0) in particular)
and
powrz: RxZ -> R (where powint(0,0) = 1)
and even other two functions, where R is replaced by C (the complex
numbers). Unfortunately, the C language doesn't distinguish them.
> Now in practice I can imagine that a language confuses x^integer and
> x^real by mapping them to the same function, or only provides a
> function for doing x^real. Perhaps this is the case with C?
Yes, and to compute complex^integer, you need to use cpow(), AFAIK.
I think this is the reason why cpow((0,0),(0,0)) should return 1,
just like pow(0,0).
> If so, then having 0^0.0 return 1.0 is a convenient hack to work
> around that mistake. On the other hand, ignoring such things as
> language standards and the weight of history, if there are separate
> functions for x^integer and x^real, then in my opinion the most
> sensible thing would be for 0^0 to return 1, and 0^0.0 to return
> NaN. This might confuse programmers though.
They would be two different mathematical functions, thus returning
different results should be OK. Anyway the C language has only one
function for that (I don't know about the other languages, though).
Moreover, the implicit conversions between signed and unsigned
integers in C are much more confusing.
--
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA
- References:
- __builtin_cpow((0,0),(0,0))
- Re: __builtin_cpow((0,0),(0,0))
- Re: __builtin_cpow((0,0),(0,0))
- Re: __builtin_cpow((0,0),(0,0))
- Re: __builtin_cpow((0,0),(0,0))
- Re: __builtin_cpow((0,0),(0,0))
- Re: __builtin_cpow((0,0),(0,0))
- Re: __builtin_cpow((0,0),(0,0))
- Re: __builtin_cpow((0,0),(0,0))