[Bug c++/57034] ternary operator with float infinity in O0

2013-04-23 Thread christopher.hite at jpmorgan dot com


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_limitsint32_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.


[Bug c++/57034] ternary operator with float infinity in O0

2013-04-23 Thread christopher.hite at jpmorgan dot com


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



--- Comment #6 from Christopher Hite christopher.hite at jpmorgan dot com 
2013-04-23 17:26:26 UTC ---

Good, I was a big worried I couldn't convert ints to floats unless the int was

safely mappable.  It rounds which is what I'd expect.



I now think z5 is safe, since int32_t(float(MAX)) wouldn't be evaluated.

const float   fMAX=std::numeric_limitsint32_t::max();

Any (positive) float less than fMax, must be representable in int32_t, though

z5 will never equal MAX-1 or MAX-2



Do you agree?



z5 is definately clearer code than playing with fetestexcept().  I'd guess it's

also faster.


[Bug c++/57034] New: ternary operator with float infinity in O0

2013-04-22 Thread christopher.hite at jpmorgan dot com


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



 Bug #: 57034

   Summary: ternary operator with float infinity in O0

Classification: Unclassified

   Product: gcc

   Version: 4.7.2

Status: UNCONFIRMED

  Severity: normal

  Priority: P3

 Component: c++

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: christopher.h...@jpmorgan.com





std::numeric_limitsfloat::infinity() should be greater than

std::numeric_limitsint32_t::max().



The ternary operator produces a different result in O0.  I would expect y to be

MAX.  The correct code is produced in O1+, but O0 seems to produce the wrong

code.



Appologies for the additonal variables, but they are useful in debugging.


[Bug c++/57034] ternary operator with float infinity in O0

2013-04-22 Thread christopher.hite at jpmorgan dot com


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



--- Comment #1 from Christopher Hite christopher.hite at jpmorgan dot com 
2013-04-22 17:36:52 UTC ---

Created attachment 29915

  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=29915

unit test of bug + build instructions in comment