is_floating_point
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
x |
|
x |
|
x |
Function Usage
Checks whether a type is the floating-point type during program compilation. This API can be used for type checking and conditional processing during compilation.
Prototype
1 2 | template <typename T> struct is_floating_point; |
Parameters
Parameter |
Description |
|---|---|
T |
Types to be checked, including basic data types and modifier types |
Restrictions
None
Returns
The static constant member value of is_floating_point is used to obtain the returned Boolean value. The values of is_floating_point<Tp>::value are as follows:
- true: Tp is of the floating-point type.
- false: Tp is not of the floating-point type.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // Custom test type struct MyStruct{}; // Function type whose return value is of the floating-point type using FuncType = double(int); // Legal floating point type AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<float>::value); AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<double>::value); AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<long double>::value); // Floating point types limited by CV AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<const float>::value); AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<volatile double>::value); // non-floating point type AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<int>::value); AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<bool>::value); AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<double*>::value); AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<float&>::value); AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<double[5]>::value); AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<FuncType>::value); AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<MyStruct>::value); AscendC::printf("AscendC::Std::is_floating_point::value:%d\n", AscendC::Std::is_floating_point<void>::value); |
// Execution result AscendC::Std::is_floating_point::value:1 AscendC::Std::is_floating_point::value:1 AscendC::Std::is_floating_point::value:1 AscendC::Std::is_floating_point::value:1 AscendC::Std::is_floating_point::value:1 AscendC::Std::is_floating_point::value:0 AscendC::Std::is_floating_point::value:0 AscendC::Std::is_floating_point::value:0 AscendC::Std::is_floating_point::value:0 AscendC::Std::is_floating_point::value:0 AscendC::Std::is_floating_point::value:0 AscendC::Std::is_floating_point::value:0 AscendC::Std::is_floating_point::value:0
Parent topic: Type Traits