Last Updated: February 25, 2016
·
441
· dionysios

Casting to a "smaller" type in Q

Casting is usually done by using the underlying types (e.g. from datetime to float) or the underlying bit representation (e.g. short infinity to int).

When casting from a "more general" type to a "less general" one (eg from int to short), the result is the largest number that can be held by the new variable.

For example:

`short$(-1 + 2 xexp 15)    / 32767h
`short$(-1 + 2 xexp 20)   /32767h
`short$0W   /32767h
`boolean$32h  /1b

This naturally generalizes to types that are supersets of others, like datetime and date or datetime and time:

`date$2014.01.06T14:25:57   / 2014.01.06
`time$2014.01.06T14:25:57.123   / 14:25:57.123