Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the C++ standard not mention __STDC_IEC_559__?

Tags:

c++

c++11

According to C++11 standard [c.math], the <cmath> header is same as Standard C library header <math.h>.
(Of course, there are several differences, --- namespace, overloads etc. --- but these can be ignored here.)
And according to C99 standard annex F, "An implementation that defines __STDC_IEC_559__ shall conform to the specifications in" the annex F.

Ex. The atan2 may cause a domain error if both arguments are zero, but It must not if __STDC_IEC_559__ is defined.

In C99, many behavior is also dependent on whether __STDC_IEC_559__ is defined or not.

However, it seems that __STDC_IEC_559__ is not mentioned anywhere in C++11 standard.
If so, shall a C++ implementation conform to the specifications in the annex F?

I think that std::numeric_limits<T>::is_iec559() is a substitute, but it seems to mention about only type.

like image 906
Mitsuru Kariya Avatar asked May 22 '14 09:05

Mitsuru Kariya


1 Answers

The C++ standard (n3797) includes the C standard library by reference, see s1.2/2.

The library described in Clause 7 of ISO/IEC 9899:1999 and Clause 7 of ISO/IEC 9899:1999/Cor.1:2001 and Clause 7 of ISO/IEC 9899:1999/Cor.2:2003 is hereinafter called the C standard library.

With the qualifications noted in Clauses 18 through 30 and in C.4, the C standard library is a subset of the C++ standard library.

The standard contains no mention of that symbol, and I would not expect it be defined, since it appears to be specific to Standard C. By not defining that symbol, C++ is not bound by the contents of Annex F.

Instead the C++ standard contains multiple mentions of IEC 559 in a rather more C++-like form. For example,

Shall be true for all specializations in which is_iec559 != false

There is a specific mention in 18.3.2.4/56.

static constexpr bool is_iec559;

True if and only if the type adheres to IEC 559 standard.218

Meaningful for all floating point types.

I think it would be fair to say that C++ includes all the same capabilities (or lack of them), but adapted to the C++ world.

like image 58
david.pfx Avatar answered Oct 23 '22 12:10

david.pfx