Boost logo

Boost Users :

Subject: Re: [Boost-users] Numeric_cast from int to float
From: Matthieu Brucher (matthieu.brucher_at_[hidden])
Date: 2009-01-26 14:09:26


2009/1/26 Hermann Rodrigues <hermann.rodrigues_at_[hidden]>:
>>> I always thought that the conversion from int to float could raise an
>>> exception when the int can not be properly represented as a float.
>>
>> Well, in this case, even casting 2 should raise an exception :|
>
> But the IEEE spec says that every integer less than 2^24 can be
> exactly represented as a single precision floating point number...
> (http://en.wikipedia.org/wiki/Floating_point)

Sorry, I may confuse with something else. At least, if you try 2.6, it
will print as 2.5999...

> 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?
>
> Best.

No, I don't think so, and I don't think it should raise an exception either.

Matthieu

-- 
Information System Engineer, Ph.D.
Website: http://matthieu-brucher.developpez.com/
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn: http://www.linkedin.com/in/matthieubrucher

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