on master help sign in
Added signed integers
05d6554iko
src/Urbit/Deconstructor.elm+14
@@ -15,6 +15,7 @@ module Urbit.Deconstructor exposing
15 , run
15 , run
16 , runBytes
16 , runBytes
17 , sig
17 , sig
18+ , signedInt
18 , tape
19 , tape
19 , tar
20 , tar
20 )
21 )
@@ -96,6 +97,19 @@ int =
96 )
97 )
97
98
98
99
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+
99float32 : Deconstructor (Float -> a) a
113float32 : Deconstructor (Float -> a) a
100float32 =
114float32 =
101 Deconstructor
115 Deconstructor
tests/Test/Urbit.elm+9
@@ -139,6 +139,15 @@ tests =
139 )
139 )
140 )
140 )
141 ]
141 ]
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+ )
142 ]
151 ]
143 ]
152 ]
144
153