<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - stringstream operator>>(double&) does not correctly convert "INFINITY" to an infinite value"
   href="http://llvm.org/bugs/show_bug.cgi?id=19611">19611</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>stringstream operator>>(double&) does not correctly convert "INFINITY" to an infinite value
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.4
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>greg@gregfiumara.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>A stringstream containing the string "INFINITY" does not produce an infinite
value when calling 'operator>>(double&).' It instead produces the double 0.

In the latest revision of the C++ standard, section 27.7.2.2.2 states that the
locale's num_get<> should be used for parsing. Section 22.4.2.1.2 states that,
in num_get<>'s Stage 3, "For a floating-point value, the function strtold (is
used)." The C11 standard states in section 7.22.1.3 that, "The expected form of
the subject sequence is an optional plus or minus sign, then one of the
following...INF or INFINITY, ignoring case." It follows then that a
stringstream containing "INFINITY" should convert to an infinite value.

Below is a piece of code and resulting output demonstrating that the result of
operator>>() does not result in a value that returns true from isinf(). This
code was compiled and run on OS X 10.9.2, with "Apple LLVM version 5.1
(clang-503.0.40) (based on LLVM 3.4svn)."

#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>

void
doTest(
    const std::string &str)
{
    double val1 = std::strtod(str.c_str(), nullptr);
    std::cout << str << " - std::isinf from strtod: " << std::boolalpha <<
        std::isinf(val1) << '\n';

    std::stringstream sstream(str);
    double val2;
    sstream >> val2;
    std::cout << str << " - std::isinf from stringstream: " <<
        std::boolalpha << std::isinf(val2) << '\n';

    std::cout << val1 << " vs " << val2 << '\n';

    std::cout << std::endl;
}

int
main()
{
    doTest("INFINITY");
    doTest("+INF");

    return (0);
}

$ clang++ -Wall -Wextra -std=c++11 inf.cpp -o inf
[gfiumara@vito ~]$ ./inf 
INFINITY - std::isinf from strtod: true
INFINITY - std::isinf from stringstream: false
inf vs 0

+INF - std::isinf from strtod: true
+INF - std::isinf from stringstream: true
inf vs inf</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>