[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#262104: info: misleading description in "FP Exceptions" node



Package: glibc-doc
Version: 2.3.2.ds1-12
Severity: minor

Hi,

in libc.info, there's a section listing exceptions raised on FP errors (node
"FP Exceptions"):

The exceptions defined in IEEE 754 are:

`Invalid Operation'
...
       7. Conversion of an unrecognizable input string.

Reading this, I became concerned of, when doing strtod, sscanf etc., if I
have to worry about raised FP exceptions instead of just checking the return
value (in case of invalid input string).  But looking through the sources and
finally trying myself, I found there is no reason:

egon@base:~/work-test$ cat fp-test.c
#include <stdio.h>  // sscanf
#include <fenv.h>  // fegetexcept

int main(int argc, const char** argv)
{
  if (feenableexcept(fegetexcept() | FE_ALL_EXCEPT) != -1) {
    float f;
    printf("converted: %d\n", sscanf("huh", "%f", &f));
    f = 0;
    printf("%f\n", f / f);
  }
  return 0;
}
egon@base:~/work-test$ gcc -o fp-test fp-test.c -lm
egon@base:~/work-test$ ./fp-test 
converted: 0
Floating point exception
egon@base:~/work-test$ 

...the unsuccessful scan did not raise the exception.  So, if I'm right (and
I hope to be, to not waste your precious time :) ), I would suggest a note
like this:

Note:

In GNU LIBC, there are no FP exceptions raised on failed input string-to-FP
conversions.  When using functions strtof, scanf and similar, you just have
to check their return value(s) to see if the conversion succeeded.

Regards,

-- 
Egon Eckert, Heaven Industries, s.r.o.
E-mail: egon@heaven.industries.cz

Never be afraid to try something new. Remember, amateurs built the
ark; professionals built the Titanic. -- Anonymous



Reply to: