on master help sign in
Added signed integers
commit05d655450a0e3e12e34041d7eae36b3c608d73cf authoriko <mail@iko.soy> dateThu 1 Jun 2023, 17:34 (3 years ago) parentd4b214e
2 files changed+23
src/Urbit/Deconstructor.elm+14 tests/Test/Urbit.elm+9
src/Urbit/Deconstructor.elm+14
@@ -15,6 +15,7 @@ module Urbit.Deconstructor exposing
1515 , run
1616 , runBytes
1717 , sig
18+ , signedInt
1819 , tape
1920 , tar
2021 )
@@ -96,6 +97,19 @@ int =
9697 )
9798
9899
100+signedInt : Deconstructor (Int -> a) a
101+signedInt =
102+ int
103+ |> fmap
104+ (\i ->
105+ if Bitwise.and 1 i == 1 then
106+ -(Bitwise.shiftRightBy 1 (1 + i))
107+
108+ else
109+ Bitwise.shiftRightBy 1 i
110+ )
111+
112+
99113float32 : Deconstructor (Float -> a) a
100114float32 =
101115 Deconstructor
tests/Test/Urbit.elm+9
@@ -139,6 +139,15 @@ tests =
139139 )
140140 )
141141 ]
142+ , test "[--8 -8]"
143+ (\() ->
144+ Expect.equal
145+ (Just ( 8, -8 ))
146+ (D.runBytes
147+ (D.cell D.signedInt D.signedInt |> D.map Tuple.pair)
148+ (Bytes.fromByteValues [ 0xC1, 0x20, 0xE4, 0x01 ])
149+ )
150+ )
142151 ]
143152 ]
144153