Boost logo

Boost Users :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2004-02-26 16:38:15


"King, William D" <William.D.King_at_[hidden]> escribió en el mensaje
news:1F6B51721B46D711A28B0008C7562DE99E94BD_at_ecu.bankofamerica.com...
>
> Hello,
>
> I am seeing a bug that the regression tests miss for numeric_cast<unsigned
> long> with gcc 3.3.2. Specifically, the following code is throwing an
> exception:
>
> double small_value = 1.25;
> unsigned long l=0;
> l = numeric_cast<unsigned long>(small_value); // throws exception!
> unsinged char c=0;
> c = numeric_cast<unsigned char>(small_value); // throws exception!
>
> I am under the impression that numeric_cast is supposed to accept losses
of
> precision (by truncating the fractional values), and to throw exceptions
> only if there is a range or sign error. Is this so?
>
FWIW, the new Numeric Conversions library has recently been accepted into
boost.
It works exactly as you expected, and has a replacement for numeric_cast<>.

Check it out from:

http://personales.ciudad.com.ar/fernando_cacciola/numeric_conversions.zip

HTH

Fernando Cacciola
SciSoft


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net