~ubuntu-branches/ubuntu/trusty/khronos-opencl-man/trusty

« back to all changes in this revision

Viewing changes to convert_T.xml

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2013-05-21 18:06:15 UTC
  • Revision ID: package-import@ubuntu.com-20130521180615-6e0s2n3pai95ip2f
Tags: upstream-1.0~svn21772
ImportĀ upstreamĀ versionĀ 1.0~svn21772

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="UTF-8"?>
 
2
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook MathML Module V1.1b1//EN"
 
3
              "http://www.oasis-open.org/docbook/xml/mathml/1.1CR1/dbmathml.dtd">
 
4
 
 
5
<refentry>
 
6
    <refentryinfo>
 
7
        <keywordset>
 
8
            <keyword>
 
9
                Explicit conversions with convert_T()
 
10
            </keyword>
 
11
        </keywordset>
 
12
    </refentryinfo>
 
13
 
 
14
    <refmeta>
 
15
        <refentrytitle>Explicit conversions with convert_T()</refentrytitle>
 
16
 
 
17
        <refmiscinfo>
 
18
            <copyright>
 
19
                <year>2007-2011</year>
 
20
                <holder>The Khronos Group Inc.
 
21
 Permission is hereby granted, free of charge, to any person obtaining a
 
22
copy of this software and/or associated documentation files (the
 
23
"Materials"), to deal in the Materials without restriction, including
 
24
without limitation the rights to use, copy, modify, merge, publish,
 
25
distribute, sublicense, and/or sell copies of the Materials, and to
 
26
permit persons to whom the Materials are furnished to do so, subject to
 
27
the condition that this copyright notice and permission notice shall be included
 
28
in all copies or substantial portions of the Materials.</holder>
 
29
            </copyright>
 
30
        </refmiscinfo>
 
31
        <manvolnum>3</manvolnum>
 
32
    </refmeta>
 
33
 
 
34
<!-- ================================ SYNOPSIS -->
 
35
 
 
36
    <refnamediv id="convert_T">
 
37
        <refname>Explicit conversions with convert_T()</refname>
 
38
 
 
39
        <refpurpose>
 
40
            Explicit type conversions using convert_<varname>T</varname>()
 
41
        </refpurpose>
 
42
    </refnamediv>
 
43
 
 
44
    <!-- ALTERNATIVE SYNTAX SYNOPSIS (NON-FUNCTION) -->
 
45
 
 
46
    <refsect2 id="synopsis">
 
47
        <title>
 
48
        </title>
 
49
 
 
50
        <informaltable frame="none">
 
51
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
52
                <colspec colname="col1" colnum="1" />
 
53
                <tbody>
 
54
                    <row>
 
55
                        <entry>
 
56
convert_<replaceable>destType</replaceable>(<replaceable>sourceType</replaceable>)
 
57
<replaceable>destType</replaceable> convert_<replaceable>destType</replaceable>&lt;_sat&gt;&lt;<replaceable>roundingMode</replaceable>&gt; (<replaceable>sourceType</replaceable>)
 
58
<replaceable>destTypen</replaceable> convert_<replaceable>destTypen</replaceable>&lt;_sat&gt;&lt;<replaceable>roundingMode</replaceable>&gt; (<replaceable>sourceType</replaceable>)
 
59
                        </entry>
 
60
                    </row>
 
61
                </tbody>
 
62
            </tgroup>
 
63
        </informaltable>
 
64
    </refsect2>
 
65
 
 
66
<!-- ================================ DESCRIPTION  -->
 
67
 
 
68
    <refsect1 id="description"><title>Description</title>
 
69
        <para>
 
70
          Explicit conversions may be performed using the <code>convert_destType(sourceType)</code>
 
71
          suite of functions.  These provide a full set of type conversions between
 
72
          supported types (see <citerefentry href="scalarDataTypes"><refentrytitle>Scalar Data
 
73
          Types</refentrytitle></citerefentry>)<!--section 6.1.1--> except for the following types:
 
74
          <type>bool</type>, <type>half</type>, <type>size_t</type>, <type>ptrdiff_t</type>,
 
75
          <type>intptr_t</type>, <type>uintptr_t</type>, and  <type>void</type>.
 
76
        </para>
 
77
 
 
78
        <para>
 
79
           The number of elements in the source and destination vectors must match.
 
80
        </para>
 
81
 
 
82
        <para>
 
83
          The behavior of the conversion may be modified by one or two optional modifiers that
 
84
          specify saturation for out-of-range inputs and rounding behavior.
 
85
        </para>
 
86
 
 
87
        <para>
 
88
          The full form of the scalar convert function is:
 
89
          <literallayout>          <code><replaceable>destType</replaceable>
 
90
          convert_<replaceable>destType</replaceable>&lt;_sat&gt;&lt;<replaceable>_roundingMode</replaceable>&gt;(<replaceable>sourceType</replaceable>)</code></literallayout>
 
91
        </para>
 
92
 
 
93
        <para>
 
94
          The full form of the vector convert function is:
 
95
          <literallayout>          <code><replaceable>destTypen</replaceable>
 
96
          convert_<replaceable>destTypen</replaceable>&lt;_sat&gt;&lt;<replaceable>_roundingMode</replaceable>&gt;(<replaceable>sourceTypen</replaceable>)</code></literallayout>
 
97
        </para>
 
98
 
 
99
        <bridgehead>Data Types</bridgehead>
 
100
 
 
101
        <para>
 
102
          Conversions are available for the following scalar types:  <type>char</type>,
 
103
          <type>uchar</type>, <type>short</type>, <type>ushort</type>, <type>int</type>,
 
104
          <type>uint</type>, <type>long</type>, <type>ulong</type>, <type>float</type>, and
 
105
          built-in vector types derived therefrom. The operand and result type must have the
 
106
          same number of elements. The operand and result type may be the same type in which
 
107
          case the conversion has no effect on the type or value of an expression.
 
108
        </para>
 
109
 
 
110
        <para>
 
111
          Conversions between integer types follow the conversion rules specified in sections
 
112
          6.3.1.1 and 6.3.1.3 of the C99 specification except for out-of-range behavior and
 
113
          saturated conversions which are described in section 6.2.3.3 below.
 
114
        </para>
 
115
 
 
116
        <bridgehead>Rounding Modes</bridgehead>
 
117
 
 
118
        <para>
 
119
          Conversions to and from floating-point type shall conform to IEEE-754 rounding rules.
 
120
          Conversions may have an optional rounding mode modifier described in the table below.
 
121
        </para>
 
122
 
 
123
        <para>
 
124
            <informaltable frame="all">
 
125
                <tgroup cols="2" align="left" colsep="1" rowsep="1">
 
126
                    <colspec colname="col1" colnum="1" />
 
127
                    <colspec colname="col2" colnum="2" />
 
128
 
 
129
                    <thead>
 
130
                        <row>
 
131
                            <entry>Modifier</entry>
 
132
                            <entry>Rounding Mode Description</entry>
 
133
                        </row>
 
134
                    </thead>
 
135
 
 
136
                    <tbody>
 
137
                        <row>
 
138
                            <entry><para><code>_rte</code></para></entry>
 
139
                            <entry><para>Round to nearest even</para></entry>
 
140
                        </row>
 
141
 
 
142
                        <row>
 
143
                            <entry><para><code>_rtz</code></para></entry>
 
144
                            <entry><para>Round towards zero</para></entry>
 
145
                        </row>
 
146
 
 
147
                        <row>
 
148
                            <entry><para><code>_rtp</code></para></entry>
 
149
                            <entry><para>Round toward positive infinity</para></entry>
 
150
                        </row>
 
151
 
 
152
                        <row>
 
153
                            <entry><para><code>_rtn</code></para></entry>
 
154
                            <entry><para>Round toward negative infinity</para></entry>
 
155
                        </row>
 
156
 
 
157
                        <row>
 
158
                            <entry><para>no modifier specified</para></entry>
 
159
                            <entry>
 
160
                                <para>
 
161
                                  Use the default rounding mode for this destination type,
 
162
                                  <code>_rtz</code> for conversion to integers or the default
 
163
                                  rounding mode for conversion to floating-point types.
 
164
                                </para>
 
165
                            </entry>
 
166
                        </row>
 
167
                    </tbody>
 
168
                </tgroup>
 
169
            </informaltable>
 
170
        </para>
 
171
 
 
172
        <para>
 
173
          By default, conversions to integer type use the <code>_rtz</code> (round toward zero)
 
174
          rounding mode and conversions to floating-point type use the default rounding mode. The
 
175
          only default floating-point rounding mode supported is round to nearest even, i.e
 
176
          the default rounding mode will be <code>_rte</code> for floating-point types.
 
177
        </para>
 
178
 
 
179
        <para>
 
180
          For conversions to floating-point format, when a finite source value exceeds the
 
181
          maximum representable finite floating-point destination value, the rounding mode will
 
182
          affect whether the result is the maximum finite floating point value or infinity of
 
183
          same sign as the source value, per IEEE-754 rules for rounding.
 
184
        </para>
 
185
 
 
186
        <para>
 
187
            <bridgehead>Out-of-Range Behavior and Saturated Conversions</bridgehead>
 
188
        </para>
 
189
 
 
190
        <para>
 
191
          When the conversion operand is either greater than the greatest representable
 
192
          destination value or less than the least representable destination value, it is
 
193
          said to be out-of-range. The result of out-of-range conversion is determined by the
 
194
          conversion rules specified by the C99 specification in section 6.3.  When converting
 
195
          from a floating-point type to integer type, the behavior is implementation-defined.
 
196
        </para>
 
197
 
 
198
        <para>
 
199
          Conversions to integer type may opt to convert using the optional saturated mode by
 
200
          appending the <code>_sat</code> modifier to the conversion function name. When in
 
201
          saturated mode, values that are outside the representable range shall clamp to the
 
202
          nearest representable value in the destination format. (NaN should be converted to 0).
 
203
        </para>
 
204
 
 
205
        <para>
 
206
          Conversions to floating-point type shall conform to IEEE-754 rounding rules. The
 
207
          <code>_sat</code> modifier may not be used for conversions to floating-point formats.
 
208
        </para>
 
209
    </refsect1>
 
210
 
 
211
<!-- ================================ NOTES  -->
 
212
 
 
213
<!--
 
214
    <refsect1 id="notes"><title>Notes</title>
 
215
    </refsect1>
 
216
-->
 
217
 
 
218
<!-- ================================ EXAMPLE  -->
 
219
 
 
220
    <refsect2 id="example0">
 
221
        <title>
 
222
Examples
 
223
        </title>
 
224
 
 
225
        <para>
 
226
          In the following example, <function>convert_int4</function> converts a
 
227
          <type>uchar4</type> vector <code>u</code> to an <type>int4</type> vector <code>c</code>:
 
228
        </para>
 
229
 
 
230
        <informaltable frame="none">
 
231
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
232
                <colspec colname="col1" colnum="1" />
 
233
                <tbody>
 
234
                    <row>
 
235
                        <entry>
 
236
uchar4 u;
 
237
int4   c = convert_int4(u);
 
238
                        </entry>
 
239
                    </row>
 
240
                </tbody>
 
241
            </tgroup>
 
242
        </informaltable>
 
243
 
 
244
        <para>
 
245
          In the following example, <function>convert_int</function> converts a float scalar
 
246
          <code>f</code> to an int scalar <code>i</code>:
 
247
        </para>
 
248
 
 
249
        <informaltable frame="none">
 
250
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
251
                <colspec colname="col1" colnum="1" />
 
252
                <tbody>
 
253
                    <row>
 
254
                        <entry>
 
255
float   f;
 
256
int    i = convert_int(f);
 
257
                        </entry>
 
258
                    </row>
 
259
                </tbody>
 
260
            </tgroup>
 
261
        </informaltable>
 
262
    </refsect2>
 
263
 
 
264
    <refsect2 id="example1">
 
265
        <title>
 
266
        </title>
 
267
 
 
268
        <para>
 
269
            Example:
 
270
        </para>
 
271
 
 
272
        <informaltable frame="none">
 
273
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
274
                <colspec colname="col1" colnum="1" />
 
275
                <tbody>
 
276
                    <row>
 
277
                        <entry>
 
278
short4  s;
 
279
 
 
280
// negative values clamped to 0
 
281
ushort4 u = convert_ushort4_sat( s );
 
282
 
 
283
// values &gt; CHAR_MAX converted to CHAR_MAX
 
284
// values &lt; CHAR_MIN converted to CHAR_MIN
 
