tact-lang / tact-docs

Tact main documentation
https://docs.tact-lang.org
57 stars 39 forks source link

Emphasize integer range in explanation of repeat statement #347

Closed jeshecdom closed 4 months ago

jeshecdom commented 4 months ago

In the repeat statement explanation:

https://docs.tact-lang.org/book/statements#repeat-loop

The sentence "Number of repetitions must be a non-negative 32-bit Int", could be understood as saying that it is a 32-bit unsigned integer. So, it may be better to include the allowed integer range. For example, as:

Number of repetitions must be a non-negative 32-bit Int, i.e., a number x such that 0 <= x <= 2^31 - 1.

Or simply:

Number of repetitions must be a non-negative integer (>= 0) smaller or equal than 2^31 - 1.

anton-trunov commented 4 months ago

It's actually

If the number of times is less than -2^31 or greater than 2^31 - 1, range check exception is thrown.

novusnota commented 4 months ago

Not quite, range check is only thrown when the number is greater than $2^{31} - 1$. If the number is less than zero and even as low as $-2^{256}$, there is no exception

jeshecdom commented 4 months ago

So, I guess that executing the repeat a negative number of times is equivalent to executing it 0 times?

novusnota commented 4 months ago

@jeshecdom exactly so. I'll clarify that in a PR in a moment