Hi
I am scratching my head :
120%60= 0 //OK
49.5%5.5=0 //OK
4.71%1.57=1.57 // how is is possible?
(3*(global::UnityEngine.Mathf.PI/2))%(global::UnityEngine.Mathf.PI/2)= 1.570796 ?
471%157 = 0
It’s quite strange, it seems to link with the variable type.
I need to make this opération :
float d = X -X % (Mathf.PI / 2);
Where X is between 0 and 2Mathf.PI , but the result is not the one expected when X = 3PI/2
Thanks for your help
This should answer all your questions. To explain your exact usecase:
The number 3 * Pi/2 is of course larger than PI/2. That means 3*PI/2 has roughly one digit less behind the “binary point” and the number is probably slightly smaller than your divisor. So the modulo will just return that remainder which is slightly smaller than the divisor you’re using. It’s even possible that after the modulo operation that the result is rounded to the same number as your divisor since the number is not smaller than the original number and you have one digit more behind the binary point.
Over here I’ve posted a table to get a better intuition how many (binary) digits you have before / after the binary point depending on the floating range of a number.