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

            統計系統
            久久精品中文字幕第23页| 99热都是精品久久久久久| 中文成人无码精品久久久不卡| 久久国产AVJUST麻豆| 中文字幕无码精品亚洲资源网久久 | 国产精品一区二区久久不卡| 久久精品国内一区二区三区| 久久精品视频91| 久久偷看各类wc女厕嘘嘘| 欧美综合天天夜夜久久| 亚洲精品综合久久| 久久亚洲国产欧洲精品一| 久久久久99精品成人片牛牛影视| 77777亚洲午夜久久多喷| 久久精品人妻一区二区三区| 日韩精品久久久肉伦网站| 久久久精品日本一区二区三区 | 久久精品国产精品青草app| 久久中文字幕精品| 国产69精品久久久久9999| 久久精品国产清高在天天线| 国产欧美久久久精品影院| 国内精品久久久久影院网站| 91精品国产高清久久久久久io | 久久久久波多野结衣高潮| 久久久不卡国产精品一区二区| 99久久99这里只有免费的精品| 日韩av无码久久精品免费| 久久99热这里只频精品6| 久久综合久久综合亚洲| 亚洲婷婷国产精品电影人久久| 久久精品国产99久久丝袜| 久久久久噜噜噜亚洲熟女综合| 日本久久久精品中文字幕| 久久免费线看线看| 精品亚洲综合久久中文字幕| 久久国产精品成人影院| 精品国产乱码久久久久久1区2区| 久久精品国产亚洲av麻豆小说| 国产一级做a爰片久久毛片| 免费观看久久精彩视频|