program_options: accepting NaNs for doubles

Hi all, program_options does not accept NaN or Inf as valid double input. For example, the following sequence modifies the "Getting Started" first.cpp [1] to accept double input: cp $BOOST_SOURCE/libs/program_options/example/first.cpp . perl -pi -e 's/<int>/<double>/;' first.cpp LDFLAGS="-lboost_program_options" make first # ...or whatever The modified example indeed barfs on NaN or Inf input: $ ./first --compression=5.5 Compression level was set to 5.5. $ ./first --compression=Inf error: in option 'compression': invalid option value 'Inf' $ ./first --compression=NaN error: in option 'compression': invalid option value 'NaN' Two questions: 1) Does this count as a bug? 'std::cin >> foo' doesn't grok Inf or NaNs (on my system anyhow) but methods like strtod() do. Users providing explicit infinities or not-a-numbers as options parameters likely don't do so accidentally. This Inf/NaN behavior is not mentioned in the active tickets. 2) Can anyone suggest a workaround (shy of using string-based parameters and calling strtod myself)? Thanks, Rhys [1] http://www.boost.org/doc/libs/1_47_0/doc/html/program_options/tutorial.html#...

Responding to my own question...
program_options does not accept NaN or Inf as valid double input.
1) Does this count as a bug?
It seems yes as the root cause appears to be a (now fixed for 1.48) bug in lexical_cast (https://svn.boost.org/trac/boost/ticket/5689). I have filed https://svn.boost.org/trac/boost/ticket/5776 against program_options with a milestone matching the lexical_cast bug.
2) Can anyone suggest a workaround (shy of using string-based parameters and calling strtod myself)?
lexical_cast would be a natural choice were it not for the above bug. Cheers, Rhys

Hi Rhys,
I would think the workaround would be the one mentioned in the ticket you
reference, use the trunk version of boost.
Mike
On Thu, Aug 11, 2011 at 2:16 PM, Rhys Ulerich
Responding to my own question...
program_options does not accept NaN or Inf as valid double input.
1) Does this count as a bug?
It seems yes as the root cause appears to be a (now fixed for 1.48) bug in lexical_cast (https://svn.boost.org/trac/boost/ticket/5689). I have filed https://svn.boost.org/trac/boost/ticket/5776 against program_options with a milestone matching the lexical_cast bug.
2) Can anyone suggest a workaround (shy of using string-based parameters and calling strtod myself)?
participants (2)
-
Michael Lindner
-
Rhys Ulerich