Notes 

(0000258)

mgiuca

20100401 16:05


Irk... that patch is wrong. The "Wrapped" value is not necessarily in int range (I thought it worked because conversion to int truncated anyway, but you can't assume that since it's specified as undefined.)
Positive integers in range 2^31 to 2^321 need to become negative, and vice versa for negative integers in range 2^311 to 2^32. This is tricky to do with integer bit operations since they specifically *don't* wrap values. I'm thinking it'll be easier to use mod/rem but I'll have to think hard about it. Does anyone have a better mathematical formula for wraparound conversion?
Also, is there a test suite I need to write test cases for? 


(0000259)

mgiuca

20100401 16:14


A valid formula appears to be (at least for 2's complement):
((X + int_max + 1) `mod` (int_max+1) * 2)  int_max  1
Is this overly complicated? 


(0000260)

mgiuca

20100401 18:10


Added a new patch (integer2.patch) which uses the above formula.
I'm aware that there is a formal patch review process, and this isn't it. I'm just seeing if anyone is interested first. 



