core/intcode: fix unsigned to signed conversion function
authorKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 26 Oct 2021 16:11:06 +0000 (18:11 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 26 Oct 2021 16:11:06 +0000 (18:11 +0200)
nihav-core/src/io/intcode.rs

index 55c8f859dd9a2fbc43df7dc8fb891207659aaeea..f5d128216e802212b4a69ce9e9d4429b5d9a84e4 100644 (file)
@@ -142,7 +142,7 @@ fn read_gammap(br: &mut BitReader) -> BitReaderResult<u32> {
 }
 
 fn uval_to_sval0mp(uval: u32) -> i32 {
-    if (uval & 1) != 0 { -((uval >> 1) as i32) }
+    if (uval & 1) != 0 { -(((uval + 1) >> 1) as i32) }
     else               { (uval >> 1) as i32 }
 }