Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2001-02-26 02:27:52


In message <3A93094C.864C36E5_at_[hidden]>, Greg Chicares
<chicares_at_[hidden]> writes
>> In message <3A90B900.E6B07CE5_at_[hidden]>, Greg Chicares
>> <chicares_at_[hidden]> writes
>> >Would it be worthwhile to modify lexical_cast to reflect the inherent
>> >precision of floating-point numbers?
[...]
>> and (2) how
>> practical is it to root out all of the edge cases?
>
>Do you mean denormals, NaNs, and infinities? Is it too cavalier
>to say "let them throw if they will"?

Nope, not cavalier at all. I was referring to types rather than specific
values -- ie other numeric types.

>> That said, there may be a solution if you select how you set the
>> precision based on numeric_limits<>::is_specialized. This would
>> discriminate in favour of built-ins, but at least would not actively
>> discriminate against other types. However, I have not tried this
>> approach out.
>
>An approach that I believe is equivalent and simpler is to set the
>precision to no less than the default of 6. This leads me to the
>revised suggestion:
>
> interpreter.precision
> (std::max
> (interpreter.precision()
> ,1 + static_cast<std::streamsize>
> (
> std::max
> (std::numeric_limits<Source>::digits10
> ,std::numeric_limits<Target>::digits10
> )
> )
> )
> );

Yes, this looks good.

Kevlin
____________________________________________________________

  Kevlin Henney phone: +44 117 942 2990
  Curbralan Limited mobile: +44 7801 073 508
  mailto:kevlin_at_[hidden] fax: +44 870 052 2289
  http://www.curbralan.com
____________________________________________________________


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