Why does int/float multiplication lead to different results?

Viewed 620

If I multiply a float and and integer like below, why does all multiplications lead to a differnt result? My expectation was a consistent result. I thought in both cases the int value gets implicitly converted to a float before multiplication. But there seems to be a difference. What is the reason for this differnt handling?

int multiply(float val, int multiplier)
{
    return val * multiplier;
}

int multiply2(float val, int multiplier)
{
    return float(val * multiplier);
}

float val = 1.3f;

int result0 = val * int(10); // 12
int result1 = 1.3f * int(10); // 13
int result3 = multiply(1.3f, 10); //12 
int result4 = multiply2(1.3f, 10); // 13

Thank you Thorsten

1 Answers
Related