1e301-10^301 ~= 0 ?

6 visualizzazioni (ultimi 30 giorni)
Robin Lindström
Robin Lindström il 14 Ago 2016
Risposto: Walter Roberson il 14 Ago 2016
Why does 1e301-10^301 not equal zero in matlab, but 1e300-10^300 does?
1e301-10^301 is 1.18961352678223e+285.

Risposta accettata

Walter Roberson
Walter Roberson il 14 Ago 2016
1e301 is computed entirely at parse time, as a double precision number.
10^301 involves computing 10 and 301 at parse time, each as double precision numbers, and then computing the one to the power of the other at run time, resulting in a double precision number. As this is a floating point calculation, it is subject to standard floating point roundoff .
1e301 comes out as the first representable double precision number greater than 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 and 10^301 is one bit different, coming out as the last representable double precision number less than 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 . 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 itself is not exactly representable in double precision.

Più risposte (1)

Azzi Abdelmalek
Azzi Abdelmalek il 14 Ago 2016

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by