Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like <em>Martin Ankerl</em> has a few of articles on this, <a href="http://martin.ankerl.com/2012/01/25/optimized-approximative-pow-in-c-and-cpp/" rel="nofollow noreferrer">Optimized Approximative pow() in C / C++</a> is one and it has two fast versions, one is as follows:</p> <pre><code>inline double fastPow(double a, double b) { union { double d; int x[2]; } u = { a }; u.x[1] = (int)(b * (u.x[1] - 1072632447) + 1072632447); u.x[0] = 0; return u.d; } </code></pre> <p>which relies on type punning through a union which is undefined behavior in C++, from the draft standard section <code>9.5</code> <em>[class.union]</em>:</p> <blockquote> <p>In a union, at most one of the non-static data members can be active at any time, that is, the value of at most one of the non-static data members can be stored in a union at any time. [...]</p> </blockquote> <p>but most compilers including <a href="https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Optimize-Options.html#Type_002dpunning" rel="nofollow noreferrer">gcc support this with well defined behavior</a>:</p> <blockquote> <p>The practice of reading from a different union member than the one most recently written to (called “type-punning”) is common. Even with -fstrict-aliasing, type-punning is allowed, provided the memory is accessed through the union type</p> </blockquote> <p>but this is not universal as <a href="http://blog.regehr.org/archives/959" rel="nofollow noreferrer">this article points out</a> and as I <a href="https://stackoverflow.com/a/31080901/1708801">point out in my answer here</a> using <code>memcpy</code> should generate identical code and does not invoke undefined behavior.</p> <p>He also links to a second one <a href="http://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/" rel="nofollow noreferrer">Optimized pow() approximation for Java, C / C++, and C#</a>.</p> <p>The first article also links to his microbenchmarks <a href="http://pastebin.com/DRvPJL2K" rel="nofollow noreferrer">here</a></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. 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.
    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