python - Why are the results of integer division and converting to an int after division different for large numbers? -


  प्रिंट (10 ** 40 // 2) प्रिंट (int (10 ** 40/2)) < / कोड>  

कोड का आउटपुट:

  500000000000000000000000000000000000000000 500000000000000000151893014213501833445376  

क्यों विभिन्न मूल्यों? दूसरा प्रिंट () का उत्पादन क्यों दिखता है?

अस्थायी 10 ** 40 // 2 का बिंदु प्रतिनिधित्व सटीक नहीं है:

  & gt; & gt; & gt; प्रारूप (फ्लोट (10 ** 40/2), '.0f') '500000000000000000151893014213501833445376'  

यही कारण है कि अस्थायी अंक अंकगणित केवल एक सन्निकटन है, खासकर जब आप अपने सीपीयू सही ढंग से मॉडल हो सकता है (जैसा कि फ़्लोटिंग पॉइंट को हार्डवेयर में संभाला जाता है)।

पूर्णांक डिवीज़न को कभी भी 10 ** 40 संख्या को एक फ्लोट के रूप में प्रतिनिधित्व नहीं करना है, यह केवल विभाजित करना है

  • पायथन ट्यूटोरियल में
  • Li>

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -