I have code that runs on different platforms that seems to get different results. I am looking for a proper explanation.
I expected casting to unsigned
This conversion is undefined and therefore not portable.
C99/C11 6.3.1.4
When a finite value of real floating type is converted to an integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part cannot be represented by the integer type, the behavior is undefined.
According to C11 6.3.1.4 footnote 61:
The remaindering operation performed when a value of integer type is converted to unsigned type need not be performed when a value of real floating type is converted to unsigned type. Thus, the range of portable real floating values is (−1, Utype_MAX+1).