Modify

Ticket #5689 (closed Support Requests: fixed)

Opened 3 years ago

Last modified 2 years ago

lexical_cast must understand "inf" and "nan"

Reported by: apolukhin Owned by: apolukhin
Milestone: Boost 1.48.0 Component: lexical_cast
Version: Boost Development Trunk Severity: Regression
Keywords: inf nan fininte Cc: pbristow@…, antoshkka@…

Description

Some libraries and compilers understand "inf","+inf","nan", and some - not.
Make lexical_cast understand such input and do not depend on particular stringstream/scanf realization.

Attachments

Change History

comment:1 Changed 3 years ago by apolukhin

  • Status changed from new to closed
  • Resolution set to fixed

(In [73118]) Fixes #5689. Added code to work with Inf and NaN on any platform

comment:2 Changed 3 years ago by apolukhin

(In [73155]) Fixes #5689. Added code to work -NaN on any platform. Removed some warnings

comment:3 Changed 3 years ago by anonymous

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.

comment:4 Changed 3 years ago by apolukhin

It is impossible, because:

  • it depends on functions of boost::math that exist only in trunk
  • this patch depends on some previous patches for lexical_cast that are only commited in trunk version and are not fully tested
  • this fix is a workaround for some rare compiler error, it can wait till 1.48

stringstream won`t help you, in 1.47 lexical_cast uses stringstream to convert float types. And VC++ hav no problems with conversion.

You can always use a trunk version of boost. It will bring you all the new (but not always stable) features.

comment:5 follow-up: ↓ 6 Changed 2 years ago by anonymous

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.

comment:6 in reply to: ↑ 5 Changed 2 years ago by apolukhin

  • Cc antoshkka@… added
  • Status changed from closed to reopened
  • Resolution fixed deleted
  • Type changed from Bugs to Support Requests

Replying to anonymous:

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.

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:

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:
...


Last time I`ve been confused by printf functions, they have more strict rules for outputting NaNs?:

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.


Great thanks for reporting this bug!

Last edited 2 years ago by apolukhin (previous) (diff)

comment:7 Changed 2 years ago by apolukhin

  • Status changed from reopened to closed
  • Resolution set to fixed

(In [77040]) More tests for fixed #5689 (issue mentiond in 5th comment)

comment:8 Changed 2 years ago by apolukhin

Fixed in r77039

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.