Subject: Re: [boost] [Spirit] real_policies<> and 1.0#NAN
From: Joel de Guzman (djowel_at_[hidden])
Date: 2016-06-08 04:34:12
On 08/06/2016 5:00 AM, Pete Bartlett wrote:
> Boost.Spirit is not sure of itself when it comes to parsing representations of infs
nans such as â1.0#NANâ.
> The docs  for the default real_policies<T> for parsing numbers say: â[â¦] with the
additional detection of NaN and Inf as mandated by the C99 Standard and proposed for
inclusion into the C++0x Standard: nan, nan(...), inf and infinity (the matching is
case-insensitive). This corresponds to the following grammar:â
> The first sentence suggests that 1.0#NAN etc will not be parsed. But the grammar
> = -lit("1.0#") >> no_case["nan"]
>>> -('(' >> *(char_ - ')') >> ')')
> = no_case[lit("inf") >> -lit("inity")]
> suggesting that "#1.0NAN" is intended to parsed, but "#1.0INF" is not!
> Then the in-code docs  however suggest that both "1.0#NAN" and "1.0#INF" are
to be parsed:
> <quote> // The second call allows to recognize representation formats starting // with
> a 1.0 (such as 1.0#NAN or 1.0#INF etc.). </quote>
> However, the actual code fails to parse either of these these. This is because in 
the presence of the "0" causes frac_digits to be non-zero and so the
"traits::is_equal_to_one(..)" condition is never tested. In the case "1.#NAN" (without a
zero) frac_digits is zero so the condition is tested and we enter the traits::parse_nan
code, but now the text parsed to this sub-parser is "#NAN" and the parser does not cater
for the initial "#".
> Could the maintainers state which behaviour is intended...hopefully I may be able to
supply a patch to docs/code/tests knowing that.
>  http://www.boost.org/doc/libs/1_61_0/libs/spirit/doc/html/spirit/qi/reference/numeric/real.html
>  <boost/spirit/home/qi/numeric/real_policies.hpp>
Hrmm... Following the standard is the intent. I'm very welcome to suggestions
and of course patches :-)
-- Joel de Guzman http://www.ciere.com http://boost-spirit.com http://www.cycfi.com/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk