D arithmetic problem

Tim Matthews tim.matthews7 at gmail.com
Tue Jun 2 19:48:02 PDT 2009


davidl wrote:
> Following two piece of code demonstrate different behaviors currently.
> 
> import std.stdio;
> void main()
> {
>     uint v;
>     v=31234;
>     byte t= -1;
>     v |= t;
>     writefln(v);
> }
> 
> Output:4294967295
> 
> import std.stdio;
> void main()
> {
>     uint v;
>     v=31234;
>     byte t= -1;
>     v |= cast(ubyte)t;
>     writefln(v);
> }
> 
> Output:31487
> 
> I would always want the second result. What's your opinion?
> 
> 

should be in d.learn but try this:

import std.stdio;
void main()
{
     uint v;
     v=31234;
     ubyte t= -1;
     v |= t;
     writefln(v);
}



More information about the Digitalmars-d mailing list