diff --git a/doc/usage.md b/doc/usage.md index 5eaf9666..eff61087 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -250,7 +250,6 @@ fq can be used as a scrip interpreter: - [gojq's differences to jq](https://github.com/itchyny/gojq#difference-to-jq), notable is support for arbitrary-precision integers. - Supports hexdecimal `0xab`, octal `0o77` and binary `0b101` integer literals. -- Has bitwise operators, `band`, `bor`, `bxor`, `bsl`, `bsr`, `bnot`. - Try include `include "file?";` that don't fail if file is missing. - Some values can act as a object with keys even when it's an array, number etc. - There can be keys hidden from `keys` and `[]`. @@ -269,6 +268,8 @@ notable is support for arbitrary-precision integers. - `diff/2` produce diff object between two values. - `delta/0`, `delta_by/1`, array with difference between all consecutive pairs. - `chunk/1`, split array or string into even chunks +- Bitwise functions `band`, `bor`, `bxor`, `bsl`, `bsr` and `bnot`. Works the same as jq math functions, +unary uses input and if more than one argument all as arguments ignoring the input. Ex: `1 | bnot` `bsl(1; 3)` - Adds some decode value specific functions: - `root/0` tree root for value - `buffer_root/0` root value of buffer for value diff --git a/pkg/interp/testdata/bitops.fqtest b/pkg/interp/testdata/bitops.fqtest index b5a97e49..8f3b93c0 100644 --- a/pkg/interp/testdata/bitops.fqtest +++ b/pkg/interp/testdata/bitops.fqtest @@ -4,24 +4,48 @@ null> 0, -1, 1208925819614629174706175, -1208925819614629174706176 | bnot 0 -1208925819614629174706176 1208925819614629174706175 +null> null | bnot +error: cannot bnot: null +null> bnot(1) +error: repl:1:0: function not defined: bnot/1 null> [0,0], [8,1], [0xffff_ffff_ffff_ffff,1] | bsl(.[0]; .[1]) 0 16 36893488147419103230 +null> bsl(1) +error: repl:1:0: function not defined: bsl/1 +null> bsl(null; 1) +error: cannot bsl: null and number null> [0,0], [8,1], [0x1_ffff_ffff_ffff_fffe,1] | bsr(.[0]; .[1]) 0 4 18446744073709551615 +null> bsr(1) +error: repl:1:0: function not defined: bsr/1 +null> bsr(null; 1) +error: cannot bsr: null and number null> [0,0], [0xffff_ffff_ffff_ffff_ffff,0x1234], [0x1234,0xffff_ffff_ffff_ffff_ffff,0x1234] | band(.[0]; .[1]) 0 4660 4660 +null> band(1) +error: repl:1:0: function not defined: band/1 +null> band(null; 1) +error: cannot band: null and number null> [0,0], [0xffff_ffff_ffff_ffff_0000,0x1234], [0x1234,0xffff_ffff_ffff_ffff_0000,0x1234] | bor(.[0]; .[1]) 0 1208925819614629174645300 1208925819614629174645300 +null> bor(1) +error: repl:1:0: function not defined: bor/1 +null> bor(null; 1) +error: cannot bor: null and number null> [0,0], [0xffff_ffff_ffff_ffff_ffff,0x1234], [0x1234,0xffff_ffff_ffff_ffff_ffff,0x1234] | bxor(.[0]; .[1]) 0 1208925819614629174701515 1208925819614629174701515 +null> bxor(1) +error: repl:1:0: function not defined: bxor/1 +null> bxor(null; 1) +error: cannot bxor: null and number null> ^D