## table of contents

EXPLICIT CONVERSIONS(3clc) | OpenCL Manual | EXPLICIT CONVERSIONS(3clc) |

# NAME¶

Explicit_conversions_with_convert_T() - Explicit type conversions using convert_T()## ¶

convert_destType(sourceType) destType
convert_destType<_sat>< roundingMode>
(sourceType) destTypen
convert_destTypen<_sat>< roundingMode>
(sourceType) |

# DESCRIPTION¶

Explicit conversions may be performed using the convert_destType(sourceType) suite of functions. These provide a full set of type conversions between supported types (see**scalarDataTypes**(3clc)) except for the following types:

**bool**,

**half**,

**size_t**,

**ptrdiff_t**,

**intptr_t**,

**uintptr_t**, and

**void**. The number of elements in the source and destination vectors must match. 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. The full form of the scalar convert function is:

destTypeconvert_destType<_sat><_roundingMode>(sourceType)

destTypenconvert_destTypen<_sat><_roundingMode>(sourceTypen)

**char**,

**uchar**,

**short**,

**ushort**,

**int**,

**uint**,

**long**,

**ulong**,

**float**, and built-in vector types derived therefrom. The operand and result type must have the same number of elements. The operand and result type may be the same type in which case the conversion has no effect on the type or value of an expression. Conversions between integer types follow the conversion rules specified in sections 6.3.1.1 and 6.3.1.3 of the C99 specification except for out-of-range behavior and saturated conversions which are described in section 6.2.3.3 below. Rounding Modes.PP Conversions to and from floating-point type shall conform to IEEE-754 rounding rules. Conversions may have an optional rounding mode modifier described in the table below.

Modifier | Rounding Mode Description |

_rte | Round to nearest even |

_rtz | Round towards zero |

_rtp | Round toward positive infinity |

_rtn | Round toward negative infinity |

no modifier specified | Use the default rounding mode for this destination type, _rtz for conversion to integers or the default rounding mode for conversion to floating-point types. |

## Examples¶

In the following example,**convert_int4**converts a

**uchar4**vector u to an

**int4**vector c:

uchar4 u; int4 c = convert_int4(u); |

**convert_int**converts a float scalar f to an int scalar i:

float f; int i = convert_int(f); |

## ¶

Example:short4 s; // negative values clamped to 0 ushort4 u = convert_ushort4_sat( s ); // values > CHAR_MAX converted to CHAR_MAX // values < CHAR_MIN converted to CHAR_MIN char4 c = convert_char4_sat( s ); |

## ¶

Example:float4 f; // values implementation defined for // f > INT_MAX, f < INT_MIN or NaN int4 i = convert_int4( f ); // values > INT_MAX clamp to INT_MAX, values < 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 ); |

## ¶

Example:int4 i; // convert ints to floats using the default 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 ); |

# SPECIFICATION¶

**OpenCL Specification**[1]

# SEE ALSO¶

**scalarDataTypes**(3clc),

**vectorDataTypes**(3clc)

# AUTHORS¶

**The Khronos Group**

# COPYRIGHT¶

Copyright © 2007-2011 The Khronos Group Inc.# NOTES¶

- 1.
- OpenCL Specification

page 207, section 6.2.3 - Explicit Conversions

06/18/2014 | The Khronos Group |