Negating a short?

Andy Valencia dont at spam.me
Tue Nov 5 17:32:00 UTC 2024


I have a template which has a bit where it negates a value.  This 
works well until it encountered a short, where ldc2 complained:

integral promotion not done for -val

I ended up with this, but is negating a short really this 
problematic, or did I miss something?

     static if (!__traits(isUnsigned, T)) {
         if (val < 0) {
             static if (__traits(getPointerBitmap, T)[0] < 
int.sizeof) {
                 val = cast(T)(-(cast(int)val));
             } else {
                 val = -val;
             }
         }
     }

As always, thanks much in advance,
Andy



More information about the Digitalmars-d-learn mailing list