ScalarCast
Applicability
Product |
Supported |
|---|---|
√ |
|
√ |
|
x |
|
√ |
|
x |
|
x |
Function
Converts the data type of a scalar.
Prototype
1 2 | template <typename T, typename U, RoundMode roundMode> __aicore__ inline U ScalarCast(T valueIn) |
Parameters
Parameter |
Description |
||
|---|---|---|---|
T |
Data type of valueIn. The value can be float. |
||
U |
Data type after conversion. The value can be half or int32_t. |
||
roundMode |
Precision conversion mode. The type is RoundMode. RoundMode is an enumeration type used to control the precision conversion mode. The definition is as follows:
For ScalarCast, only float-to-half (f322f16) and float-to-int32_t (f322s32) conversion types are supported. The corresponding supported RoundMode values are as follows:
The precision conversion rules of ScalarCast is the same as those of Cast. For details, see Table 1. |
Parameter |
Input/Output |
Description |
|---|---|---|
valueIn |
Input |
Scalar of the data type to be converted. |
Returns
valueIn of the U type.
Restrictions
None
Example
1 2 3 | float valueIn = 2.5; // Output (valueOut): 3 int32_t valueOut = AscendC::ScalarCast<float, int32_t, AscendC::RoundMode::CAST_ROUND>(valueIn); |