Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Motion 46: finalise interval literals



On 2013-07-12 16:21:52 +0200, Vincent Lefevre wrote:
> On 2013-07-12 14:37:47 +0100, John Pryce wrote:
> > BTW. What does denote infinity in a Turkish C program?
> 
> Interpretation of a C program is locale-independent. But locales
> affect strtod(). I haven't done any test yet. There are 4 possibilities
> to write "inf", but I don't know which ones are recognized in practice
> and whether there may be errors in the documentation or the the C
> library.

I had raised the issue in 2005 and 2006 for the revision of the
IEEE 754 standard, but it has been ignored. The final version of
the IEEE 754-2008 standard says:

  Conversion of external character sequences "inf" and "infinity"
  (regardless of case) with an optional preceding sign, to a supported
  floating-point format shall produce an infinity (with the same sign
  as the input).

So, in Turkish locales, where "i" and "I" are different letters
(even in a case-insensitive way[*]), "INF" is not guaranteed to
produce an infinity.

[*] You can see the dot over the "i" as an accent.

The C99 standard says:

    7.20.1.3 The strtod, strtof, and strtold functions
[...]
 3  The expected form of the subject sequence is an optional plus or minus
    sign, then one of the following:
    — a nonempty sequence of decimal digits optionally containing a
      decimal-point character, then an optional exponent part as defined
      in 6.4.4.2;
    — a 0x or 0X, then a nonempty sequence of hexadecimal digits
      optionally containing a decimal-point character, then an optional
      binary exponent part as defined in 6.4.4.2;
    — INF or INFINITY, ignoring case
    — NAN or NAN(n-char-sequence_opt), ignoring case in the NAN part,
[...]
 5  In other than the "C" locale, additional locale-specific subject
    sequence forms may be accepted.

(and AFAIK, C11 says the same thing). So, this is the opposite: "INF"
will give an infinity, but nothing is guaranteed for "inf" in Turkish
locales.

I've done some tests against the glibc and reported the following bug:

  http://sourceware.org/bugzilla/show_bug.cgi?id=15744

Note also the behavior concerning the decimal-point character.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)