Boost logo

Boost :

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:
> Hi,
> Boost.Spirit is not sure of itself when it comes to parsing representations of infs
> and
nans such as “1.0#NAN”.
> The docs [1] 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
> itself
then says:

> <quote>
> nan
> = -lit("1.0#") >> no_case["nan"]
>>> -('(' >> *(char_ - ')') >> ')')
> ;
> inf
> = no_case[lit("inf") >> -lit("inity")]
> ;
> </quote>
> suggesting that "#1.0NAN" is intended to parsed, but "#1.0INF" is not!
> Then the in-code docs [2] however suggest that both "1.0#NAN" and "1.0#INF" are
> intended
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 [3]
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.

> Regards,
> Pete
> [1]
> [2] <boost/spirit/home/qi/numeric/real_policies.hpp>
> [3]<boost/spirit/home/qi/numeric/detail/real_impl.hpp>

Hrmm... Following the standard is the intent. I'm very welcome to suggestions
and of course patches :-)


Joel de Guzman

Boost list run by bdawes at, gregod at, cpdaniel at, john at