Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes there is a problem here, __result must be set to zero.</p> <p>And I can see one more possible problem in your code -- result is comparing with<code>0.99*enough</code> in one case and with<code>0.95*enough</code> in other case, that is highly suspicious to be a typo. I suggest you to rewrite this macro, explicitly stating "satisfying" conditions and to simplify logic, checking good conditions first. Like this:</p> <pre><code>#define SEARCH_EXIT_CASE(__result, __enough) ((__result) &gt; 0.95 * (__enough) &amp;&amp; (__result) &lt; 1.2 * (__enough)) #define BENCH_INNER(loop_body, enough) { \ static iter_t __iterations = 1; \ int __enough = get_enough(enough); \ iter_t __n; \ double __result = 0.; \ \ while(!SEARCH_EXIT_CASE(__result, __enough)) { \ start(0); \ for (__n = __iterations; __n &gt; 0; __n--) { \ loop_body; \ } \ __result = stop(0,0); \ /* good result */ \ if (SEARCH_EXIT_CASE(__result, __enough)) { \ break; \ } \ /* failure cases */ \ if (__result &gt; 150.) { \ double tmp = __iterations / __result; \ tmp *= 1.1 * __enough; \ __iterations = (iter_t)(tmp + 1); \ } else { \ if (__iterations &gt; (iter_t)1&lt;&lt;27) { \ __result = 0.; \ break; \ } \ __iterations &lt;&lt;= 3; \ } \ __result = 0.; \ } /* while */ \ save_n((uint64)__iterations); settime((uint64)__result); \ } </code></pre> <p>Also I suggest to define other magical constants like <code>1&lt;&lt;27, 1.1, 3, 150.0</code> to have meaningful names like<code>MAX_ITER</code>, <code>CORRECTION_RATE</code>,<code>INCREASE_RATE</code>,<code>RESULT_OVERFLOW</code>, etc...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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