Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Konstruktionsplan's avatar

Explain Code

Hello! Can someone explain this code to me? Why this Tilde?

return ~~(101 * lcg_value());

Thanks! 💖

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

A double tilde is a double NOT bitwise operator.

Whenever used like this, it returns the floor of the value, e.g. 1.99 would round down to 1. It is not exactly the same as a floor function however; whenever dealing with negative numbers, it will act as a ceil function. In effect, it will remove the decimals from the value.

Please or to participate in this conversation.