Any programmer can explain how to express this code in math terms?
public static int px32(int p){
int h = 0;
for (int i = 0; i < p; i = i + 32) { h++; }
return h;
}
Any programmer can explain how to express this code in math terms?
public static int px32(int p){
int h = 0;
for (int i = 0; i < p; i = i + 32) { h++; }
return h;
}
Summarizing the thread so far, the code above (along with a if(p <= 0) { return 0; }) computes
\begin{matrix}
&{\rm R\acute{o}cherz} &\text{achille hui}\\
h={}&\left\lceil\dfrac{\max\{0,p\}}{32}\right\rceil &=\left\lfloor\dfrac{\max\{0,p\}+31}{32}\right\rfloor & \qquad \text{for } p \in \mathbb{Z}.
\end{matrix}
However, since $32 =2^5$ is a power of $2$, perhaps the fastest way to compute $h$ is (zwim):
return (p<0) ? 0 : ((p+31)>>5);.
I tried if(p <= 0){ return 0; } return p / 32; but did not give the same result.
– Jonathan Costa Apr 26 '18 at 19:02Any way for no need use?
– Jonathan Costa Apr 26 '18 at 19:15