Implicit type conversion: Difference between revisions

(insert →‎Pascal)
Line 701:
Double: 6728</pre>
 
=={{header|Free Pascal}}==
''See [[#Delphi|Delphi]]''
 
=={{header|Furor}}==
Line 1,240 ⟶ 1,242:
 
There are no user-defined types and hence no implicit conversion on them.
 
=={{header|Pascal}}==
<lang pascal>program implicitTypeConversion;
var
i: integer;
r: real;
begin
i := 42;
r := i { integer → real }
end.</lang>
{{works with|Extended Pascal}}
<lang pascal>program additionalImplicitTypeConversionInExtendedPascal;
var
c: char;
s: string(20);
i: integer;
r: real;
x: complex;
begin
c := 'X';
s := c; { char → string(…) }
i := 42;
x := i; { integer → complex }
r := 123.456;
x := r { real → complex }
end.</lang>
All available implicit conversions are applicable when providing parameters to a routine call.
For instance the Extended Pascal function <tt>im</tt> intended to return the imaginary part of a <tt>complex</tt> number can be called with an <tt>integer</tt> value.
Obviously, <tt>im(42)</tt> will always return <tt>0</tt>&nbsp;(zero), but the implicit conversion (<tt>integer</tt> to <tt>complex</tt>) is performed.
This is important to remember, when the conversion could cause a loss in precision.
For instance Extended Pascal’s [[Exponentiation order#Pascal|exponentiation operator]] <tt>**</tt> will promote any <tt>integer</tt> operand to a <tt>real</tt> value first.
 
=={{header|Perl}}==
149

edits