Yes, this code is badly broken and invokes undefined behavior. In particular, notice these two lines:
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
Since the object *(long *)&y
has type long
, the compiler is free to assume it cannot alias an object of type float
; thus, the compiler could reorder these two operations with respect to one another.
To fix it, a union should be used.