Numeric limits tracking

Walter Bright newshound2 at digitalmars.com
Sun May 12 18:03:31 PDT 2013


On 5/12/2013 5:00 PM, Manu wrote:
> So, here's an issue that constantly drives me nuts, and an elegant solution
> seems so do-able.

It's a form of "data flow analysis". This is done by the optimizer, although it 
doesn't track ranges.

It isn't quite as simple as you suggest, there are issues like dealing with 
arbitrary control flow.

   x &= 0xFFFF;
   short s = x; // Error! (but we know x is 0 .. 65535)

Ok, but what about:

   x &= 0xFFFF;
   while (expr) {
       short s = x;
       x += 1;
   }

There's a forward reference going on. We cannot semantically evaluate s=x until 
we semantically evaluate the rest of the function in order to know that x is or 
is not reassigned.


More information about the Digitalmars-d mailing list