Boost logo

Boost Users :

Subject: Re: [Boost-users] Numeric_cast from int to float
From: Hermann Rodrigues (hermann.rodrigues_at_[hidden])
Date: 2009-01-26 14:39:33


On Mon, Jan 26, 2009 at 4:13 PM, Matthieu Brucher
<matthieu.brucher_at_[hidden]> wrote:
>> So, I am still confident that converting integers greater that 2^24 to
>> float using boost::numeric_cast must raise an exception. Has this
>> behavior changed in the newer versions of Boost?
>
> To be more accurate, this would mean testing the value in the
> numerical cast, as there are no ASM instruction to do this on the
> usual platforms. The cost that this would induce is probably too high
> a price to pay. I think the best course of action would be to write
> your own cast for this specific use.

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.

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.

Best.

--
Hermann Rodrigues
hermann_at_[hidden]
Centro de Sensoriamento Remoto / UFMG
http://www.csr.ufmg.br/dinamica

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