Answer the question
In order to leave comments, you need to log in
What does int i = *(int*)&x; mean?
float interesting_function(float x){
float xhalf = 0.5f*x;
int i = *(int*)&x;
i = 0x5f3759df - (i>>1);
x = *(float*)&i;
x = x*(1.5f - xhalf*x*x);
return x;
}
Answer the question
In order to leave comments, you need to log in
&x
- the address (pointer) is taken, at which the value of the variable x is located (int*)
- the designation that with the value of the address that was received earlier, you need to work as a int
type (although it was earlier float
)
* - we get the value at this address, but it will no longer be float
, a int
. Which results in a i
completely different number. Only in the binary representation nothing has changed
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question