0

I think there is a bug in Python. When I wanted to sum an integer and a float number Python did it wrong.From GeeksForGeeks İ read "it is not a bug and it is problem of floating-point numbers".But i checked in C++ and the results was true.Why?

I wrote print(12+23.12) and the result was 35.120000000000005

Then I wrote print(23+12.23) and the result was 35.230000000000004

If this is not bug,please say this reason

  • 1
    Floating point math is imprecise. If you want precise math with decimal fractions, check out the `decimal` module. – Samwise Dec 10 '22 at 16:23
  • 1
    It's not a Python bug. It's an incorrect assumption that floating-point values accurately model the real numbers. – chepner Dec 10 '22 at 16:23
  • 1
    If this was a bug in python, you could be sure that someone would have found it in the last decade or two. Rather than assume the language has an issue, it would be worth searching for an explanation – roganjosh Dec 10 '22 at 16:25
  • "I think there is a bug in Python"—while no software is perfect, and Python certainly contains bugs, it is _exceedingly_ unlikely that you will find one in a product as large and established as Python. _Always_ assume that this cannot be true unless you have exhausted every single other possibility. – ChrisGPT was on strike Dec 10 '22 at 16:29
  • How did you check the value in C++? I'm quite sure, that the real value is not `35.12` in C++ either. The output might be different, but that's just a question how a value is prepared for output. – Matthias Dec 10 '22 at 17:11
  • İ checked it in CxxDroid – Ali Heydarov Dec 10 '22 at 17:17

0 Answers0