2

Recently, I have discovered that 1.0e-323 is not considered a zero in Python but 1.0e-324 is. Is there a theoretical reason why the cut is actually made at 1.0e-324? Maybe is stupid question, but without background in CS it is really intriguing to me.

a = 1.0e-323
a == 0
> False

a = 1.0e-324
a == 0
> True
An economist
  • 1,301
  • 1
  • 15
  • 35
  • 6
    What Every Computer Scientist Should Know About Floating-Point Arithmetic https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html – Joe Aug 17 '17 at 13:05
  • 1
    because using binary arithmetic, the closest point to that exact float is 0. – Ma0 Aug 17 '17 at 13:07
  • Thank you both for the explanation and the source. – An economist Aug 17 '17 at 13:09
  • Link in the top answer -> [Python documentation](https://docs.python.org/3/library/sys.html#sys.float_info) -> "section 5.2.4.2.2 of the 1999 ISO/IEC C standard [C99]" – vaultah Aug 17 '17 at 13:09
  • 1
    the subnormal representation allows even smaller values up to about 5 × 10−324 https://en.wikipedia.org/wiki/Double-precision_floating-point_format – Joe Aug 17 '17 at 13:21
  • 1
    Also see https://stackoverflow.com/questions/588004/is-floating-point-math-broken – PM 2Ring Aug 17 '17 at 15:49
  • 2
    @cᴏʟᴅsᴘᴇᴇᴅ: I know this happened a while ago, but reopening a question unilaterally should not be done hastily or quietly. Furthermore, why reopen an obvious duplicate, when you can *add* better (?) links to cover it completely? A couple of your past comments and actions got me thinking that your understanding of how this feature works and when it should be used is a bit flawed. Could you take time to read [this](//meta.stackexchange.com/a/10844) and [this](//meta.stackexchange.com/q/291824), and not be so quick to vote to reopen? In general, please use your privileges more responsibly. – vaultah Aug 17 '17 at 20:02
  • 1
    @vaultah Pinging you one last time. Just keep in mind that I do take feedback and criticism very seriously and will use that as an opportunity to improve. You're free to call me out as much as needed. Thanks. – cs95 Oct 26 '17 at 17:28

0 Answers0