blob: 3bdd9d54656f8246355ebe20048e3e5b66487baa [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1-transitional.dtd">
<!-- saved from url=(0013)about:internet -->
<?xml-stylesheet type="text/xsl" href="mathml.xsl"?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:pref="http://www.w3.org/2002/Math/preference" xmlns:xlink="http://www.w3.org/1999/xlink" pref:renderer="mathplayer-dl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style xmlns="" type="text/css">
/* This style sets a margin around the entire page */
html, body {
margin: 10px;
}
p {
font: normal 16px verdana, sans-serif;
margin: 0;
padding-bottom:12px;
}
h1 {
font: bold 25px verdana, sans-serif;
margin-top: 0;
margin-bottom: 3px;
padding-top: 0;
padding-bottom: 0;
}
h2 {
font: bold 19px verdana, sans-serif;
margin-top: 28px;
margin-bottom: 3px;
padding-top: 0;
padding-bottom: 0;
}
h3 {
font: bold 19px verdana, sans-serif !important;
margin-top: 28px;
margin-bottom: 3px;
padding-top: 0;
padding-bottom: 0;
}
li {
font: normal 16px verdana, sans-serif;
margin-top: 0;
margin-bottom: 18px;
padding-top: 0;
padding-bottom: 0;
}
.pdparam {
font: italic 16px verdana, sans-serif;
}
.term {
font: italic 16px verdana, sans-serif;
font-weight: normal;
}
.type {
font: normal 16px verdana, sans-serif !important;
}
.parameter {
font-style: italic;
}
a:link, a:visited {
color: blue;
text-decoration: none;
font: normal 16px;
}
a:hover {
background-color: #FFFF99;
font: normal 16px;
}
div.funcsynopsis {
text-align: left;
background-color: #e6e6e6;
font: normal 16px verdana, sans-serif;
padding-top: 10px;
padding-bottom: 10px;
}
div.funcsynopsis table {
border-collapse: separate;
font: normal 16px verdana, sans-serif;
}
div.funcsynopsis td {
background-color: #e6e6e6;
border: 0 solid #000;
padding: 1px;
font: normal 16px verdana, sans-serif;
}
div.refsect1 {
font-family: verdana, sans-serif;
font-size: 16px;
}
code.constant {
font: normal 16px courier new, monospace !important;
}
span.errorname {
font: normal 16px verdana, sans-serif !important;
}
code.function {
font: bold 16px verdana, sans-serif !important;
}
b.fsfunc {
font: bold 16px verdana, sans-serif !important;
}
code.varname {
font: italic 16px verdana, sans-serif;
}
code.replaceable {
font: italic 16px courier new, monospace;
}
code.funcdef {
font: normal 16px verdana, sans-serif !important;
}
.citerefentry {
font: normal 16px verdana, sans-serif !important;
}
.parameter {
font-style: italic;
}
code.fsfunc {
font: normal 16px verdana, sans-serif !important;
}
/* PARAMETER: This style controls spacing between the terms in Parameter section */
dt {
margin-top: 15px;
}
/* TABLES: These styles apply to all tables OTHER than the Synopsis and Example tables */
div.refsect1 table {
width: 100%;
margin-top: 10px;
background-color: #FFF;
border-collapse: collapse;
border-color: #000;
border-width: 1px;
font: normal 16px verdana, sans-serif;
}
div.refsect1 th {
border-collapse: collapse;
border-color: #000;
border-width: 1px;
font: bold 16px verdana, sans-serif;
}
div.refsect1 td {
background-color: #FFF;
padding: 5px;
vertical-align: text-top;
border-collapse: collapse;
border-color: #000;
border-width: 1px;
font: normal 16px verdana, sans-serif;
}
div.refsect1 p{
font: normal 16px verdana, sans-serif;
margin-top: 8px;
margin-bottom: 8px;
padding-top: 0;
padding-bottom: 0;
}
/* EXAMPLE: These styles apply only to the Example section */
div.refsect2 {
font: normal 16px courier new, monospace !important;
}
div.refsect2 table {
margin-top: 0;
background-color: #e6e6e6;
width: 100%;
border: 0 solid #000;
padding: 2px;
font: normal 16px courier new, monospace !important;
}
div.refsect2 td {
background-color: #e6e6e6;
font: normal 16px courier new, monospace !important;
white-space:pre;
}
/* COPYRIGHT: This style formats the text of the copyright statement at the bottom of the page */
div.refsect3 {
font: normal 11px verdana, sans-serif;
margin-top: 50px;
margin-bottom: 20px;
padding-top: 0;
padding-bottom: 0;
}
</style>
<title>Explicit conversions with convert_T()</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
<meta name="keywords" content=" &#10; Explicit conversions with convert_T()&#10; " />
</head>
<body>
<div class="refentry">
<a id="id-1"></a>
<div class="titlepage"></div>
<div xmlns="" class="refnamediv">
<a xmlns="http://www.w3.org/1999/xhtml" id="convert_T"></a>
<h1>Explicit conversions with convert_T()</h1>
<p>
Explicit type conversions using convert_<code xmlns="http://www.w3.org/1999/xhtml" class="varname">T</code>()
</p>
</div>
<div class="refsect2">
<a id="synopsis"></a>
<h3>
</h3>
<div class="informaltable">
<table border="0">
<colgroup>
<col align="left" class="col1" />
</colgroup>
<tbody>
<tr>
<td align="left">
convert_<em class="replaceable"><code>destType</code></em>(<em class="replaceable"><code>srctype val</code></em>)
<em class="replaceable"><code>destType</code></em> convert_<em class="replaceable"><code>destType</code></em>[_sat][<em class="replaceable"><code>roundingMode</code></em>] (<em class="replaceable"><code>srcType val</code></em>)
<em class="replaceable"><code>destTypen</code></em> convert_<em class="replaceable"><code>destTypen</code></em>[_sat][<em class="replaceable"><code>roundingMode</code></em>] (<em class="replaceable"><code>srcTypen val</code></em>)
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="refsect1">
<a id="description"></a>
<h2>Description</h2>
<p>
Explicit conversions may be performed using the <code class="code">convert_&lt;dest type name&gt;(srctype)</code> suite of functions. These provide a full set of type conversions between supported types (see
<a class="citerefentry" href="scalarDataTypes.html"><span class="citerefentry"><span class="refentrytitle">Scalar Data Types</span></span></a>)
except for the following types:
<span class="type">bool</span>, <span class="type">half</span>, <span class="type">size_t</span>, <span class="type">ptrdiff_t</span>, <span class="type">intptr_t</span>, <span class="type">uintptr_t</span>, and <span class="type">void</span>. The number of elements in the source and destination vectors must match.
</p>
<p>
Explicit conversions from a type to the same type has no effect on the type or value of an
expression.
</p>
<p>
The behavior of the conversion may be modified by one or two optional modifiers that specify
saturation for out-of-range inputs and rounding behavior.
</p>
<p>
The full form of the scalar convert function is:
</p>
<div class="literallayout">
<p>          <code class="code"><em class="replaceable"><code>destType</code></em> convert_<em class="replaceable"><code>destType</code></em>[_sat][<em class="replaceable"><code>roundingMode</code></em>](<em class="replaceable"><code>srcType val</code></em>)</code></p>
</div>
<p>
</p>
<p>
The full form of the vector convert function is:
</p>
<div class="literallayout">
<p>          <code class="code"><em class="replaceable"><code>destTypen</code></em> convert_<em class="replaceable"><code>destTypen</code></em>[_sat][<em class="replaceable"><code>roundingMode</code></em>](<em class="replaceable"><code>srcTypen val</code></em>)</code></p>
</div>
<p>
</p>
<h4><a id="id-1.5.7"></a>Data Types</h4>
<p>
The operand and result type may be the same type and must have the same number of elements. Conversions are available for the following scalar types and built-in vector types derived therefrom: <span class="type">char</span>, <span class="type">uchar</span>, <span class="type">short</span>, <span class="type">ushort</span>, <span class="type">int</span>, <span class="type">uint</span>, <span class="type">long</span>, <span class="type">ulong</span>, and <span class="type">float</span>.
</p>
<h4><a id="id-1.5.9"></a>Rounding Modes</h4>
<p>
Conversions to and from floating-point type shall conform to IEEE-754 rounding rules.
Conversions involving a floating-point or integer source operand or destination type may have an
optional rounding mode modifier. These are described in the table below:
</p>
<p>
</p>
<div class="informaltable">
<table border="1">
<colgroup>
<col align="left" class="col1" />
<col align="left" class="col2" />
</colgroup>
<thead>
<tr>
<th align="left">Modifier</th>
<th align="left">Rounding Mode Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">
<p>
<code class="code">_rte</code>
</p>
</td>
<td align="left">
<p>
Round to nearest even
</p>
</td>
</tr>
<tr>
<td align="left">
<p>
<code class="code">_rtz</code>
</p>
</td>
<td align="left">
<p>
Round towards zero
</p>
</td>
</tr>
<tr>
<td align="left">
<p>
<code class="code">_rtp</code>
</p>
</td>
<td align="left">
<p>
Round toward positive infinity
</p>
</td>
</tr>
<tr>
<td align="left">
<p>
<code class="code">_rtn</code>
</p>
</td>
<td align="left">
<p>
Round toward negative infinity
</p>
</td>
</tr>
<tr>
<td align="left">
<p>
no modifier specified
</p>
</td>
<td align="left">
<p>
Use the default rounding mode for this destination type, <code class="code">_rtz</code> for conversion to integers or the current rounding mode for conversion to floating-point types.
</p>
</td>
</tr>
</tbody>
</table>
</div>
<p>
</p>
<p>
By default, conversions to integer type use the <code class="code">_rtz</code> (round toward zero) rounding mode and conversions to floating-point type use the current rounding mode. The only default floating-point rounding mode supported is round to nearest even, i.e the current rounding mode will be <code class="code">_rte</code> for floating-point types.
</p>
<p>
</p>
<h4><a id="id-1.5.13.1"></a>Out-of-Range Behavior and Saturated Conversions</h4>
<p>
</p>
<p>
When the conversion operand is either greater than the greatest representable destination value or
less than the least representable destination value, it is said to be out-of-range. When converting
between integer types, the resulting value for out-of-range inputs will be equal to the set of least
significant bits in the source operand element that fit in the corresponding destination element.
When converting from a floating-point type to integer type, the behavior is implementation-
defined.
</p>
<p>
Conversions to integer type may opt to convert using the optional saturated mode by appending
the <code class="code">_sat</code> modifier to the conversion function name. When in saturated mode, values that are
outside the representable range shall clamp to the nearest representable value in the destination
format. (NaN should be converted to 0).
</p>
<p>
Conversions to floating-point type shall conform to IEEE-754 rounding rules. The _sat
modifier may not be used for conversions to floating-point formats.
</p>
</div>
<div class="refsect1">
<a id="notes"></a>
<h2>Notes</h2>
<p>
For conversions to floating-point format, when a finite source
value exceeds the maximum representable finite
floating-point destination value, the rounding mode will affect
whether the result is the maximum finite floating-point value
or infinity of same sign as the source value, per IEEE-754 rules for rounding.
</p>
</div>
<div class="refsect2">
<a id="example1"></a>
<h3>
Examples
</h3>
<div class="informaltable">
<table border="0">
<colgroup>
<col align="left" class="col1" />
</colgroup>
<tbody>
<tr>
<td align="left">
short4 s;
// negative values clamped to 0
ushort4 u = convert_ushort4_sat( s );
// values &gt; CHAR_MAX converted to CHAR_MAX
// values &lt; CHAR_MIN converted to CHAR_MIN
char4 c = convert_char4_sat( s );
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="refsect2">
<a id="example2"></a>
<h3>
</h3>
<div class="informaltable">
<table border="0">
<colgroup>
<col align="left" class="col1" />
</colgroup>
<tbody>
<tr>
<td align="left">
float4 f;
// values implementation defined for
// f &gt; INT_MAX, f &lt; INT_MIN or NaN
int4 i = convert_int4( f );
// values &gt; INT_MAX clamp to INT_MAX, values &lt; INT_MIN clamp
// to INT_MIN. NaN should produce 0.
// The _rtz rounding mode is
// used to produce the integer values.
int4 i2 = convert_int4_sat( f );
// similar to convert_int4, except that
// floating-point values are rounded to the nearest
// integer instead of truncated
int4 i3 = convert_int4_rte( f );
// similar to convert_int4_sat, except that
// floating-point values are rounded to the
// nearest integer instead of truncated
int4 i4 = convert_int4_sat_rte( f );
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="refsect2">
<a id="example3"></a>
<h3>
</h3>
<div class="informaltable">
<table border="0">
<colgroup>
<col align="left" class="col1" />
</colgroup>
<tbody>
<tr>
<td align="left">
int4 i;
// convert ints to floats using the current rounding mode.
float4 f = convert_float4( i );
// convert ints to floats. integer values that cannot
// be exactly represented as floats should round up to the
// next representable float.
float4 f = convert_float4_rtp( i );
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="refsect1">
<a id="specification"></a>
<h2>Specification</h2>
<p>
<img src="pdficon_small1.gif" />
<a href="http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf#page=167" target="OpenCL Spec">OpenCL Specification</a>
</p>
</div>
<div class="refsect1">
<a id="seealso"></a>
<h2>Also see</h2>
<p>
<a class="citerefentry" href="scalarDataTypes.html"><span class="citerefentry"><span class="refentrytitle">Scalar Data Types</span></span></a>,
<a class="citerefentry" href="vectorDataTypes.html"><span class="citerefentry"><span class="refentrytitle">Vector Data Types</span></span></a>
</p>
</div>
<div xmlns="" class="refsect3" lang="en" xml:lang="en"><a xmlns="http://www.w3.org/1999/xhtml" id="Copyright"></a><h4 xmlns="http://www.w3.org/1999/xhtml"></h4><img xmlns="http://www.w3.org/1999/xhtml" src="KhronosLogo.jpg" /><p xmlns="http://www.w3.org/1999/xhtml"></p>Copyright © 2007-2010 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the condition that this copyright notice and permission notice shall be included
in all copies or substantial portions of the Materials.
</div>
</div>
</body>
</html>