Document: WG14 N1467


ilogb


Submitter: Fred J. Tydeman (USA)
Submission Date: 2010-05-10
Related documents: N1428
Subject: ilogb

Background: There appear to be contradictory requirements in C99 on ilogb.

C99 7.12.6.5 The ilogb functions has:

ilogb(x) is (int)logb(x).

and

If the correct value is outside the range of the return type, the numeric result is unspecified.

C99 F.10.3.11 The logb functions has:

logb(+/-0.0) is -infinity.
logb(+/-infinity) is +infinity.

In addition, logb(NaN) is NaN is implied by F.10#11.

None of +/-infinity nor NaN are representable in int. So, that implies F.10.3.5#2

If the correct result is outside the range of the return type, the numeric result is unspecified and the "invalid" floating-point exception is raised.

would apply. But, 7.12.6.5 has specific return values for ilogb(zero), ilogb(infinity), and ilogb(NaN).

So, we really have correct result outside the range of the return type (which raises invalid), but with specified return values.

Proposal

Add to F.9.3.5 The ilogb functions, a new bullet:

-- ilobg(x) raises the "invalid" floating-point exception for x being a NaN, infinity, or zero and has a return value specified in 7.12.6.5.

Add to Raionale:

Since integer types do not have representations of NaN or infinity, ilogb(x) for x being a NaN, infinity, or zero, has return values that cannot be represented. Normally, that would result in an unspecified return value, but ilogb has required return values for those specific cases. The committee does not know of any hardware that has a return value for a finite non-zero value that exceeds the range of int.