user2019840 - 9 months ago 38

C++ Question

Putting it directly, my question is precisely as stated in the title: in an application being written using C++, is there a way to detect whether floats/doubles denormals are being "normalized" by the compiler/system (e.g. trough DAZ, FTZ, etc)?

If context is needed, what I am trying to accomplish is to detect programaticaly the minimal float/double values. These results, however, depend on whether denormals are or not being "normalized": if they are, the minimal values are given by std's numeric limits min(), otherwise it's given by denorm_min().

Answer

You should simply trust the implementation to return the correct values for `std::numeric_limits`

. If `std::numeric_limits<float>::has_denorm`

is `std::denorm_present`

, then you should assume that regular C++ operators will not implicitly normalize floating-point values.

Note that this is a separate query from `std::numeric_limits<float>::has_iec559`

, which tests for the usage of IEC-559/IEEE-754 floats. So a system can use IEEE-754 floats, but not support denormalized floats. Therefore, implementations which always flush denormalized floats to zero ought to return `std::denorm_absent`

for `has_denorm`

.