Search code examples
floating-pointprecisionnumerical-methods

Is the computation precise in 64-bit floating point


Let's say I have probabilities between 0.1 and 0.2(10,000 of them), and I want to store the result, which is the multiplication of all these probabilities in the 64-bit floating point? Is it a reliable computation?


Solution

  • This will not work. If you multiply together 10000 numbers, all less than 0.2, the result will be less than 0.2^10000 which is about 1e-7000. The smallest positive number that can be represented in 64-bit double precision floating point is about 2.2e-308 so you will underflow by several thousand orders of magnitude. If you try this you'll just get the result 0.0.

    You may want to add their logs instead.