{"id":7011,"date":"2015-10-19T14:00:00","date_gmt":"2015-10-19T14:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2015\/10\/19\/do-you-prefer-fast-or-precise\/"},"modified":"2019-02-18T18:04:57","modified_gmt":"2019-02-18T18:04:57","slug":"do-you-prefer-fast-or-precise","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/do-you-prefer-fast-or-precise\/","title":{"rendered":"Do You Prefer Fast or Precise?"},"content":{"rendered":"<h3>What is this Blog About?<\/h3>\n<p>My name is Jim Hogg, a Program Manager in the Compilers team.<\/p>\n<p>We would like your feedback on a feature of the Visual C++ compiler that affects the code we generate for floating-point operations. Your answers will help determine what we do. <strong>You can vote via <a href=\"http:\/\/www.instant.ly\/s\/6cd68\">survey<\/a> &#8212; it should not take you more than a few minutes to fill out!<\/strong><\/p>\n<h3>OK, I&#8217;m Still Reading . . .<\/h3>\n<p>The C and C++ languages let you declare variables of type <span style=\"color: #0000ff\">float<\/span> or <span style=\"color: #0000ff\">double<\/span>. We call these &ldquo;floating-point&rdquo; types. And the Visual C++ compiler lets you specify how it should treat calculations involving these floating-point variables. The options we discuss in this blog are <span style=\"color: #0000ff\">\/fp:fast<\/span> and <span style=\"color: #0000ff\">\/fp:precise<\/span>.<\/p>\n<p>Today&rsquo;s default is <span style=\"color: #0000ff\">\/fp:precise<\/span>. This blog asks for your feedback on whether we should change the default to <span style=\"color: #0000ff\">\/fp:fast<\/span>. This change would make your code run faster; but might reduce the accuracy of the results, depending upon the calculations involved.<\/p>\n<p>There are many excellent articles that explain floating-point in detail. This blog, by contrast, includes an appendix providing a homely overview &ndash; enough for you to form an opinion on the issue of changing the default to <span style=\"color: #0000ff\">\/fp:fast<\/span>. Readers who want to dig deeper may explore the links at the end of this post.<\/p>\n<p>[Note that you have control either way: you can specify that the compiler should follow <span style=\"color: #0000ff\">\/fp:fast<\/span> or <span style=\"color: #0000ff\">\/fp:precise<\/span> down to the level of each .cpp file, or even each function]<\/p>\n<p>Please let us know what you think, after reading this blog post, by filling out <a href=\"http:\/\/www.instant.ly\/s\/6cd68\">this short survey<\/a>.<\/p>\n<h3>Notation<\/h3>\n<p>This blog uses the notation 1.2E+34 as short-hand for 1.2 * 10<sup>34<\/sup>. If the &ldquo;fraction&rdquo; part is 1.0, we abbreviate further: so 1.0E+23 is shortened to E+23.<\/p>\n<h3>Floating Point Basics<\/h3>\n<p>In C++, a <span style=\"color: #0000ff\">float<\/span> can store a value in the 3 (approximate) disjoint ranges { [-E+38, -E-38], 0, [E-38, E+38] }. Each <span style=\"color: #0000ff\">float<\/span> consumes 32 bits of memory. In this limited space, a <span style=\"color: #0000ff\">float<\/span> can only store approximately 4 billion different values. It does this in a cunning way, where adjacent values for small numbers lie close together; while adjacent values for big numbers lie far apart. You can count on each <span style=\"color: #0000ff\">float<\/span> value being accurate to about 7 decimal digits.<\/p>\n<h3>Floating Point Calculations<\/h3>\n<p>We all understand how a computer calculates with <span style=\"color: #0000ff\">int<\/span>s. But what about <span style=\"color: #0000ff\">float<\/span>s? One obvious effect is that if I add a big number and a small number, the small one may simply get lost. For example, E+20 + E-20 results in E+20 &ndash; there are not enough bits of precision within a <span style=\"color: #0000ff\">float<\/span> to represent the precise\/exact\/correct value.<\/p>\n<p>Similarly, each calculation using <span style=\"color: #0000ff\">float<\/span>s has to round the precise result to fit within the space available (actually 23 bits). Depending upon the calculation, the result may differ a little, or a lot, from the mathematical result (the one you&#8217;d get if you had lots and lots of bits available).<\/p>\n<p>Here is a simple example:<\/p>\n<pre class=\"scroll\" style=\"padding-left: 30px\"><code class=\"cplusplus\">int main() {<br \/> float inc = 0.000001, sum = 0.0;<br \/> for (int i = 1; i &lt;= 1000000; ++i) sum += inc;<br \/> printf(\"Sum = %f \\n\", sum);<br \/>}<\/code><\/pre>\n<p>You would expect this program to add <span style=\"color: #0000ff\">inc<\/span> (one-millionth) to <span style=\"color: #0000ff\">sum<\/span>, one million times, resulting in an answer of 1.0. But one-millionth can only be represented approximately as a <span style=\"color: #0000ff\">float<\/span> (actually 0x358637bd), so the result obtained is not 1.0, but 1.009039.<\/p>\n<p>To scare ourselves even more, note that calculations with <span style=\"color: #0000ff\">float<\/span>s do not obey all rules of algebra. For example, associativity of addition states that: (a + b) + c == a + (b + c). But floats don&rsquo;t quite abide by that rule. For example:<\/p>\n<ul>\n<li>(E-10 + E10) + -E10 = E10 + -E10 = 0<\/li>\n<li>E-10 + (E10 + -E10) = E-10 + 0 = E-10<\/li>\n<\/ul>\n<p>So results can differ, depending upon the order in which we perform the operations.<\/p>\n<p>Floating-point calculations don&rsquo;t obey all the laws of algebra &ndash; but in many cases, it&rsquo;s &ldquo;close enough&rdquo; to the mathematically precise answer. [Eg: if we calculate the stress on a bridge truss to be 1.2593 tonnes, but the accurate value is 1.2592 tonnes, we&rsquo;re likely happy: the bridge won&rsquo;t fall down]<\/p>\n<h3>What Does \/fp:fast Do?<\/h3>\n<p>By throwing the <span style=\"color: #0000ff\">\/fp:fast<\/span> switch, you tell the compiler it should pretend that <span style=\"color: #0000ff\">float<\/span>s (and <span style=\"color: #0000ff\">double<\/span>s) obey the rules of simple algebra (associativity and distributivity). This allows the compiler to optimize your code so that it runs faster. It trades off accuracy for speed. (It also lets the compiler play a fast-and-loose with that sub-species of floats called <span style=\"color: #0000ff\">NaN<\/span>s &ndash; &ldquo;Not a Number&rdquo; &ndash; see below)<\/p>\n<h3>How Fast is \/fp:fast?<\/h3>\n<p>Just how much speedup will you get by enabling <span style=\"color: #0000ff\">\/fp:fast<\/span>? Here are results we found using a few common benchmarks:<\/p>\n<table style=\"padding-left: 30px\" border=\"0\">\n<tbody>\n<tr>\n<td>Name<\/td>\n<td>&nbsp; &nbsp;Area<\/td>\n<td>&nbsp; &nbsp;Speedup (x86)<\/td>\n<\/tr>\n<tr>\n<td>Parsec<\/td>\n<td>&nbsp; &nbsp;Next-Gen Shared Memory<\/td>\n<td>&nbsp; &nbsp;1.58<\/td>\n<\/tr>\n<tr>\n<td>Eigen<\/td>\n<td>&nbsp; &nbsp;Linear Algebra<\/td>\n<td>&nbsp; &nbsp;1.03<\/td>\n<\/tr>\n<tr>\n<td>Spec FP 2006<\/td>\n<td>&nbsp; &nbsp;CPU &amp; Memory<\/td>\n<td>&nbsp; &nbsp;1.03<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&ldquo;Speedup&rdquo; is defined as follows: denote the time to execute the benchmark, when compiled under <span style=\"color: #0000ff\">\/fp:precise<\/span>, as <span style=\"color: #0000ff\">Tprecise<\/span>. Correspondingly, <span style=\"color: #0000ff\">Tfast<\/span>. Then &ldquo;Speedup&rdquo; is <span style=\"color: #0000ff\">Tprecise\/Tfast<\/span>.<\/p>\n<p>Note that the speedup you achieve will depend on the details of your App. For example, we measured a huge range of speedups among the individual Parsec benchmarks: from 1.0 (ie, no speedup) up to a massive 5.2x!<\/p>\n<h3>How Inaccurate is \/fp:fast?<\/h3>\n<p>As with speedup, accuracy of results will vary App to App. If your App, or test program, computes a simple result, then comparison is simple. But if your App computes hypersonic airflow round an airfoil, comparison is more challenging.<\/p>\n<p>If your App is a game, then some calculations need only be accurate enough to plot the right color on the right pixels (so a display of 2048 columns needs an accuracy of 1 part in a few thousand). With game Apps, it&rsquo;s unlikely you would even see any difference in the display between <span style=\"color: #0000ff\">\/fp:fast<\/span> and <span style=\"color: #0000ff\">\/fp:precise<\/span>.&nbsp; [Xbox games are compiled, by default, with <span style=\"color: #0000ff\">\/fp:fast<\/span>]<\/p>\n<h3>Counter Example<\/h3>\n<p>The explanations so far would lead you to expect that <span style=\"color: #0000ff\">\/fp:fast<\/span> will sometimes (maybe always?) produce a result that is less accurate than <span style=\"color: #0000ff\">\/fp:precise<\/span>. As a simple example, let&rsquo;s consider the sum of the first million reciprocals, or Sum(1\/n) for n = 1..1000000. I calculated the approximate result using <span style=\"color: #0000ff\">float<\/span>s, and the correct result using Boost&rsquo;s <span style=\"color: #0000ff\">cpp_dec_float<\/span> (to a precision of 100 decimal digits). With <span style=\"color: #0000ff\">\/O2<\/span> level of optimization, the results are:<\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td>float \/fp:precise<\/td>\n<td>&nbsp; &nbsp;14.3574<\/td>\n<\/tr>\n<tr>\n<td>float \/fp:fast<\/td>\n<td>&nbsp; &nbsp;14.3929<\/td>\n<\/tr>\n<tr>\n<td>cpp_dec_float&lt;100&gt;<\/td>\n<td>&nbsp; &nbsp;14.39272672286<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>So the <span style=\"color: #0000ff\">\/fp:fast<\/span> result is nearer the correct answer than the <span style=\"color: #0000ff\">\/fp:precise<\/span>!&nbsp;<\/p>\n<p>How can this be?&nbsp; With <span style=\"color: #0000ff\">\/fp:fast<\/span> the auto-vectorizer emits the SIMD <span style=\"color: #0000ff\">RCPPS<\/span> machine instruction, which is both faster and more accurate than the <span style=\"color: #0000ff\">DIVSS<\/span> emitted for <span style=\"color: #0000ff\">\/fp:precise<\/span>.<\/p>\n<p>This is just one specific case. But the point is that even a complete error analysis won&rsquo;t tell you whether <span style=\"color: #0000ff\">\/fp:fast<\/span>is acceptable in your App &ndash; there&rsquo;s more going on. The only way to be sure is to test your App under each regime and compare answers.<\/p>\n<h3>What about Doubles?<\/h3>\n<p>This blog has described what happens with floats under <span style=\"color: #0000ff\">\/fp:fast<\/span>. <span style=\"color: #0000ff\">double<\/span>s are similar to <span style=\"color: #0000ff\">float<\/span>s, but occupy 64 bits, rather than 32; they have more bits dedicated to both significand and exponent. In some sense (which we won&rsquo;t spell out), they obey the rules of algebra more closely than <span style=\"color: #0000ff\">float<\/span>s. But you can still observe the effects of rounding errors and their propagation through calculation. <span style=\"color: #0000ff\">\/fp:fast<\/span> affects the behavior of both <span style=\"color: #0000ff\">float<\/span>s and <span style=\"color: #0000ff\">double<\/span>s.<\/p>\n<h3>Next Steps?<\/h3>\n<p>Please try an App, or test programs, with <span style=\"color: #0000ff\">\/fp:fast<\/span> rather than the default of <span style=\"color: #0000ff\">\/fp:precise<\/span>. Compare speed and accuracy. Based on this experience, please tell us whether you would agree for us to change the default for the Visual C++ compiler to <span style=\"color: #0000ff\">\/fp:fast<\/span>. &nbsp;<strong>Let us know what you think, by filling out&nbsp;<a href=\"http:\/\/www.instant.ly\/s\/6cd68\">this short survey<\/a>.<\/strong><\/p>\n<h3>Appendices<\/h3>\n<p>The next few sections, numbered A1, A2, etc provide a little more detail on floating-point. If this whets your appetite for more, please follow the links at the end of the post.<\/p>\n<h3>A1. Integers<\/h3>\n<p>An <span style=\"color: #0000ff\">int<\/span>variable in Visual C++ is 32 bits wide. It can store any whole number in the range -2,147483,648 to 2,147,483,647, inclusive. Adjacent values are spread evenly along the real number line, each lying 1 unit away from its neighbor.<\/p>\n<h3>A2. Floating Point Format<\/h3>\n<p>Calculations in science or engineering need to represent fractional values, whose range is also wider than the 4 billion or so afforded by the <span style=\"color: #0000ff\">int<\/span>s. How can we possibly represent such an enormous range of numbers within the 32 bits that comprise a <span style=\"color: #0000ff\">float<\/span>? Answer: we divide our precious 32 bits into 3 chunks, like this:<\/p>\n<ul>\n<li>S, a 1-bit sign. 0 denotes positive. 1 denotes negative.&nbsp;<\/li>\n<li>V, a 23-bit &ldquo;significand&rdquo;. A binary fraction, where bits range in value from 2-1 to 2-23. (Actually, we normalize the original binary number so as to make its most significant bit a 1; which we therefore don&rsquo;t need to store; so we really achieve 24 bits of precision)<\/li>\n<li>E, an 8-bit exponent. As an 8-bit, unsigned integer, this field can store values [0, 255]. But the values 0 and 255 are reserved (used to denote zeros, sub-normals, infinities and <span style=\"color: #0000ff\">NaN<\/span>s (see links for details). From the stored exponent value, we subtract 127 (the exponent &ldquo;bias&rdquo; &ndash; fixed for all <span style=\"color: #0000ff\">float<\/span>s) to get the actual exponent, in the range [-126, 127].<\/li>\n<\/ul>\n<p>The value of a <span style=\"color: #0000ff\">float<\/span> is given by: (-1)S * (1 + V) * 2 (E &ndash; 127). &nbsp;Here is an example:<\/p>\n<p style=\"padding-left: 30px\">0 &nbsp; &nbsp; 0111 1110 &nbsp; &nbsp; 101 0000 0000 0000 0000 0000<\/p>\n<ul>\n<li>S = sign = 0, so this is a positive number<\/li>\n<li>E = exponent = 0111 1110, or 126 (decimal). Subtract 127 to get the actual exponent of -1.<\/li>\n<li>V = significand = 1 + (1 * 0.5) + (0 * 0.25) + (1 * 0.125) = 1.625<\/li>\n<\/ul>\n<p>So the value of this particular <span style=\"color: #0000ff\">float<\/span> is 1.625 * 2-1 = 0.8125<\/p>\n<p>We can readily see that the smallest <span style=\"color: #0000ff\">float<\/span> magnitude is therefore: 1 * 2^(-126) or about E-38. And the largest is: 2 * 2^127, or about E+38. (The interested reader can explore the topic of &ldquo;sub-normal&rdquo; values, which lie closer to zero, in links at the end of the blog)<\/p>\n<h3>A3. How Do They Do That?<\/h3>\n<p>We appear to have achieved the impossible! Within 32 bits, <span style=\"color: #0000ff\">float<\/span>s can represent any number in the approximate range [-E38, +E38]. This is vastly wider than of a 32-bit <span style=\"color: #0000ff\">int<\/span>, which spans approximately [-2E9, +2E9]. What&rsquo;s going on?<\/p>\n<p>One way to span the wide range would be to use an <span style=\"color: #0000ff\">int<\/span>, but multiply its value by a big number, such as E29. That would let us span the range [-2E38, +2E38]. But the smallest number after zero we could represent would be many miles away, at E29! [We would call this a fixed-point, rather than floating-point, format]. Such a system is doomed to failure. We need something better.<\/p>\n<p>In fact, <span style=\"color: #0000ff\">float<\/span>s vary the distance between neighbors: small values, such as E-20, lie very close together; large values, such as E+20, lie &lsquo;miles&rsquo; apart. As you proceed thru the range, you need to take bigger and bigger jumps to reach the next <span style=\"color: #0000ff\">float<\/span> value. So <span style=\"color: #0000ff\">float<\/span>s allow us to represent a finite number of values in the approximate range [-E38, +E38] &ndash; but not all such possible values. Here are 3 examples of adjacent floats (they differ by the least significant bit in their significand):<\/p>\n<ul>\n<li>0 &nbsp; &nbsp; 0011 1111 &nbsp; &nbsp; 000 0000 0000 0000 0000 0000 ~= 5.42101E-20<\/li>\n<li>0 &nbsp; &nbsp; 0011 1111 &nbsp; &nbsp; 000 0000 0000 0000 0000 0001 ~= 5.4210115E-20<\/li>\n<\/ul>\n<p style=\"padding-left: 30px\">(The ~= means approximately equal). So these two very small, neighboring values, lie about 0.000015E-20 (1.5E-25) apart.&nbsp; (ie, a handful of yocto-metres)<\/p>\n<ul>\n<li>0 &nbsp; &nbsp; 0111 1111 &nbsp; &nbsp; 000 0000 0000 0000 0000 0000 = 1.0&nbsp;<\/li>\n<li>0 &nbsp; &nbsp; 0111 1111 &nbsp; &nbsp; 000 0000 0000 0000 0000 0001 ~= 1.000 000 1&nbsp;<\/li>\n<\/ul>\n<p style=\"padding-left: 30px\">So these two, middle-of-the-road, neighboring values, lie about E-7 apart. (ie, 100 nano-metres)<\/p>\n<ul>\n<li>0 &nbsp; &nbsp; 1100 0010 &nbsp; &nbsp; 000 0000 0000 0000 0000 0000 ~= 1.4757395E+20&nbsp;<\/li>\n<li>0 &nbsp; &nbsp; 1100 0010 &nbsp; &nbsp; 000 0000 0000 0000 0000 0001 ~= 1.4757397E+20&nbsp;<\/li>\n<\/ul>\n<p style=\"padding-left: 30px\">So these two very large, neighboring values, lie about 2E14 apart! (ie, a light-week)<\/p>\n<h3>A4. Rounding Errors &ndash; Analogy<\/h3>\n<p>Use a pocket calculator to work out:&nbsp; 1.23 * 2.45 * 3.67. &nbsp;I get the answer 11.059545.<\/p>\n<p>Now repeat, but round each intermediate result to hold just 3 significant digits. So we get:<\/p>\n<ul>\n<li>1.23 * 2.45 = 3.0135, rounded gives 3.01&nbsp;<\/li>\n<li>3.01 * 3.67 = 11.0467, rounded give 11.05&nbsp;<\/li>\n<\/ul>\n<p>This answer is slightly wrong.&nbsp; It is 0.009545 too small. And that&rsquo;s because we forced intermediate results to fit within the 3 decimal digits of our hobbled calculator. A similar thing happens when the computer uses <span style=\"color: #0000ff\">float<\/span>s &ndash; the calculated answer drifts up or down from the mathematically correct answer, because intermediate results are made to fit within the <span style=\"color: #0000ff\">float<\/span>&rsquo;s limited-size. [This is a simplification &ndash; see links for details]<\/p>\n<h3>A5. Nasty Numbers<\/h3>\n<p>Given some <span style=\"color: #0000ff\">float<\/span> variable, <span style=\"color: #0000ff\">x<\/span>, the compiler would like to assume that any intermediate calculation involving the expression <span style=\"color: #0000ff\">(x &ndash; x)<\/span> can be replaced by 0. But that&rsquo;s not true if <span style=\"color: #0000ff\">x<\/span> has any of the special values <span style=\"color: #0000ff\">NaN<\/span>, +infinity or &ndash;infinity.&nbsp; (See later link for explanation). If you specify <span style=\"color: #0000ff\">\/fp:fast<\/span>, the compiler will optimize <span style=\"color: #0000ff\">(x &ndash; x)<\/span> to zero. If not, it will perform the calculation, and thereby run more slowly. If <span style=\"color: #0000ff\">x<\/span> happens to have the value <span style=\"color: #0000ff\">NaN<\/span>, then the correct result for <span style=\"color: #0000ff\">(x &#8211; x)<\/span> would have been, not 0, but <span style=\"color: #0000ff\">NaN<\/span>.<\/p>\n<h3>A6. Constant Sub-Expression Elimination<\/h3>\n<p>This, and the following two sections, give examples of the effects of enabling <span style=\"color: #0000ff\">\/fp:fast<\/span>. Suppose the compiler generates the following, simplified-C-code for a function in your program:<\/p>\n<div style=\"padding-left: 30px\"><span style=\"font-family: terminal, monaco\">t1 = a * b;<\/span><\/div>\n<div style=\"padding-left: 30px\"><span style=\"font-family: terminal, monaco\">t2 = t1 * c;<\/span><\/div>\n<div style=\"padding-left: 30px\"><span style=\"font-family: terminal, monaco\">. . \/\/ intervening code &ndash; no changes to a, b or c<\/span><\/div>\n<div style=\"padding-left: 30px\"><span style=\"font-family: terminal, monaco\">t3 = b * c;<\/span><\/div>\n<div style=\"padding-left: 30px\"><span style=\"font-family: terminal, monaco\">t4 = a * t3<\/span><\/div>\n<p>Note that t2 = (a * b) * c, whilst t4 = a * (b * c). &nbsp;With <span style=\"color: #0000ff\">\/fp:precise<\/span>, the compiler cannot not assume that t2 == t4 and would generate code to calculate t2 and, separately, to calculate t4. &nbsp;With <span style=\"color: #0000ff\">\/fp:fast<\/span>, the compiler is allowed to infer that t2 and t4 have the same value.&nbsp; So it will calculate t2, and simply re-use that value for t4 (rather than calculate it over again).&nbsp; Of course, in many cases, the calculated values will be identical, or very close.&nbsp; If you&rsquo;re unlucky (pathological differences in the magnitudes of the participating operands) the calculated results could be different.<\/p>\n<h3>A7. Auto-Vectorization<\/h3>\n<p>The <span style=\"color: #0000ff\">\/fp:fast<\/span> switch lets the optimizer perform auto-vectorization of code patterns not otherwise allowed. (See the sequence of blog posts on <a title=\"http:\/\/blogs.msdn.com\/b\/nativeconcurrency\/archive\/2012\/04\/12\/auto-vectorizer-in-visual-studio-11-overview.aspx\" href=\"http:\/\/blogs.msdn.com\/b\/nativeconcurrency\/archive\/2012\/04\/12\/auto-vectorizer-in-visual-studio-11-overview.aspx\">auto-vectorization<\/a>). For example, suppose our program calculates the sum of an array of 100 floats. This would take 100 iterations of a simple loop. But we can use the chip&rsquo;s vector registers to get the answer in just 25 iterations, performing 4 calculations in parallel on each iteration. So, instead of:<\/p>\n<ul>\n<li>sum = a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + . . . a[99]<\/li>\n<\/ul>\n<p>we split the calculation into 4 partial sums, <span style=\"color: #0000ff\">sum0<\/span> thru <span style=\"color: #0000ff\">sum3<\/span>, which we run in parallel; then add them together:<\/p>\n<ul>\n<li>sum0 = a[0] + a[4] + a[8] + . . . a[96]<\/li>\n<li>sum1 = a[1] + a[5] + a[9] + . . . a[97]<\/li>\n<li>sum2 = a[2] + a[6] + a[10] + . . . a[98]<\/li>\n<li>sum3 = a[3] + a[7] + a[11] + . . . a[99]<\/li>\n<li>sum&rsquo;&nbsp; = sum0 + sum1 + sum2 + sum3<\/li>\n<\/ul>\n<p>Does sum&rsquo; == sum ? &nbsp;Only if (a[0]+a[4]+&hellip;) + (a[1]+a[5]+&hellip;) + (a[2]+a[6]+&hellip;)&nbsp; + ([a[3]+a[7]+&hellip;) == a[0] + a[1] + a[2] +&hellip; This holds under associativity, which <span style=\"color: #0000ff\">float<\/span>s don&rsquo;t adhere to, all of the time. &nbsp;Specifying <span style=\"color: #0000ff\">\/fp:fast&nbsp;<\/span>lets the compiler transform your code to run faster &ndash; up to 4 times faster, for this simple calculation.<\/p>\n<h3>Links &ndash; More Details on Floating Point<\/h3>\n<ul>\n<li><a title=\"https:\/\/en.wikipedia.org\/wiki\/Floating_point\" href=\"https:\/\/en.wikipedia.org\/wiki\/Floating_point\">Floating point on Wikipedia<\/a>.&nbsp; A peek into the complexities of floating-point.&nbsp;<\/li>\n<li><a title=\"https:\/\/en.wikipedia.org\/wiki\/IEEE_floating_point\" href=\"https:\/\/en.wikipedia.org\/wiki\/IEEE_floating_point\">IEEE floating point on Wikipedia<\/a>.&nbsp; If you enjoyed the previous topic, dig deeper with this one.&nbsp;<\/li>\n<li><a title=\"http:\/\/www.h-schmidt.net\/FloatConverter\/IEEE754.html\" href=\"http:\/\/www.h-schmidt.net\/FloatConverter\/IEEE754.html\">Online Floating-Point Calculator<\/a> &ndash; great for experimenting with the bits inside a float or double.&nbsp;<\/li>\n<li><a title=\"http:\/\/docs.oracle.com\/cd\/E19957-01\/806-3568\/ncg_goldberg.html\" href=\"http:\/\/docs.oracle.com\/cd\/E19957-01\/806-3568\/ncg_goldberg.html\">What Every Computer Scientist Should Know About Floating-Point Arithmetic<\/a>.&nbsp; Thorough treatment.&nbsp; [Hazard warning for the mathematically-averse: includes theorems and proofs]&nbsp;<\/li>\n<li><a title=\"https:\/\/msdn.microsoft.com\/en-us\/library\/e7s85ffb.aspx\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/e7s85ffb.aspx\">\/fp Switches on MSDN<\/a>.&nbsp; (Actually I notice this article is out-of-date, now that we default to SSE2 instructions and registers, instead of the ancient 80-bit, x87 FPU.&nbsp; Must remember to post a fix)&nbsp;<\/li>\n<li><a title=\"https:\/\/msdn.microsoft.com\/en-us\/library\/aa289157(vs.%2071).aspx\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/aa289157(vs.%2071).aspx\">Microsoft Visual C++ Floating-Point Optimization<\/a>.&nbsp; Old, but still apt.&nbsp;<\/li>\n<li>The IEEE-754-2008 Technical Standard: 58 pages of wall-to-wall fun.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What is this Blog About? My name is Jim Hogg, a Program Manager in the Compilers team. We would like your feedback on a feature of the Visual C++ compiler that affects the code we generate for floating-point operations. Your answers will help determine what we do. You can vote via survey &#8212; it should [&hellip;]<\/p>\n","protected":false},"author":271,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[140,17,65,35],"class_list":["post-7011","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","tag-c","tag-code-generation","tag-compiler","tag-survey"],"acf":[],"blog_post_summary":"<p>What is this Blog About? My name is Jim Hogg, a Program Manager in the Compilers team. We would like your feedback on a feature of the Visual C++ compiler that affects the code we generate for floating-point operations. Your answers will help determine what we do. You can vote via survey &#8212; it should [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/7011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/271"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=7011"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/7011\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=7011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=7011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=7011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}