www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: More on semantics of opPow: return type

Andrei Alexandrescu Wrote:
 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.

Oh, for polysemous values :-) I'm somewhat inclined to say that the result type should be the same as the original type, and if the user wants other behavior they can cast. That keep the simple cases simple, and makes the fancy cases explicit. I'd really rather not have the language trying to second guess me by converting my int to a long just because I used an operation that might overflow.
Dec 08 2009