Is it possible to predict whether a mathematical operation will lead to overflow?

Let's say you have 2 numbers, for each typical mathematical operation you can predict (without significant overhead), will these operations lead to an overflow of the type that these numbers are currently presented as?

+3
source share
3 answers

Yes.

Assume for simplicity that overflow occurs at 100.

a * b >= 100we overwhelm

Therefore, for a = n, if b >= 100 / n, we have an overflow. If aor bequal to 0, you have no overflow.

- , , . , , , . Ergo, , .

, .

+2

, . , , , , , .

0

For the amount:

MAX_NUMBER - A < B

overflow will happen

0
source

Source: https://habr.com/ru/post/1760640/


All Articles