Added signed integers

This commit is contained in:
iko 2023-06-01 17:34:43 +03:00
parent d4b214ea1a
commit 05d655450a
Signed by untrusted user: iko
GPG Key ID: 82C257048D1026F2
2 changed files with 23 additions and 0 deletions

View File

@ -15,6 +15,7 @@ module Urbit.Deconstructor exposing
, run , run
, runBytes , runBytes
, sig , sig
, signedInt
, tape , tape
, tar , 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 (Float -> a) a
float32 = float32 =
Deconstructor Deconstructor

View File

@ -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 ])
)
)
] ]
] ]