A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1629.htm below:

f(inf) is inf being a range error

Fixing a contradiction.

7.12.1 paragraph 5 has:

A floating result overflows if the magnitude of the mathematical result is finite but so large that the mathematical result cannot be represented without extraordinary roundoff error ...

For example, exp(+DBL_MAX) is a very very large finite number that cannot be represented as a double, so is overflow, so is a range error.

7.12.1 paragraph 6 has:

The result underflows if the magnitude of the mathematical result is so small that the mathematical result cannot be represented, without extraordinary roundoff error ...

For example, exp(-DBL_MAX) is a very very small (non-zero) finite number that cannot be represented as a double, so is underflow, so is a range error.

For the type double, since +DBL_MAX < +infinity and -infinity < -DBL_MAX, it follows that |+/-DBL_MAX| < |+/-infinity|; that is, the magnitude of infinity is larger than the magnitude of any finite number. So, if x being DBL_MAX is "too large", then x being infinity is also "too large".

exp(+infinity) is exactly +infinity (which is representable, but not finite, so it is not an overflow, so is not a range error).

exp(-infinity) is exactly zero (which is representable, so it is not an underflow, so is not a range error).

However, 7.12.6.1 exp() has:

A range error occurs if the magnitude of x is too large.

This is a contradiction in the C standard. x being +/-infinity is "too large", so exp(too large) is a range error. But, exp(+/-infinity) is exact and representable, so is not a range error. Other standards, such as IEEE-754-2008, LIA (Language Independent Arithmetic) and POSIX-2008 all consider exp(+/-infinity) as NOT an error.

There appears to be two ways to fix this contradiction. The first is to somehow add infinity to the definition of overflow, underflow, and range error. This seems like a non-starter.

The other way to fix this contradiction is to remove infinity from the "too large" requirement. That can be done by adding "finite" giving:

A range error occurs if the magnitude of finite x is too large.

Or, it can be done by altering the first sentence of 7.12.1 to:

The behavior of each of the functions in <math.h> is specified for all representable finite values of its input arguments, except where stated otherwise.

That also matches the floating-point number model in 5.2.4.2.2 (that only has finite numbers).


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4