This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.

497. meaning of numeric_limits::traps for floating point types

Section: 17.3.5.2 [numeric.limits.members] Status: CD1 Submitter: Martin Sebor Opened: 2005-03-02 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [numeric.limits.members].

View all issues with CD1 status.

Discussion:

18.2.1.2, p59 says this much about the traps member of numeric_limits:

static const bool traps;
-59- true if trapping is implemented for the type.204)
Footnote 204: Required by LIA-1.

It's not clear what is meant by "is implemented" here.

In the context of floating point numbers it seems reasonable to expect to be able to use traps to determine whether a program can "safely" use infinity(), quiet_NaN(), etc., in arithmetic expressions, that is without causing a trap (i.e., on UNIX without having to worry about getting a signal). When traps is true, I would expect any of the operations in section 7 of IEEE 754 to cause a trap (and my program to get a SIGFPE). So, for example, on Alpha, I would expect traps to be true by default (unless I compiled my program with the -ieee option), false by default on most other popular architectures, including IA64, MIPS, PA-RISC, PPC, SPARC, and x86 which require traps to be explicitly enabled by the program.

Another possible interpretation of p59 is that traps should be true on any implementation that supports traps regardless of whether they are enabled by default or not. I don't think such an interpretation makes the traps member very useful, even though that is how traps is implemented on several platforms. It is also the only way to implement traps on platforms that allow programs to enable and disable trapping at runtime.

Proposed resolution:

Change p59 to read:

True if, at program startup, there exists a value of the type that would cause an arithmetic operation using that value to trap.

Rationale:

Real issue, since trapping can be turned on and off. Unclear what a static query can say about a dynamic issue. The real advice we should give users is to use cfenv for these sorts of queries. But this new proposed resolution is at least consistent and slightly better than nothing.