More on semantics of opPow: return type

Bill Baxter wbaxter at gmail.com
Mon Dec 7 14:41:23 PST 2009


On Mon, Dec 7, 2009 at 2:30 PM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> Lars T. Kyllingstad wrote:
>>
>> The fundamental reason why I want opPow so badly is in fact not even how
>> often I use it. If that was the case, I'd want a special "writefln" operator
>> as well. The main reason is that exponentiation is such a basic mathematical
>> operation, right up there with addition and multiplication, that it deserves
>> an operator of its own.
>
> Hmmm. Addition, subtraction, multiplication, and division with remainder are
> all closed over integers. Power isn't. It's not even closed over real
> numbers. That makes it quite special and quite non-basic.

Uh, but a/b is not a "division with remainder" operator.  It's just
division-with-a-remainder-silently-ignored.
If you want to define pow in the same way as a "pow with remainder but
with the remainder ignored" then there's nothing stopping you.

    1^^-1 == 1
    2^^-1 == 0
    4^^(1/2) == 2
    5^^(1/2) == 2

Though I'd rather go the other direction and make the
remainder-dropping integer division use a different symbol a la
Python.

--bb



More information about the Digitalmars-d mailing list