Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Too understand what is going on you can made little changes to you program. According to the default argument promotions rules from C standard <code>printf()</code> promotes <code>float</code> to <code>double</code>. Thus we can take a look on what is going on with numbers in the operations in <code>double</code> format (more fraction part digits):</p> <pre><code> while (j&gt;=0) { printf ("%3.18lf ", j*0.1); printf ("%3.18lf ", broj); printf ("%3.18lf ", broj - j*0.1); /*printf ("%3.18lf ", (double)(broj-(j*0.1)));*/ break; j--; } </code></pre> <p>The output:</p> <pre><code>9 0.000000000000000000 0.000000000000000000 0.000000000000000000 0. red 0.100000000000000006 0.100000001490116119 0.000000001490116114 1. red 0.200000000000000011 0.200000002980232239 0.000000002980232228 2. red 0.300000000000000044 0.300000011920928955 0.000000011920928938 3. red 0.400000000000000022 0.400000005960464478 0.000000005960464455 4. red 0.500000000000000000 0.500000000000000000 -0.000000000000000028 5. red 0.600000000000000089 0.600000023841857910 0.000000023841857877 6. red 0.700000000000000067 0.699999988079071045 -0.000000011920928994 7. red 0.800000000000000044 0.800000011920928955 0.000000011920928911 8. red 0.900000000000000022 0.899999976158142090 -0.000000023841857960 9. red </code></pre> <p>Output shows <strong>effects caused by finite precision of numbers</strong>. Thus third column is supposed to be consisting of zeros only but it doesn't, because of this effect.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload