C++ double giving wrong answer for Just 17 DIGITS !!!

Revision en3, by dawud, 2021-08-19 13:23:21

Hi, Recently while practicing I found this problem, Please run this code in your local machine.

Code

If you run this code you should see something like this

Output

Your can also see this code running in IDEONE
You can see there from i = 16 , the program is giving wrong output.
There should be all 1s in every number.
Can anyone please tell me

  • Why this is giving wrong result even in this small range ?
  • And how to avoid this type of calculation problem ?

Thanks in advance ❤️❤️❤️

Tags double, calculation, #c++17(64), wrong ouput

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English dawud 2021-08-19 13:23:21 2 Tiny change: ', \nRecent while pra' -> ', \nRecently while pra'
en2 English dawud 2021-08-19 13:22:50 4
en1 English dawud 2021-08-19 13:21:20 1097 Initial revision (published)