Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if C++ compiler uses IEEE 754 floating point standard

People also ask

What languages use IEEE 754?

Most languages use IEEE754 doubles as their basic data type for rational numbers (C and C++ via double , Python via float ). In addition to representing floating point values, IEEE 754 also allows representation of two other numeric data types.

How floating-point numbers are represented using the IEEE standard 754?

The IEEE 754 standard specifies two precisions for floating-point numbers. Single precision numbers have 32 bits − 1 for the sign, 8 for the exponent, and 23 for the significand. The significand also includes an implied 1 to the left of its radix point.

What are the 2 IEEE standards for floating-point numbers?

There are three binary floating-point basic formats (encoded with 32, 64 or 128 bits) and two decimal floating-point basic formats (encoded with 64 or 128 bits). The binary32 and binary64 formats are the single and double formats of IEEE 754-1985 respectively.


Actually you have an easier way to achieve this in C++. From the C++ standard 18.2.1.1 the class numeric_limits exists within std. In order to access said static member you simply do this:

std::numeric_limits<double>::is_iec559;

Or:

std::numeric_limits<float>::is_iec559;

Which should return true if IEEE 754 is in use, false otherwise.

As an alternative method, the second part of Adam's answer should do it also for C++.