Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print(0.1+0.2==0.3)
#4
(Mar-04-2024, 06:59 AM)akbarza Wrote: what is your opinion about it?
1)True
2)False
3) machine dependence
4)...
choice 3, machine dependence is not true?
Choice 2 occurs for example if Python is implemented using IEEE754 with 64 bits, that is to say 11 bits of exponent and 52 bits of mantissa plus the sign bit. This is usually the case. It would also be the choice if Python was implemented using 128 bits or 256 bits.

I don't think the choice of 64 bits is enforced in the specification of the Python language.

I made tests that showed that if a machine implemented IEEE754 on 65 bits instead of 64, that is to say 53 bits of mantissa instead of 52, then on such a machine, 0.1 + 0.2 == 0.3 would be true, so Choice 3 is a valid choice since we can't exclude that someone is crazy enough to implement Python with mad architectures.
akbarza likes this post
« We can solve any problem by introducing an extra level of indirection »
Reply


Messages In This Thread
print(0.1+0.2==0.3) - by akbarza - Mar-04-2024, 06:59 AM
RE: print(0.1+0.2==0.3) - by buran - Mar-04-2024, 08:50 AM
RE: print(0.1+0.2==0.3) - by Axel_Erfurt - Mar-04-2024, 12:46 PM
RE: print(0.1+0.2==0.3) - by Gribouillis - Mar-04-2024, 02:02 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020