From https://en.cppreference.com/w/c/language/conversion :
Real floating-integer conversions
A finite value of any real floating type can be implicitly converted to any integer type. Except where covered by boolean conversion above, the rules are:
Your code does:
float test = -6.25f;
(unsigned int)test;
The type unsigned int
is not able to represent the value -6
. You can't convert a float
with a negative value to unsigned
type. Your code has undefined behavior.
Do you know how can force intel compiler to make output 0 as arm compiler?
Check if the value is less than 0.
int result_1 = test < 0 ? 0 : <something else here>;
If your compiler if following ANNEX F addition to the C language, then according to https://port70.net/~nsz/c/c11/n1570.html#F.4
[...] if the integral part of the floating value exceeds the range of the integer type, then the ''invalid'' floating- point exception is raised and the resulting value is unspecified [...]
In which case anyway, the resulting value is unspecified, so it may differ between compilers as you experience.