Brian Weed wrote: > Today, we converted a project from Lua v5.02 to v5.1.1, and we started > having a problem when converting double to int. > I have narrowed my problem down to code that has nothing to do with > Lua. But I still wanted to get other people's opinions about it. > > double d = 0xFFFFFFFF; > int n; > n = (int)d; > > // n now contains 0x80000000 On my system (Ubuntu Edgy Linux, gcc 4.1.2) n now containts 0x7FFFFFFF, which is what I would consider to be correct. > n = (int)(unsigned int)d; > > // n now contains 0xFFFFFFFF I get this too. I also consider this to be correct, because casting d to an unsigned int will fit, and will therefore not truncate the value; and casting an unsigned int to an int doesn't truncate (which I've never really understood). -- ╭─┈David Given┈──McQ─╮ "A line dancer near a graduated cylinder, the │┈ dg@cowlark.com┈┈┈┈│ blithe spirit inside some wheelbarrow, and a tomato │┈(dg@tao-group.com)┈│ are what made America great!" --- received via spam ╰─┈www.cowlark.com┈──╯
Attachment:
signature.asc
Description: OpenPGP digital signature