Skip to content

Commit

Permalink
number_to_bytes: Force int to make it work with bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Sep 12, 2021
1 parent 1888bb2 commit 6a8ba31
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/interp/funcs.jq
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ def table(colmap; render):

# convert number to array of bytes
def number_to_bytes($bits):
# TODO: figure out a saner way to force int
def _to_int: (. % (. + 1));
def _number_to_bytes($d):
if . > 0 then
. % $d, (intdiv(.; $d) | _number_to_bytes($d))
else
empty
end;
if . == 0 then [0]
else [_number_to_bytes(1 bsl $bits)] | reverse
else [_number_to_bytes(pow(2; $bits) | _to_int)] | reverse
end;
def number_to_bytes:
number_to_bytes(8);
Expand Down

0 comments on commit 6a8ba31

Please sign in to comment.