symmetric signed types

Walter Bright newshound2 at digitalmars.com
Fri Jan 24 11:03:59 PST 2014


On 1/24/2014 2:40 AM, Dominikus Dittes Scherkl wrote:
> Ah, ok. Of course the small types always become int.
> But the problem would be the same with
>
> long a = long.min;
> auto b = -a;
>
> does this return ulong (which could hold the correct result) or long (and a
> wrong result)?

The negation operator does not change the type, and no operation changes the 
type as the result of particular runtime operand values.

BTW, Python has what you want - runtime overflow automatically fails over to 
bignum. But Python is a slow language.


More information about the Digitalmars-d mailing list