http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57034



--- Comment #4 from Christopher Hite <christopher.hite at jpmorgan dot com> 
2013-04-23 11:35:25 UTC ---

64-bit.



Thanks for pointing out I was converting to float and back.  Both of the

following work:

    int32_t z3=(qFuture >= double(MAX) ? MAX : double(qFuture) );  //works

    int32_t z4=(qFuture >= double(MAX) ? MAX : int32_t(qFuture) );  // works



The following also works:

    int32_t z5=(qFuture >= MAX ? MAX : int32_t(qFuture) );  //works



which seems to contradict what you were saying that if the integral value can't

be perfectly represented by the float it fails.



    const float   fMAX=std::numeric_limits<int32_t>::max();

    (gdb) fMAX = 2.14748365e+09



Is this bad code?  Should I convert to double before float?  What about larger

ints?



All I'm tring to do is convert float to int clipping at max int.  What's the

best way to do it?  Can I calculate the highest float that is convertible to an

int?  Or do I have to check that the conversion fails.

Reply via email to