Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2006-04-19 23:01:15


On Wed, 19 Apr 2006 18:31:14 +0100, Paul A Bristow wrote

> So a) is in principle fixed IMO.
>
> As to b), I had understood that we had agreed that all NaNs could reasonably
> be treated as identical and one would get a NaN (unspecified) back.
> Similarly infinities.
>
> http://article.gmane.org/gmane.comp.lib.boost.devel/134569/match=serializati
> on+nan
>
> But simple
>
> stream << output_value; // write out.
> double read_value;
> stream >> read_value; // read back.
>
> doesn't work for
>
> double output_value = numeric_limits<double>::quiet_NaN(); // output_value
> 1.#QNAN != read_value 1
> double output_value = numeric_limits<double>::infinity(); // output_value
> 1.#INF != read_value 1
>
> So some special flag would be needed to hold the Nan or Inf nature.
>
> If only there was a Standard representation of Nan and Infs. VERY
> shortsighted, making NaNs and infs hardly useable.

Agreed. The types in date_time have the ability to serialize and deserilize
NADT (not a date time), -infinity and +infinity. Why couldn't there be a
simple extension to the numpunct<charT> facet to define an appropriate output
string? Basically something like:

  //see Langer and Kreft p 414...
  template<class charT>
  class numpunct : public locale::facet {
  
    //new functions for nan and infinity
    string_type not_a_number_name() const;
    string_type infinity_name() const;

And you'd have to fix num_get as well.

Jeff


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk