More on semantics of opPow: return type

Bill Baxter wbaxter at gmail.com
Tue Dec 8 09:07:58 PST 2009


On Tue, Dec 8, 2009 at 12:01 AM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:

> What I'd like would be a solid rationale for the choice. Off the top of my
> head and while my hat is off to your math skills and experience, I have
> trouble understanding the soundness of making int^^int yield an int, for the
> following reason:
>
> For all negative exponents, the result is zero, except when the base is 1 or
> -1. So I guess I'd suggest you at least make the exponent  unsigned - the
> result is of zero interest (quite literally) for all negative exponents. If
> that behavior is interesting, it would be great if you provided a rationale
> for it.

The rationale (exponentiale?) for it is consistency.  Yeh, it's of
zero interest.  But it's simple and consistent and doesn't require a
bunch of new rules.  In the world of ints, small positive powers
really are the only interesting case.  (And not just two and three --
sometimes you'll see 2**N used to compute buffer sizes in Python.   Or
at least that's what I observed in the code searches people posted.
Arguably a more direct expression of intent than 1<<N.)

You seem to be gunning to make some unneccesarily complicated rules up
to handle a case that's not really important, but then at the same
time argue that things are getting too complicated so we better axe
the whole feature.  It doesn't really make sense.

To make a comparison, << and >> aren't very useful for floating point
numbers, does that mean they shouldn't be in the language?  In
contrast  ^^ is useful for both floats and ints with small positive
powers.  No, not all ints, but that's better versatility than << and
>> at least.

> One small nit is that the exponential function is increasing very rapidly,
> much faster than multiplication. So yielding a long may actually be
> justified. (Some people would argue 32-bit multiplication is in the same
> league and ought to yield 64-bit results.) But then again, most uses of ^^
> only raise things to small powers such as 2 and 3.

Yep, or raising 2 to something < 32.

--bb



More information about the Digitalmars-d mailing list