• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            O(1) 的小樂

            Job Hunting

            公告

            記錄我的生活和工作。。。
            <2011年6月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            統計

            • 隨筆 - 182
            • 文章 - 1
            • 評論 - 41
            • 引用 - 0

            留言簿(10)

            隨筆分類(70)

            隨筆檔案(182)

            文章檔案(1)

            如影隨形

            搜索

            •  

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            NaN解釋

            There are three kinds of operation which return NaN:[4]

            • Operations with a NaN as at least one operand
            • Indeterminate forms
              • The divisions 0/0, ∞/∞, ∞/?∞, ?∞/∞, and ?∞/?∞
              • The multiplications 0×∞ and 0×?∞
              • The additions ∞ + (?∞), (?∞) + ∞ and equivalent subtractions
              • The standard has alternative functions for powers:
                • The standard pow function and the integer exponent pown function define 00, 1, and ∞0 as 1.
                • The powr function define all three indeterminate forms as invalid operations and so returns NaN.
            • Real operations with complex results, for example:
              • The square root of a negative number
              • The logarithm of a negative number
              • The inverse sine or cosine of a number which is less than ?1 or greater than +1.

            NaNs may also be explicitly assigned to variables, typically as a representation for missing values. Prior to the IEEE standard, programmers often used a special value (such as ?99999999) to represent undefined or missing values, but there was no guarantee that they would be handled consistently or correctly.[1]

            NaNs are not necessarily generated by the processor. In the case of quiet NaNs, the first item is always valid for each processor; the others may not necessarily be. For example, on the Intel Architecture processors, the FPU never creates a NaN except in the first case, unless the corresponding floating point exception mask bits have been set.[5] The other items would cause exceptions, not NaNs. However, the software exception handler may examine the operands and decide to return a NaN (e.g. in the case of 0/0).

            [edit]Quiet NaN

            Quiet NaNs, or qNaNs, do not raise any additional exceptions as they propagate through most operations. The exceptions are where the NaN cannot simply be passed through unchanged to the output, such as in format conversions or certain comparison operations (which do not "expect" a NaN input).

            [edit]Signaling NaN

            Signaling NaNs, or sNaNs, are special forms of a NaN which when consumed by most operations should raise an invalid exception and then, if appropriate, be "quieted" into a qNaN which may then propagate. They were introduced in IEEE 754. There have been several ideas for how these might be used:

            • Filling uninitialized memory with signaling NaNs would produce an invalid exception if the data is used before it is initialized
            • Using an sNaN as a placeholder for a more complicated object, such as:

            When encountered a trap handler could decode the sNaN and return an index to the computed result. In practice this approach is faced with many complications. The treatment of the sign bit of NaNs for some simple operations (such as absolute value) is different from that for arithmetic operations. Traps are not required by the standard. There are other approaches to this sort of problem which would be more portable.

             

            NaN是Not a Number的縮寫,就是說它不是一個數。NaN是定義在IEEE 754標準中的特殊值,類似的特殊值還有INF(無窮大,INFinite)。IEEE 754是定義浮點數的標準,有1985和2008兩個版本。其中,2008版本還定義了十進制浮點數的標準。

            NaN的產生(可以)是這樣的(此段文字摘譯自WIKI):
            1)NaN參與數學運算的結果仍是NaN
            2)0/0,正無窮大/正無窮大,正無窮大/負無窮大,負無窮大/正無窮大,負無窮大/負無窮大
            3)0和正/負無窮大相乘
            4)正無窮大+負無窮大,負無窮大加正無窮大
            5)數學上無解的一些函數值,比如:負數的平方根,對2.0的求反正弦,等等

            第一條說明了NaN在運算中的“傳染性”。如果不慎在某處引入了NaN,那么之后的算式值很可能就一直是NaN了。所以在涉及浮點數值運算時一定要注意NaN的存在。

            回過頭來解釋前面的題目:NaN永遠不等于自己,所以說NaN == NaN永遠為false,而NaN != NaN永遠為true。這是一個相當特殊的情況:即使參與比較的兩個NaN的內存表示是一模一樣的,但它們仍然是不等的。

            更深一步地說,NaN有兩種,一種是Quiet NaN,另一種是Signalling NaN。在使用時,Signalling NaN會立即引發異常,然后將自身變為Quiet NaN;Quiet NaN的行為比較安靜,在算術運算中它不會引發異常,只是將運算結果“傳染”為NaN(但是在某些不接受NaN的地方仍會引發異常)。

            INF,它溢出到無窮大

            INF就是無窮大,在浮點數中,有+INF和-INF兩種。INF在數學上有對應的概念,所以它比NaN更好理解一些。比如用1/0,得到的結果就是INF

            0,它竟然還有正負

            在IEEE浮點數中,0也是特殊的,因為它有+0和-0兩種(“正零”和“負零”)。其中,1除以“負0”等于“負無窮大”,1除以“正0”等于“正無窮大”。

            舍入,它可不是“四舍五入”

            舍入算法對我們多數人來說意味著“四舍五入”。這個在上學時就學過了,但它卻會給舍入之后的數帶來擴大的趨勢。在買賣方之間,民俗傳統中一直有“五 刨六撩”一說,“五刨”是說將5及5以下的舍去,“六撩”是說將6及6以上的進位,這種舍入算法有整體減小的趨勢,體現了小生意人讓利的“誠意”。那么, 更好的舍入算法是什么樣的呢?

            IEEE754中定義了最基本的舍入算法:Rounds to nearest, ties to even(even在這里是“偶數”的意思)。這種算法將4及4以下的數拋棄,6及6以上的數進位,如果要舍入的最高位是5的話,則將要保留的最低位圓整 到最接近的偶數(這里說的“偶數”包括0)。比如:

            89.64 --> 90
            98.46 --> 98
            1919.54 --> 1920
            1918.55 --> 1918

            對于大量均勻分布的數來說,這種50%概率算法保證了舍入后的數沒有放大或者縮小的趨勢。在銀行里都是用的這種算法,做過金融類程序的對此應該印象深刻的。

            除了上面提到的“Ties To Even算法”之外,還有幾種舍入算法,因為定義得非常清晰和明確,這里不再多說,詳情請見參考資料。

            參考資料/延伸閱讀

            1、http://en.wikipedia.org/wiki/IEEE_754-2008
            2、http://en.wikipedia.org/wiki/IEEE_754-1985
            3、http://en.wikipedia.org/wiki/Signed_zero
            4、http://en.wikipedia.org/wiki/Not_a_Number
            5、IEEE標準

             

             

            以上這篇文章zz自 http://blog.csdn.net/yuankaining/archive/2009/08/19/4461238.aspx

             

            這個問題是在看Fundamentals of Computer Graphics的時候看到的!總結一下:

            當深入理解了IEEE標準和NAN之后,我們完全可以改善程序的設計來避免復雜的判斷!這一點是完全可以做到的!注意Signalling NaN 和Quiet NaN

            posted on 2010-10-16 21:35 Sosi 閱讀(1200) 評論(0)  編輯 收藏 引用

            統計系統
            久久这里有精品| 久久婷婷五月综合97色| 国产精品青草久久久久福利99| 亚洲精品乱码久久久久久不卡| 99999久久久久久亚洲| 欧美黑人激情性久久| 久久精品无码av| 国产成人久久久精品二区三区| 久久久国产精品| 久久久久亚洲AV无码永不| 国内精品久久久久影院亚洲| 国产麻豆精品久久一二三| 人妻无码久久一区二区三区免费| 伊人色综合久久| 91精品国产高清久久久久久国产嫩草| 久久伊人色| 久久久久亚洲AV无码专区首JN| 亚洲国产精品成人久久蜜臀| av无码久久久久不卡免费网站| 人人狠狠综合久久亚洲高清| 香蕉久久久久久狠狠色| 久久99精品国产| 国内精品久久久久久中文字幕| 国内精品久久久久国产盗摄| 久久综合亚洲欧美成人| 久久夜色精品国产亚洲| 亚洲精品无码久久久| 久久99精品国产麻豆蜜芽| 国内精品久久久久影院日本| 日韩精品久久久肉伦网站| 日日噜噜夜夜狠狠久久丁香五月| 狠狠色丁香久久婷婷综合_中| 亚洲国产成人精品无码久久久久久综合| 狠狠色丁香久久婷婷综合五月| 日韩久久久久久中文人妻| 亚洲愉拍99热成人精品热久久| 国产一区二区精品久久| 久久国产精品久久久| 婷婷综合久久狠狠色99h| 久久99精品国产99久久6| 久久精品这里只有精99品|