Checking for IEEE 754 Floating Point Standard in C
Determining whether a C compiler adheres to the IEEE 754 floating point standard is typically accomplished through a compiler define. However, the technique used for C may not apply directly to C .
C -Specific Approach
Fortunately, C offers a straightforward method to accomplish this check using the numeric_limits class:
std::numeric_limits::is_iec559;
This expression evaluates to true if IEEE 754 is utilized by the compiler and false otherwise. A similar check can be performed for the float type:
std::numeric_limits::is_iec559;
Alternative Method
As an alternative to the numeric_limits approach, you can adapt the second part of Adam's response for C :
#include
int main() {
// Check for IEEE 754 compliance by checking for a finite number of float exponents.
if (std::numeric_limits::max_exponent == std::numeric_limits::max()) {
// Compiler uses IEEE 754.
} else {
// Compiler does not use IEEE 754.
}
}
This approach relies on the fact that IEEE 754 defines a specific range of exponents for floating point numbers. If the compiler's maximum exponent matches the maximum size of an integer, it is likely adhering to IEEE 754.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3