285
char4 c = convert_char4_sat( s );
 
286
                        </entry>
 
287
                    </row>
 
288
                </tbody>
 
289
            </tgroup>
 
290
        </informaltable>
 
291
    </refsect2>
 
292
 
 
293
    <refsect2 id="example2">
 
294
        <title>
 
295
        </title>
 
296
 
 
297
        <para>
 
298
            Example:
 
299
        </para>
 
300
 
 
301
        <informaltable frame="none">
 
302
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
303
                <colspec colname="col1" colnum="1" />
 
304
                <tbody>
 
305
                    <row>
 
306
                        <entry>
 
307
float4 f;
 
308
 
 
309
// values implementation defined for
 
310
// f &gt; INT_MAX, f &lt; INT_MIN or NaN
 
311
int4   i = convert_int4( f );
 
312
 
 
313
// values &gt; INT_MAX clamp to INT_MAX, values &lt; INT_MIN clamp
 
314
// to INT_MIN. NaN should produce 0.
 
315
 
 
316
// The _rtz rounding mode is
 
317
// used to produce the integer values.
 
318
int4   i2 = convert_int4_sat( f );
 
319
 
 
320
// similar to convert_int4, except that
 
321
// floating-point values are rounded to the nearest
 
322
// integer instead of truncated
 
323
int4   i3 = convert_int4_rte( f );
 
324
 
 
325
// similar to convert_int4_sat, except that
 
326
// floating-point values are rounded to the
 
327
// nearest integer instead of truncated
 
328
int4   i4 = convert_int4_sat_rte( f );
 
329
                        </entry>
 
330
                    </row>
 
331
                </tbody>
 
332
            </tgroup>
 
333
        </informaltable>
 
334
    </refsect2>
 
335
 
 
336
    <refsect2 id="example3">
 
337
        <title>
 
338
        </title>
 
339
 
 
340
        <para>
 
341
            Example:
 
342
        </para>
 
343
 
 
344
        <informaltable frame="none">
 
345
            <tgroup cols="1" align="left" colsep="0" rowsep="0">
 
346
                <colspec colname="col1" colnum="1" />
 
347
                <tbody>
 
348
                    <row>
 
349
                        <entry>
 
350
int4   i;
 
351
 
 
352
// convert ints to floats using the default rounding mode.
 
353
float4 f = convert_float4( i );
 
354
 
 
355
// convert ints to floats. integer values that cannot
 
356
// be exactly represented as floats should round up to the
 
357
// next representable float.
 
358
float4 f = convert_float4_rtp( i );
 
359
                        </entry>
 
360
                    </row>
 
361
                </tbody>
 
362
            </tgroup>
 
363
        </informaltable>
 
364
    </refsect2>
 
365
 
 
366
<!-- ================================ SPECIFICATION  -->
 
367
<!-- Set the "uri" attribute in the <olink /> element to the "named destination" for the PDF page
 
368
-->
 
369
    <refsect1 id="specification"><title>Specification</title>
 
370
        <para>
 
371
            <imageobject>
 
372
                <imagedata fileref="pdficon_small1.gif" format="gif" />
 
373
            </imageobject>
 
374
 
 
375
            <olink uri="convert_T">OpenCL Specification</olink>
 
376
        </para>
 
377
    </refsect1>
 
378
 
 
379
<!-- ================================ ALSO SEE  -->
 
380
 
 
381
    <refsect1 id="seealso"><title>Also see</title>
 
382
        <para>
 
383
            <citerefentry href="scalarDataTypes"><refentrytitle>Scalar Data Types</refentrytitle></citerefentry>,
 
384
            <citerefentry href="vectorDataTypes"><refentrytitle>Vector Data Types</refentrytitle></citerefentry>
 
385
        </para>
 
386
    </refsect1>
 
387
 
 
388
<!-- ============================== COPYRIGHT -->
 
389
<!-- Content included from copyright.inc.xsl -->
 
390
 
 
391
    <refsect3 id="Copyright"><title></title>
 
392
        <imageobject>
 
393
                <imagedata fileref="KhronosLogo.jpg" format="jpg" />
 
394
        </imageobject>
 
395
        <para />
 
396
    </refsect3>
 
397
 
 
398
<!-- 17-Oct-2011 -->
 
399
</refentry>
 
400