I have the following function which is suppose to convert a floating point number to int32. The problem is that for negative numbers it just doesn't work (my if statement isn't executing). I've tried a similar program for a conversion from float to int16 and everything works just fine. Sry if this is too simple , but I just can't figure out what I'm missing and why it doesn't work for negative values.
#define MaxInt32 2147483647
#define MinInt32 -2147483648
…
bool CastFloatToInt32 ( float fNumber, int32 *ConvertedValue) {
bool CastStatus = False;
if ( ( fNumber >= MinInt32 ) && ( fNumber <= MaxInt32 ) ) {
*ConvertedValue = ( int32 ) ( fNumber );
CastStatus = True;
} else {
if (fNumber < MinInt32) {
*ConvertedValue = MinInt32;
} else {
*ConvertedValue = MaxInt32;
}
}
return CastStatus;
}