久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <i id='vYIZ1'><tr id='vYIZ1'><dt id='vYIZ1'><q id='vYIZ1'><span id='vYIZ1'><b id='vYIZ1'><form id='vYIZ1'><ins id='vYIZ1'></ins><ul id='vYIZ1'></ul><sub id='vYIZ1'></sub></form><legend id='vYIZ1'></legend><bdo id='vYIZ1'><pre id='vYIZ1'><center id='vYIZ1'></center></pre></bdo></b><th id='vYIZ1'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vYIZ1'><tfoot id='vYIZ1'></tfoot><dl id='vYIZ1'><fieldset id='vYIZ1'></fieldset></dl></div>
    • <bdo id='vYIZ1'></bdo><ul id='vYIZ1'></ul>

    1. <legend id='vYIZ1'><style id='vYIZ1'><dir id='vYIZ1'><q id='vYIZ1'></q></dir></style></legend>
    2. <small id='vYIZ1'></small><noframes id='vYIZ1'>

    3. <tfoot id='vYIZ1'></tfoot>

    4. 即使浮點數不精確,Excel 如何成功舍入?

      How does Excel successfully round floating point numbers even though they are imprecise?(即使浮點數不精確,Excel 如何成功舍入?)

      <small id='IqTah'></small><noframes id='IqTah'>

        <i id='IqTah'><tr id='IqTah'><dt id='IqTah'><q id='IqTah'><span id='IqTah'><b id='IqTah'><form id='IqTah'><ins id='IqTah'></ins><ul id='IqTah'></ul><sub id='IqTah'></sub></form><legend id='IqTah'></legend><bdo id='IqTah'><pre id='IqTah'><center id='IqTah'></center></pre></bdo></b><th id='IqTah'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IqTah'><tfoot id='IqTah'></tfoot><dl id='IqTah'><fieldset id='IqTah'></fieldset></dl></div>

        <tfoot id='IqTah'></tfoot>
          <bdo id='IqTah'></bdo><ul id='IqTah'></ul>
          <legend id='IqTah'><style id='IqTah'><dir id='IqTah'><q id='IqTah'></q></dir></style></legend>
              <tbody id='IqTah'></tbody>

                本文介紹了即使浮點數不精確,Excel 如何成功舍入?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                例如,這個博客 說 0.005 不完全是 0.005,但四舍五入這個數字會產生正確的結果.

                For example, this blog says 0.005 is not exactly 0.005, but rounding that number yields the right result.

                我在 C++ 中嘗試了各種四舍五入,但在將數字四舍五入到某些小數位時失敗.例如,Round(x,y) 將 x 舍入為 y 的倍數.所以 Round(37.785,0.01) 應該給你 37.79 而不是 37.78.

                I have tried all kinds of rounding in C++ and it fails when rounding numbers to certain decimal places. For example, Round(x,y) rounds x to a multiple of y. So Round(37.785,0.01) should give you 37.79 and not 37.78.

                我重新打開這個問題是為了向社區尋求幫助.問題在于浮點數的不精確性(37,785 表示為 37.78499999999).

                I am reopening this question to ask the community for help. The problem is with the impreciseness of floating point numbers (37,785 is represented as 37.78499999999).

                問題是 Excel 如何解決這個問題?

                The question is how does Excel get around this problem?

                此round() for float in C++ 中的解決方案對于以上問題.

                The solution in this round() for float in C++ is incorrect for the above problem.

                推薦答案

                Round(37.785,0.01) 應該給你 37.79 而不是 37.78."

                "Round(37.785,0.01) should give you 37.79 and not 37.78."

                首先,沒有人認為 37.79 而不是 37.78 是正確"的答案?決勝局總是有點困難.雖然在平局的情況下總是四舍五入是一種廣泛使用的方法,但它肯定不是唯一的方法.

                First off, there is no consensus that 37.79 rather than 37.78 is the "right" answer here? Tie-breakers are always a bit tough. While always rounding up in the case of a tie is a widely-used approach, it certainly is not the only approach.

                其次,這不是決勝局.IEEE binary64 浮點格式中的數值為 37.784999999999997(大約).除了人類輸入 37.785 的值并碰巧將其轉換為浮點表示之外,還有很多方法可以獲得 37.784999999999997 的值.在大多數情況下,正確答案是 37.78 而不是 37.79.

                Secondly, this isn't a tie-breaking situation. The numerical value in the IEEE binary64 floating point format is 37.784999999999997 (approximately). There are lots of ways to get a value of 37.784999999999997 besides a human typing in a value of 37.785 and happen to have that converted to that floating point representation. In most of these cases, the correct answer is 37.78 rather than 37.79.

                附錄
                考慮以下 Excel 公式:

                Addendum
                Consider the following Excel formulae:

                =ROUND(37785/1000,2)
                =ROUND(19810222/2^19+21474836/2^47,2)
                

                兩個單元格將顯示相同的值,37.79.關于 37785/1000 是否應該四舍五入到 37.78 或 37.79 并具有兩位精度,這是一個合理的爭論.如何處理這些極端情況有點武斷,也沒有一致的答案.微軟內部甚至沒有一個一致的答案:由于歷史原因,Round() 函數在不同的微軟產品之間沒有以一致的方式實現."(http://support.microsoft.com/kb/196652 ) 給定一個無限精度的機器,微軟的 VBA 會將 37.785 舍入到 37.78(銀行家的圓)而 Excel 將產生 37.79(對稱算術圓).

                Both cells will display the same value, 37.79. There is a legitimate argument over whether 37785/1000 should round to 37.78 or 37.79 with two place accuracy. How to deal with these corner cases is a bit arbitrary, and there is no consensus answer. There isn't even a consensus answer inside Microsoft: "the Round() function is not implemented in a consistent fashion among different Microsoft products for historical reasons." ( http://support.microsoft.com/kb/196652 ) Given an infinite precision machine, Microsoft's VBA would round 37.785 to 37.78 (banker's round) while Excel would yield 37.79 (symmetric arithmetic round).

                對于后一個公式的四舍五入沒有爭論.它嚴格小于 37.785,所以它應該四舍五入到 37.78,而不是 37.79.然而,Excel 會將其四舍五入.為什么?

                There is no argument over the rounding of the latter formula. It is strictly less than 37.785, so it should round to 37.78, not 37.79. Yet Excel rounds it up. Why?

                原因與實數在計算機中的表示方式有關.與許多其他公司一樣,Microsoft 使用 IEEE 64 位浮點格式.以這種格式表示時,數字 37785/1000 會出現精度損失.19810222/2^19+21474836/2^47不會出現這種精度損失;這是一個確切數字".

                The reason has to do with how real numbers are represented in a computer. Microsoft, like many others, uses the IEEE 64 bit floating point format. The number 37785/1000 suffers from precision loss when expressed in this format. This precision loss does not occur with 19810222/2^19+21474836/2^47; it is an "exact number".

                我特意構造了那個精確的數字,使其具有與不精確的 37785/1000 相同的浮點表示.Excel 將這個精確值向上舍入而不是向下舍入是確定 Excel 的 ROUND() 函數如何工作的關鍵:它是對稱算術舍入的一種變體.它基于與極端情況的浮點表示的比較進行舍入.

                I intentionally constructed that exact number to have the same floating point representation as does the inexact 37785/1000. That Excel rounds this exact value up rather than down is the key to determining how Excel's ROUND() function works: It is a variant of symmetric arithmetic rounding. It rounds based on a comparison to the floating point representation of the corner case.

                C++ 中的算法:

                #include <cmath> // std::floor
                
                // Compute 10 to some positive integral power.
                // Dealing with overflow (exponent > 308) is an exercise left to the reader.
                double pow10 (unsigned int exponent) { 
                   double result = 1.0;
                   double base = 10.0;
                   while (exponent > 0) {
                      if ((exponent & 1) != 0) result *= base;
                      exponent >>= 1;
                      base *= base;
                   }
                   return result;
                }   
                
                // Round the same way Excel does.
                // Dealing with nonsense such as nplaces=400 is an exercise left to the reader.
                double excel_round (double x, int nplaces) {
                   bool is_neg = false;
                
                   // Excel uses symmetric arithmetic round: Round away from zero.
                   // The algorithm will be easier if we only deal with positive numbers.
                   if (x < 0.0) {
                      is_neg = true;
                      x = -x; 
                   }
                
                   // Construct the nearest rounded values and the nasty corner case.
                   // Note: We really do not want an optimizing compiler to put the corner
                   // case in an extended double precision register. Hence the volatile.
                   double round_down, round_up;
                   volatile double corner_case;
                   if (nplaces < 0) {
                      double scale = pow10 (-nplaces);
                      round_down  = std::floor (x * scale);
                      corner_case = (round_down + 0.5) / scale;
                      round_up    = (round_down + 1.0) / scale;
                      round_down /= scale;
                   }
                   else {
                      double scale = pow10 (nplaces);
                      round_down  = std::floor (x / scale);
                      corner_case = (round_down + 0.5) * scale;
                      round_up    = (round_down + 1.0) * scale;
                      round_down *= scale;
                   }
                
                   // Round by comparing to the corner case.
                   x = (x < corner_case) ? round_down : round_up;
                
                   // Correct the sign if needed.
                   if (is_neg) x = -x; 
                
                   return x;
                }   
                

                這篇關于即使浮點數不精確,Excel 如何成功舍入?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                Scope of exception object in C++(C++中異常對象的范圍)
                Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)
                <tfoot id='h14Ds'></tfoot>
              1. <small id='h14Ds'></small><noframes id='h14Ds'>

                    <tbody id='h14Ds'></tbody>
                  • <bdo id='h14Ds'></bdo><ul id='h14Ds'></ul>
                    <i id='h14Ds'><tr id='h14Ds'><dt id='h14Ds'><q id='h14Ds'><span id='h14Ds'><b id='h14Ds'><form id='h14Ds'><ins id='h14Ds'></ins><ul id='h14Ds'></ul><sub id='h14Ds'></sub></form><legend id='h14Ds'></legend><bdo id='h14Ds'><pre id='h14Ds'><center id='h14Ds'></center></pre></bdo></b><th id='h14Ds'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='h14Ds'><tfoot id='h14Ds'></tfoot><dl id='h14Ds'><fieldset id='h14Ds'></fieldset></dl></div>
                    <legend id='h14Ds'><style id='h14Ds'><dir id='h14Ds'><q id='h14Ds'></q></dir></style></legend>

                          主站蜘蛛池模板: 欧美亚洲高清 | 精品国产色| 欧美精品久久久久久久久老牛影院 | 成人免费视频网站在线看 | 色综合视频 | 久久精品欧美一区二区三区麻豆 | 亚洲精品一级 | 国产精品久久久久久久久免费 | 超碰在线网站 | 久久狠狠| 成人福利视频 | 一级a爱片性色毛片免费 | 日日摸夜夜添夜夜添特色大片 | 桃花av在线| 欧美高清性xxxxhd | 亚洲图片视频一区 | 日韩视频二区 | 久久久久久中文字幕 | 久久丝袜视频 | 91中文在线观看 | 欧美在线视频一区二区 | 中文字字幕一区二区三区四区五区 | 亚洲二区精品 | 国产精品成人久久久久a级 久久蜜桃av一区二区天堂 | 欧产日产国产精品v | 九九久久99 | 99视频在线播放 | 日韩综合网 | 亚洲视频一区在线播放 | www..99re| 国产精品一区二区三区久久久 | 久久国产精品无码网站 | 午夜精品福利视频 | 国产伦精品一区二区三区视频金莲 | 久久精品91久久久久久再现 | 色婷婷av久久久久久久 | 91九色麻豆| 日韩一二三区视频 | 黄色片免费看视频 | 涩爱av一区二区三区 | 欧美亚洲一区二区三区 |