This is so elementary, that I'm sure someone must have reported it at some point...
However, could not find a matching report at a quick glance, so might as well push it here, even if it ends up being a duplicate and wasting everyones time.
Here is a tiny program that demonstrates the issue:
#include <stdio.h>
struct Two_Floats
{
float hi;
float lo;
};
struct Two_Floats broken_Function( struct Two_Floats clips , struct Two_Floats values )
{
if( values.hi <= clips.hi ) values.hi = clips.hi;
if( values.lo >= clips.lo ) values.lo = clips.lo;
return values;
}
struct Two_Floats working_Function( struct Two_Floats clips , struct Two_Floats values )
{
struct Two_Floats temporary = values;
if( temporary.hi <= clips.hi ) temporary.hi = clips.hi;
if( temporary.lo >= clips.lo ) temporary.lo = clips.lo;
return temporary;
}
int main( void )
{
struct Two_Floats values = { -50.0f , 25.0f };
struct Two_Floats limits = { 0.0f , 600.0f };
struct Two_Floats broken = broken_Function( limits , values );
struct Two_Floats working = working_Function( limits , values );
printf("And here we go: < %f , %f > \n", broken.hi , broken.lo );
printf("This was to be: < %f , %f > \n", working.hi , working.lo );
return 0;
}
Output:
And here we go: < -50.000000 , 25.000000 >
This was to be: < 0.000000 , 25.000000 >
Press any key to continue...
Modifying the the pass-by-value argument and returning it gives a wrong result.
Taking a temporary copy and returning it, won't.
Using version 9.009 at windows 10.
Same behavior occurs on both default debug and release configuration, with fast and strict floating point settings.
Peculiar.