On Friday, 24 January 2014 at 19:03:59 UTC, Walter Bright wrote:
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.
So, was Andrei wrong as he claimed b would be "int" in my first example?

byte a = -128;
auto b = -a;

Or is changing byte to int no typechange?!?

BTW, Python has what you want - runtime overflow automatically fails over to bignum. But Python is a slow language.
It was someone else who wanted to start a discussion over such a feature in D.

I'm fine with the safe signed type I've developed.
The only flaw in my struct for now is that I'm not able to overload opCmp in such a way that NaN compared to anything else would always be false (either < or >= is true because they can't be overloaded separately) :-/ But checking for NaN before any calculation is always the better way, so that flaw hits not too hard. I will do some performance checks to see how "slow" this will make some heavy calculations in reality.

Reply via email to