Skip to content

Commit 328f322

Browse files
committed
BigInt documentation
1 parent 26ac84a commit 328f322

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

docs/codeql/codeql-language-guides/extensible-predicates.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ An extensible predicate is a CodeQL predicate with the following restrictions:
3636

3737
- It uses the ``extensible`` keyword.
3838
- It has no body.
39-
- All predicate parameters have primitive types.
39+
- All predicate parameters have type ``string``, ``int``, ``float``, ``boolean``, or ``date``.
4040
- It is not in a module.
4141

4242
Columns shared by all extensible predicates

docs/codeql/ql-language-reference/modules.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,30 @@ The above query therefore evalutes to:
424424
+----+----+
425425
| 4 | 4 |
426426
+----+----+
427+
428+
.. index:: BigInt
429+
.. _bigint:
430+
431+
BigInt
432+
======
433+
434+
The built-in ``QlBuiltins`` module provides an **experimental** type ``BigInt`` of arbitrary-precision integers.
435+
436+
This type is not available in the CodeQL CLI by default, but you can enable it by passing the ``--allow-experimental=bigint``
437+
option to the CodeQL CLI. Consequently, BigInts are currently disallowed in query results and dbscheme columns.
438+
439+
Unlike ``int`` and ``float``, there is no automatic conversion between ``BigInt`` and other numeric types.
440+
Instead, big integers can be constructed using the ``.toBigInt()`` methods of ``int`` and ``string``.
441+
442+
The other built-in operations are:
443+
444+
* comparisons between ``BigInt``\s: ``=``, ``!=``, ``<``, ``<=``, ``>``, ``>=``,
445+
* conversions from ``BigInt``\s to strings or integers (if within range): ``.toString()``, ``.toInt()``,
446+
* ``BigInt`` arithmetic: binary ``+``, ``-``, ``*``, ``/``, ``%``, unary ``-``,
447+
* bitwise operations: ``.bitAnd(BigInt)``, ``.bitOr(BigInt)``,
448+
``.bitXor(BigInt)``, ``.bitShiftLeft(int)``, ``.bitShiftRightSigned(int)``,
449+
``.bitNot()``,
450+
* aggregates: ``min``, ``max``, (``strict``)\ ``sum``, (``strict``)\ ``count``, ``avg``,
451+
``rank``, ``unique``, ``any``.
452+
* other: ``.pow(int)``, ``.abs()``, ``.gcd(BigInt)``, ``.minimum(BigInt)``,
453+
``.maximum(BigInt)``.

docs/codeql/ql-language-reference/ql-language-specification.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ Kinds of types
359359

360360
Types in QL are either *primitive* types, *database* types, *class* types, *character* types, *class domain* types, type *parameters*, or *instantiation-nested* types.
361361

362-
The primitive types are ``boolean``, ``date``, ``float``, ``int``, and ``string``.
362+
The primitive types are ``boolean``, ``date``, ``float``, ``int``, ``string``, and ``QlBuiltins::BigInt``.
363363

364364
Database types are supplied as part of the database. Each database type has a *name*, which is an identifier starting with an at sign (``@``, U+0040) followed by lower-case letter. Database types have some number of *base types*, which are other database types. In a valid database, the base types relation is non-cyclic.
365365

@@ -433,7 +433,7 @@ Values are the fundamental data that QL programs compute over. This section spec
433433
Kinds of values
434434
~~~~~~~~~~~~~~~
435435

436-
There are six kinds of values in QL: one kind for each of the five primitive types, and *entities*. Each value has a type.
436+
There are seven kinds of values in QL: one kind for each of the six primitive types, and *entities*. Each value has a type.
437437

438438
A boolean value is of type ``boolean``, and may have one of two distinct values: ``true`` or ``false``.
439439

@@ -445,6 +445,8 @@ An integer value is of type ``int``. Each value is a 32-bit two's complement int
445445

446446
A string is a finite sequence of 16-bit characters. The characters are interpreted as Unicode code points.
447447

448+
A :ref:`big integer <bigint>` value is of type ``QlBuiltins::BigInt``. Each value is a signed arbitrary-precision integer.
449+
448450
The database includes a number of opaque entity values. Each such value has a type that is one of the database types, and an identifying integer. An entity value is written as the name of its database type followed by its identifying integer in parentheses. For example, ``@tree(12)``, ``@person(16)``, and ``@location(38132)`` are entity values. The identifying integers are left opaque to programmers in this specification, so an implementation of QL is free to use some other set of countable labels to identify its entities.
449451

450452
Ordering
@@ -458,7 +460,7 @@ For dates, the ordering is chronological.
458460

459461
For floats, the ordering is as specified in IEEE 754 when one exists, except that NaN is considered equal to itself and is ordered after all other floats, and negative zero is considered to be strictly less than positive zero.
460462

461-
For integers, the ordering is as for two's complement integers.
463+
For integers (and :ref:`big integers <bigint>`), the ordering is numerical.
462464

463465
For strings, the ordering is lexicographic.
464466

docs/codeql/ql-language-reference/types.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ independent of the database that you are querying.
5252
QL has a range of built-in operations defined on primitive types. These are available by using dispatch on expressions of the appropriate type. For example, ``1.toString()`` is the string representation of the integer constant ``1``. For a full list of built-in operations available in QL, see the
5353
section on `built-ins <https://codeql.github.com/docs/ql-language-reference/ql-language-specification/#built-ins>`__ in the QL language specification.
5454

55+
Additionally, there is an experimental arbitrary-precision integer primitive type at :ref:`QlBuiltins::BigInt <bigint>`. This type is not available in the CodeQL CLI by default, but you can enable it by passing the ``--allow-experimental=bigint`` option to the CodeQL CLI.
56+
5557
.. index:: class
5658
.. _classes:
5759

0 commit comments

Comments
 (0)