q/kdb+ | Data types
q uses a concise system for representing types. Each data type has both a character and a number (short int) associated with it, as documented in the type table [1].
Some starting notes:
the
type
function [2] will return the number associated with the data type, as a short int. For example, the number associated with atomic long integers is -7, sotype
will return-7h
for a long integer (theh
being the type of the returned number, which is a short)the number listed in that table (column
n
) is the absolute value of what's returned bytype
.type
will return the negative version of the number if the type of the data is atomicyou can convert between different types using the
$
infix function [3] (see example below)
Examples:
10j / atomic 10 in `j` type (i.e. long integer)
10 / also a long int (ints are long by default)
10h / atomic 10 in `h` type (i.e. short integer)
type 10j / -7h, representing an atomic long int
10f / 10 in `f` type (float)
type 10f / -9h, representing a float
(10 11 12) / list of long ints
type (10 11 12) / 7h, representing a non-atomic long int (contrast `type 10j`)
9h$10j / converts to 10f (note usage of positive `9h` as the first argument)
Resources: