• <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

            公告

            記錄我的生活和工作。。。
            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            統計

            • 隨筆 - 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 閱讀(1203) 評論(0)  編輯 收藏 引用

            統計系統
            综合网日日天干夜夜久久| 精品综合久久久久久98| 99国产欧美久久久精品蜜芽| 伊人久久综合精品无码AV专区| 伊人久久一区二区三区无码| 久久成人精品视频| 久久一区二区三区99| 亚洲人成精品久久久久| 国产精品无码久久久久久| 精品无码人妻久久久久久| 亚洲精品国产第一综合99久久| 99久久国产宗和精品1上映| 国产精品无码久久综合| 久久天天躁狠狠躁夜夜2020| 亚洲狠狠婷婷综合久久蜜芽| 久久最新精品国产| 亚洲精品乱码久久久久久久久久久久 | 无码伊人66久久大杳蕉网站谷歌| 亚洲综合伊人久久综合| 91精品国产色综久久| 99精品国产免费久久久久久下载| 久久久久99精品成人片直播| 色综合久久久久| 久久精品国产亚洲AV麻豆网站 | 国产精品亚洲综合久久| 国产—久久香蕉国产线看观看 | 2021国产精品午夜久久| 国产一区二区三区久久精品| 国产精品99久久久久久宅男小说| 久久精品国产第一区二区| 久久96国产精品久久久| 久久久精品人妻一区二区三区四 | 久久久精品国产免大香伊| 久久精品亚洲精品国产欧美| 国产亚洲综合久久系列| 午夜天堂av天堂久久久| 蜜臀av性久久久久蜜臀aⅴ麻豆 | 亚洲精品WWW久久久久久| 蜜桃麻豆www久久| 99久久综合国产精品二区| 国产精品青草久久久久福利99|