For promotion, every data type belongs to one of three categories, ordered boolean < integer < float:
boolean –
boolinteger –
i8,i16,i32,i64and their unsigned counterpartsui8,ui16,ui32,ui64float –
f32andf64.
These are the categories promotion works in, where signed and unsigned
integers count as one. tengen::dtype_category() reports a finer split
that names int and uint separately.
Data Type Vocabulary
Where a page says which data types an argument takes, it names a group of them with a single word:
any data type – all of them:
bool, the signed and unsigned integers, and the floats.numeric – signed integer, unsigned integer and float.
integer – signed and unsigned integer.
integerish – boolean and integer, signed or unsigned.
signed numeric – signed integer and float.
float – the whole float category:
f32andf64.boolean –
bool, the only member of its category.
Where a Data Type Comes From
An R value has no data type of its own. Where nothing in the program says
which one it should take, it materializes at the default of its category, which
default_dtypes() reports and the anvl.default_dtypes option
configures. peek_dtype() reports the default a given R value would
materialize at.
The same defaults settle the data type of a result anvl chooses on its own,
where no R value is involved at all: an index (nv_argmax(),
nv_argsort(), nv_top_k(), the cumulative extrema, nv_lu()'s pivots),
the accumulator a boolean input is counted at (nv_reduce_sum(),
nv_reduce_prod(), nv_cumsum(), nv_cumprod(), nv_trace()), and the
float a non-float input is averaged or interpolated at (nv_mean(),
nv_var(), nv_sd(), nv_median(), nv_quantile()).
Within its own category an R value assumes the data type it meets instead,
and is built at it directly rather than converted to it, which is what keeps
nv_scalar(1, "f64") / sqrt(2) exact. The primitives require operands that
have a data type to agree on it; the nv_* functions promote them to a
common one.