1

The erfcf(FLT_MAX) produces 0.0f and sets errno to ERANGE.

The erff(FLT_MAX) produces 1.0f and does not set errno to ERANGE.

In both cases returned results differ from the "true results" (i.e. obtained with infinite precision).

Why ERANGE is set only for erfcf?

pmor
  • 5,392
  • 4
  • 17
  • 36
  • 1
    `erfc(large_and_positive)` underflows; `erf(large_and_positive)` does not. – Mark Dickinson Jun 15 '22 at 18:34
  • 1
    Thanks. My initial guess was the same. Per C11 "range error occurs if the mathematical result of the function cannot be represented in an object of the specified type, **due to extreme magnitude**". So, in case of `erff(FLT_MAX)` the result of the function cannot be represented in an object of the specified type _not_ due to extreme magnitude. – pmor Jun 16 '22 at 13:53

1 Answers1

0
  1. As a general rule, math functions setting errno is considered an obsolescent feature, because IEEE infinities, NaNs, and floating point exception flags are considered a superior method of reporting errors for mathematical calculations. This does not seem to be stated explicitly anywhere in the Standard, but see generally 7.12.1 Treatment of error conditions [in math functions], particularly the discussion of math_errhandling.

  2. erfc(x) goes to zero, and erf(x) to one, quite rapidly as x increases; erfc(10) is already on the order of 2e-45. The most precise way to describe the result of erfcf(FLT_MAX) and of erff(FLT_MAX), in the terminology of IEEE 754, is as an inexact zero or one, respectively. However, even in an implementation conforming to Annex F, library functions are not required to report inexactness (F.10p8).

  3. A mathematical result that is so close to zero that it cannot be represented exactly is an underflow condition (7.12.1p6). Underflow conditions may, but are not required to, set errno to ERANGE.

  4. A mathematical result that is so close to one that it cannot be represented exactly is not considered to be any of the error conditions described in 7.12.1, and therefore is not to be reported by setting errno.

zwol
  • 135,547
  • 38
  • 252
  • 361