In Python 3.5, when dividing an even number, why division and gender division give different answers

I'm trying to split a very large even number. 13144131834269512219260941993714669605006625743172006030529504645527800951523697620149903055663251854220067020503783524785523675819158836547734770656069476 I used split and gender separation, but it gives me two different answers, which I think should be the same. Therefore i got

int(x/2) = 6572065917134756165333387211683112531415896759844144557192219233347999705289073358407747856661759761476763448808302430806962124152349175018830474952835072
int(x//2) = 6572065917134756109630470996857334802503312871586003015264752322763900475761848810074951527831625927110033510251891762392761837909579418273867385328034738

Can anyone tell me what leads to differences? Thanks

+4
source share
1 answer

/ true division always produces a floating point result, and you cannot accurately model your number with float:

>>> huge = 13144131834269512219260941993714669605006625743172006030529504645527800951523697620149903055663251854220067020503783524785523675819158836547734770656069476
>>> huge / 2
6.572065917134756e+153
>>> type(huge / 2)
<class 'float'>

That 6 times 10 ^ 153, but floatcan only carry 53 binary precision digits in the mantissa:

>>> import sys
>>> sys.float_info.mant_dig
53

, , .

int() .

// , , , , :

>>> type(huge // 2)
<class 'int'>
+5

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


All Articles