Search for type promotion: http://code.kx.com/mediawiki/index.php?title=Special:KwikiSearch&search=type+promotion&go=Go<o:p></o:p>
<o:p> </o:p>
Basically atoms == implicit type promotion (to the larger type); single-type lists == usually no type promotion (int<->long is the [only?] exception)<o:p></o:p>
<o:p> </o:p>
q)type 1i+1j /int promoted to long<o:p></o:p>
-7h<o:p></o:p>
q)1f+1h /short promoted to float<o:p></o:p>
2f<o:p></o:p>
q)@[1 2 3j;1;:;1j] /amend long list with long<o:p></o:p>
1 1 3<o:p></o:p>
q)@[1 2 3j;1;:;1i] /amend long list with int<o:p></o:p>
1 1 3<o:p></o:p>
q)type @[1 2 3j;1;:;1i] /int was promoted to long<o:p></o:p>
7h<o:p></o:p>
q)@[1 2 3i;1;:;1j] /long was demoted to int<o:p></o:p>
1 1 3i<o:p></o:p>
q)@[1 2 3i;1;:;9223372036854775] / big long was demoted to int 0W<o:p></o:p>
1 0W 3i<o:p></o:p>
q)type @[1 2 3j;1;:;1h] /short incompatible with long<o:p></o:p>
'type<o:p></o:p>
q)@[1 2 3i;1;:;1h] /also int<o:p></o:p>
'type<o:p></o:p>
q)@[1 2j,3i;1;:;1h] /but ok in mixed lists<o:p></o:p>
1<o:p></o:p>
1h<o:p></o:p>
3i<o:p></o:p>
q)@[1 2 3j;1;:;1f] /no float->long<o:p></o:p>
'type<o:p></o:p>
q)@[1 2 3f;1;:;1j] /no long->float<o:p></o:p>
'type<o:p></o:p>
/
etc
<o:p></o:p>
<o:p> </o:p>
From: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] On Behalf Of analyst
Sent: Tuesday, April 28, 2015 12:08 PM
To: personal-kdbplus@googlegroups.com
Subject: [personal kdb+] Amend : type enforcement<o:p></o:p>
<o:p> </o:p>
The Q for mortals webpage says amend (:) enforces type. However, I see some implicit casting happening between double and integers etc.. Can someone explain casting rules:<o:p></o:p>
<o:p> </o:p>
variable gl is of type long and 7i and ii are of type int. How’s the auto conversion happening ?<o:p></o:p>
<o:p> </o:p>
http://code.kx.com/wiki/JB:QforMortals2/functions#Amend_.28:.29<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
q)gl<o:p></o:p>
1<o:p></o:p>
q)type gl<o:p></o:p>
-7h<o:p></o:p>
q)gl+:7i<o:p></o:p>
q)gl<o:p></o:p>
8<o:p></o:p>
q)type gl<o:p></o:p>
-7h<o:p></o:p>
q)ii:7i<o:p></o:p>
q)type ii<o:p></o:p>
-6h<o:p></o:p>
–
Submitted via Google Groups