1

I used Python 3.9.4 (default, Apr 5 2021, 01:50:46).

The result of 2**256 - 2**224 + 2**192 - 2*96 - 1 should be 115792089210356248762697446949407573530086143415290314195533631308867097853951. However, if you try it in the Python REPL, you get something wrong.

>>> 2**256 - 2**224 + 2**192 + 2*96 - 1
115792089210356248762697446949407573530086143415211086033019366971273553903807

I can check the correct output by subtracting it piece by piece.

>>> x = 115792089210356248762697446949407573530086143415290314195533631308867097853951
>>> x -= 2**256
>>> x
-26959946660873538059280334323183841250350249843923952699046031785985
>>> x += 2**224
>>> x -= 2**192
>>> x
79228162514264337593543950335
>>> x -= 2**96
>>> x
-1

Can anybody explain what's happening here?

Cerberton
  • 376
  • 2
  • 7
  • 16
Junwei WANG
  • 239
  • 2
  • 12

1 Answers1

4

It is a typo

2**256 + ... -  2*96 - 1

Should be

2**256 + ... -  2**96 - 1

Normally Integer overflows do not happen in python. There are float overflows.