diff --git a/src/Urbit/Deconstructor.elm b/src/Urbit/Deconstructor.elm index 4a9f31c..62be6e6 100644 --- a/src/Urbit/Deconstructor.elm +++ b/src/Urbit/Deconstructor.elm @@ -15,6 +15,7 @@ module Urbit.Deconstructor exposing , run , runBytes , sig + , signedInt , tape , tar ) @@ -96,6 +97,19 @@ int = ) +signedInt : Deconstructor (Int -> a) a +signedInt = + int + |> fmap + (\i -> + if Bitwise.and 1 i == 1 then + -(Bitwise.shiftRightBy 1 (1 + i)) + + else + Bitwise.shiftRightBy 1 i + ) + + float32 : Deconstructor (Float -> a) a float32 = Deconstructor diff --git a/tests/Test/Urbit.elm b/tests/Test/Urbit.elm index 6d966f4..d3f31e5 100644 --- a/tests/Test/Urbit.elm +++ b/tests/Test/Urbit.elm @@ -139,6 +139,15 @@ tests = ) ) ] + , test "[--8 -8]" + (\() -> + Expect.equal + (Just ( 8, -8 )) + (D.runBytes + (D.cell D.signedInt D.signedInt |> D.map Tuple.pair) + (Bytes.fromByteValues [ 0xC1, 0x20, 0xE4, 0x01 ]) + ) + ) ] ]