Implicit type conversion: Difference between revisions

m
→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics
(Added Wren)
m (→‎{{header|Phix}}: added syntax colouring the hard way, phix/basics)
Line 1,017:
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
If a numerical operation on floating points results in an exact integer, that is how it is stored, eg 1.5+1.5<br>
Likewise a numerical operation on integers can need to be stored in a float, eg 1/3 or #123456*#123456.<br>
If a string character (or slice) is replaced with any value that will not fit in a byte, it is automatically
converted to a dword_sequence, eg
<!--<lang Phix>sequence s = "this"-->
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"this"</span>
s[3] = PI -- s is now {'t','h',3.1415926,'s'}</lang>
<span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">3</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">PI</span> <span style="color: #000080;font-style:italic;">-- s is now {'t','h',3.1415926,'s'}</span>
<!--</lang>-->
Phix does not, or at least tries very hard not to "drop bits" or "clock round". 1/3 is 0.333333 not 0, 0-1 is
-1 not +#FFFFFFFF, in all cases, with a plain english fatal run-time error should a type check occur, as would occur above were s defined as a string instead of a sequence.
 
=={{header|Python}}==
7,806

edits