Boost C++ Libraries: Ticket #5689: lexical_cast must understand "inf" and "nan" https://svn.boost.org/trac10/ticket/5689 <p> Some libraries and compilers understand "inf","+inf","nan", and some - not.<br /> Make lexical_cast understand such input and do not depend on particular stringstream/scanf realization. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5689 Trac 1.4.3 Antony Polukhin Fri, 15 Jul 2011 11:20:14 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5689#comment:1 https://svn.boost.org/trac10/ticket/5689#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/73118" title="Fixes #5689. Added code to work with Inf and NaN on any platform">[73118]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5689" title="#5689: Support Requests: lexical_cast must understand &#34;inf&#34; and &#34;nan&#34; (closed: fixed)">#5689</a>. Added code to work with Inf and NaN on any platform </p> Ticket Antony Polukhin Sat, 16 Jul 2011 21:02:37 GMT <link>https://svn.boost.org/trac10/ticket/5689#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5689#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/73155" title="Fixes #5689. Added code to work -NaN on any platform. Removed some warnings">[73155]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5689" title="#5689: Support Requests: lexical_cast must understand &#34;inf&#34; and &#34;nan&#34; (closed: fixed)">#5689</a>. Added code to work -NaN on any platform. Removed some warnings </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 05 Aug 2011 00:58:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5689#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5689#comment:3</guid> <description> <p> please backport this to 1.47 - it's ridiculous that it doesn't work as expected already. I just converted the code which triggered this bug to use stringstream directly but I love to use lexical_cast for it's shortness.... and 1.48 is too far off. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Fri, 05 Aug 2011 03:35:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5689#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5689#comment:4</guid> <description> <p> It is impossible, because: </p> <ul><li>it depends on functions of boost::math that exist only in trunk </li><li>this patch depends on some previous patches for lexical_cast that are only commited in trunk version and are not fully tested </li><li>this fix is a workaround for some rare compiler error, it can wait till 1.48 </li></ul><p> stringstream won`t help you, in 1.47 lexical_cast uses stringstream to convert float types. And VC++ hav no problems with conversion. </p> <p> You can always use a trunk version of boost. It will bring you all the new (but not always stable) features. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 16 Feb 2012 04:22:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5689#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5689#comment:5</guid> <description> <p> using 1.48 version of lexical_cast works for "nan" but throws a error for "NaN". I do not think there is a formal specification for Not-A-Number in string form, but "NaN" is a common usage form. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Thu, 16 Feb 2012 17:24:44 GMT</pubDate> <title>cc, status, type changed; resolution deleted https://svn.boost.org/trac10/ticket/5689#comment:6 https://svn.boost.org/trac10/ticket/5689#comment:6 <ul> <li><strong>cc</strong> <span class="trac-author">antoshkka@…</span> added </li> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Support Requests</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/5689#comment:5" title="Comment 5">anonymous</a>: </p> <blockquote class="citation"> <p> using 1.48 version of lexical_cast works for "nan" but throws a error for "NaN". I do not think there is a formal specification for Not-A-Number in string form, but "NaN" is a common usage form.<br /> </p> </blockquote> <p> There is a formal specification for Not-A-Number strings. According to standard strtod, strtof, and strtold, scanf, sscanf and fscanf functions must parse NaN like that: </p> <pre class="wiki">The expected form of the subject sequence is an optional plus or minus sign, then one of the following: — INF or INFINITY, ignoring case — NAN or NAN(n-char-sequenceopt), ignoring case in the NAN part, where: ... </pre><p> <br /> Last time I`ve been confused by printf functions, they have more strict rules for outputting <a class="missing wiki">NaNs</a>: </p> <pre class="wiki">A double argument representing an infinity is converted in one of the styles [-]inf or [-]infinity — which style is implementation-defined. A double argument representing a NaN is converted in one of the styles [-]nan or [-]nan(n-char-sequence) — which style, and the meaning of any n-char-sequence, is implementation-defined. The F conversion specifier produces INF, INFINITY, or NAN instead of inf, infinity, or nan, respectively. </pre><p> <br /> Great thanks for reporting this bug! </p> Ticket Antony Polukhin Thu, 16 Feb 2012 17:57:57 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5689#comment:7 https://svn.boost.org/trac10/ticket/5689#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/77040" title="More tests for fixed #5689 (issue mentiond in 5th comment)">[77040]</a>) More tests for fixed <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5689" title="#5689: Support Requests: lexical_cast must understand &#34;inf&#34; and &#34;nan&#34; (closed: fixed)">#5689</a> (issue mentiond in 5th comment) </p> Ticket Antony Polukhin Thu, 16 Feb 2012 17:59:33 GMT <link>https://svn.boost.org/trac10/ticket/5689#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5689#comment:8</guid> <description> <p> Fixed in <a class="changeset" href="https://svn.boost.org/trac10/changeset/77039" title="FIx #5689 (issue from 5th comment)">r77039</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>