[LLVMbugs] [Bug 19611] New: stringstream operator>>(double&) does not correctly convert "INFINITY" to an infinite value
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Apr 29 17:06:55 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=19611
Bug ID: 19611
Summary: stringstream operator>>(double&) does not correctly
convert "INFINITY" to an infinite value
Product: libc++
Version: 3.4
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: greg at gregfiumara.com
CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
Classification: Unclassified
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 at 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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140430/b11bbafc/attachment.html>
More information about the llvm-bugs
mailing list