Boost logo

Boost Users :

From: linux (linux_at_[hidden])
Date: 2008-02-07 12:23:57


Actually, I was hoping Boost had an float-to-integer conversion so I
could look at the implementation. I need to convert a float to int, but
not in OpenGL Shading Language, which is "C like" but it doesn't have
pointers, bit-shifts etc.

Ed

Frank Mori Hess wrote:
> On Thursday 07 February 2008 07:40 am, Fernando Cacciola wrote:
>
>> Then I suspect you don't really want to "convert" the float to int but to
>> get at the value-representation of the float.
>> If that's the case, you can do this:
>>
>> char* float_value_rep =
>> static_cast<char*>(static_cast<void*>(&your_float));
>>
>
> Isn't this what reinterpret_cast is for? It wouldn't require bouncing through
> a void*. Also, to the original poster, don't succumb to the temptation to
> cast to anything other than a char* (like an int*) or you'll end up in strict
> aliasing violation hell.
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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