Boost logo

Boost Users :

Subject: Re: [Boost-users] Numeric_cast from int to float
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-01-26 22:29:03


AMDG

Hermann Rodrigues wrote:
> I agree with you that testing the value in numeric_cast is a bad
> thing. But I think that numeric_cast is not delivering what it
> advertises. For me a well formed cast is always one where A can be
> converted to B and back to A without any lose in the representation.
> Unfortunately, with the current implementation A (an integer) can be
> converted to B (a float) but the resulting value can not be casted
> back to an integer representing A.
>

numeric_cast is doing exactly what it is supposed to. It makes sure that
the source value is within the range of the destination type. If it
required
reversibility, then conversion from double to float would almost always
fail,
for example.

> Maybe It is a good idea to provide an additional implementation of a
> function similar to numeric_cast (say strict_numeric_cast) behaving
> like that.
>

In Christ,
Steven Watanabe


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