mirror of
https://github.com/ilyakooo0/airlock.git
synced 2024-07-14 13:50:37 +03:00
Added signed integers
This commit is contained in:
parent
d4b214ea1a
commit
05d655450a
@ -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
|
||||
|
@ -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 ])
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user