Title
meaning of numeric_limits::traps for floating point types
Status
cd1
Section
[numeric.limits.members]
Submitter
Martin Sebor

Created on 2005-03-02.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

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.

Date: 2010-10-21.18:28:33

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.

Date: 2005-03-02.00:00:00

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.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2849
2010-10-21 18:28:33adminsetmessages: + msg2848
2005-03-02 00:00:00admincreate