2016/05/13
誤差ãçããã¨ã
Ruiããããããããåé¡ãtweetãã¦ããããããå³å¯ã«æ¸ãç´ãã¨ãããªæãã
IEEEå精度浮åå°æ°ç¹æ°æ¼ç®ã§ã
x + 0.25 - 0.25
ãx - 0.25 + 0.25
ã¨åãã«ãªããªãæ°x
ãæ±ããã
x
ãã²ã¨ã¤ã ãæ±ãããªãç°¡åã ããã©ãx
ãå
¨ã¦æ±ããã®ã¯é£åã«ãªãã¨æãã
å®ã¯ãæµ®åå°æ°ç¹æ°ã®èª¤å·®ã«ã¤ãã¦ã¯ããã¾ã§ä½åº¦ãã¯ã¾ã£ã¦ããã®ã§ããã®ãããç°¡åãã ã¨æã£ã¦èãã¦ããã£ããã ãã©ã å ¨é¨ã®ã±ã¼ã¹ãç¶²ç¾ ããã®ã¯ãã£ã±ãé£åã ã£ãã æµ®åå°æ°ç¹æ°ã¯ã©ãã¾ã§ãæ²¹æãªããªãã
(1) 0.25ãå解è½ã®ååã«è¿ãå ´å
ããã«èãã¤ãã®ã¯ããã ããã æµ®åå°æ°ç¹æ°ã®å解è½d(ããã§ã¯é£ã®æµ®åå°æ°ç¹æ°ã¾ã§ã®è·é¢ã¨ãã)ã®ååãã å°ããªæ°å¤ã¯è¶³ãã¦ãå¼ãã¦ãå ã®æ°ã«å½±é¿ãä¸ããªãã
0.25ãd/2æªæºãªãæ¼ç®ã®é çªãå ¥ãæ¿ãã¦ãçµå±å¤ãããªãããããªããã ã¨æããããããªããã æµ®åå°æ°ç¹æ°ã«ã¯ããã©ã¹å´ã¨ãã¤ãã¹å´ã§å解è½ãéãå ´åãããã®ã ã ã¡ããã©Â±2^mã®å ´åã§ããã 2^mãå¢ã«ä»®æ°é¨ãåãæã¤ç¯å²ãä¸æ¡ã·ããããã®ã§ã2^mããä¸ã§ã¯é£ã¨ã®è·é¢ã 2^(m-p) (pã¯hidden bitãå«ã¾ãªãä»®æ°é¨ã®æ¡æ°)ã«ãªãããã©ã2^mããä¸ã§ã¯ãã®ååã®è·é¢ã«ãªãã
ãã®çµµã¯æã®ãæµç¨ãã¦ãã®ã§doubleã£ã¦æ¸ãã¦ãããã©floatã§ãåãã
(å³å¯ã«è¨ãã°ãããã¯Â±2^mã®ä¸¡å´ãæ£è¦åæ°ã®å ´åãéæ£è¦åæ°é åã§ã¯ãã以ä¸å解è½ã ç´°ããã§ããªãã®ã§ä¸¡å´ã®å解è½ã¯åãã«ãªãã 以åããã«èµ·å ãããã°ãè¸ãã )
ãã©ã¹å´ã®dã0.5ããã¤ãã¹å´ã0.25ã«ãªããããª2^mãé¸ã¶ã¨ã
- 2^m + 0.25 ã¯é£ã®æµ®åå°æ°ç¹æ°2^m + 0.5ã¨ã®ã¡ããã©ä¸éã«è½ã¡ãã®ã§ã ããã©ã«ãã®å¶æ°ä¸¸ãè¦åã«ããçµæã¯2^mã«ä¸¸ãããã
- 2^m - 0.25 ã¯æµ®åå°æ°ç¹æ°ã¨ãã¦æ£ç¢ºã«è¡¨ç¾å¯è½ã
ã§ããã®ã§ã
- 2^m + 0.25 - 0.25 ã ã¨ãæåã®2^m + 0.25ã2^mã«ä¸¸ãããã¡ããã®ã§ã çµæã¯2^m - 0.25ã®å¤ã
- 2^m - 0.25 + 0.25 ã ã¨ãæåã®2^m - 0.25ã¯æ£ããè¨ç®ããã ãã®æ¬¡ã®+0.25ãæ£ããè¨ç®ããã¦ãçµæ㯠2^mã
ã¨è¨ãå
·åã«å·®ãã§ããx
ã -(2^m) ã§ããã©ã¹ã¨ãã¤ãã¹ãéã«ãªãã ãã§åãè°è«ã
(ãªãã丸ãè¨å®ãåãä¸ãã®å ´åã2^m+0.25ã¯2^m+0.5ã«åãä¸ãããããããããã0.25ãå¼ããçµæã2^m+0.5ã«åãä¸ããããã®ã§ããã£ã±ãåãã«ãªããªã)
å¾ã¯ãããããmã¯ä½ãã£ã¦ãã¨ã«ãªããIEEEå精度浮åå°æ°ç¹æ°ã¯ä»®æ°é¨ã23bitããã®ã§ã
[]
å
ã2é²è¡¨è¨ã¨ããã¨:
[1.00000_00000_00000_00000_000] * 2^m ã x [1.00000_00000_00000_00000_001] * 2^m ã x+0.5
ã¨ãªããããªå¤ã£ã¦ãã¨ã ããã0.5 * 2^23ã x
ãã¤ã¾ã x = 2^22ã
符å·ãéã«ããå ´åãå«ãããã®ã±ã¼ã¹ã«è©²å½ããã®ã¯ x = ±2^22ã
(2) 0.25ãå解è½ã«è¿ãå ´å
é¡ä¼¼ã®ã±ã¼ã¹ã¨ãã¦ã0.25ã足ããã¨ã2ã®ã¹ãä¹ã®å¢çãã¾ããã¨ããã®ãããã 2^mã®ãã©ã¹å´ã®å解è½ã0.25ããã¤ãã¹å´ã®å解è½ã0.125ã ã£ãã¨ãããã xã 2^m - 0.125 ã¨ããã¨ãããã«0.25ã足ãããã®ã¯2^m + 0.125ã ã丸ãããã¦2^mã¨ãªãã ãããã0.25ãå¼ã㨠2^m - 0.25 ã«ãªã£ã¦ãã¾ãã æ¸ç®ããå ã«ãã£ãå ´åã¯ä¸¸ããçããªããæ¡ãæãã¦æ¸ãã¦ã¿ãã¨ï¼
[1.00000_00000_00000_00000_000] * 2^m ã x + 0.125 [0.00000_00000_00000_00000_0001] * 2^m â ããã0.125 = 2^-3
ãªã®ã§ãæ£è² ãèæ ®ããã¨x㯠±(2^21 - 2^-3)ã
(3) 0.25ãåºæºã«ãã¦xãå解è½ã®ååã«è¿ãå ´å
0.25ã¯
[1.00000_00000_00000_00000_000] * 2^(-2)
ã§ããã(1)ã¨ã¯éã«ãxãå°ããã¦ããã®æ°å¤ã®å解è½ã® åå以ä¸ã§ãã£ãå ´åã«ããåæ§ã®å¯è½æ§ãçãããä¾ãã°xã2^-26ã ã£ãå ´åã
[1.00000_00000_00000_00000_000] * 2^(-2) 0.25 [0.00000_00000_00000_00000_0001] * 2^(-2) x
0.25+xã¯ä¸¸ãããã¦0.25ã«ãªããã0.25-xã¯æå¹æ¡æ°ã«åã¾ãã (ãããããã0.25-xã¨è¡¨è¨ãããã-(x-0.25)ã¨åããªã®ã§è°è«ã«å½±é¿ã¯ãªãã)
ãã®ã±ã¼ã¹ã¯å°ã è¤éã ãxã2^-26ããå°ãã§ã大ãããã°0.25+x㯠0.25ã®æ¬¡ã®æµ®åå°æ°ç¹æ°ã«è¿ããªãããããã¡ãã«ä¸¸ããããå ç®ãå ã«ãã£ã¦ã æ¸ç®ãå ã«ãã£ã¦ãçµæã¯åãã«ãªãã
ããããxã2^-26ããå°ãã ãå°ããå ´åãå ç®ã¯0.25ã«ä¸¸ãããã¦ç¡ãã£ããã¨ã«ãªããã æ¸ç®ã¯0.25ããã²ã¨ã¤ä¸ã®æµ®åå°æ°ç¹æ°ã«ä¸¸ããããããã¨ãã°x = 0.875*2^(-26)ãªãã
[1.00000_00000_00000_00000_000] * 2^(-2) 0.25 [0.00000_00000_00000_00000_0000111] * 2^(-2) x
0.25+xã¯
[1.00000_00000_00000_00000_0000111] * 2^(-2) æ£ç¢ºãªçµæ [1.00000_00000_00000_00000_000] * 2^(-2) 丸ãçµæ
ã ãã0.25-xã¯
[0.11111_11111_11111_11111_1111001] * 2^(-2) æ£ç¢ºãªçµæ [1.11111_11111_11111_11111_111001] * 2^(-3) æ£ç¢ºãªçµæãæ£è¦å [1.11111_11111_11111_11111_111] * 2^(-3) 丸ãçµæ
ã¨ãªããxã次ã®ãã¿ã¼ã³ã§#
ã«ã²ã¨ã¤ã§ã1ãããã°å·®ãçããã
[0.00000_00000_00000_00000_00001######...] * 2^(-2)
ãããã£ã¦ããã®ã±ã¼ã¹ã§ã®x㯠2^-27 < x ⦠2^-26 ãããã³ãã®ç¬¦å·ã å転ãããã®ã
(4) 0.25ã®å ç®ã§æ¡æ°ãå¢ãã¦ä¸¸ããçããå ´å
xã®å解è½ã0.25ã«å¯¾ãã¦ååã«ãã£ã¦ãã丸ããèµ·ãã¦ãã¾ãã±ã¼ã¹ãããã 次ã®ä¾ãè¦ã¦ã¿ããã
[1.11111_11111_11111_00000_001] * 2^13 x [0.00000_00000_00001_00000_000] * 2^13 0.25
å ç®ããã¨ã次ã ã¨ç¹°ãä¸ãããããã¦ãæä¸æ¡ãã²ã¨ã¤å¢ããä»®æ°é¨ã®æå¹æ¡æ°ã è¶ãã¦ãã¾ããæå¾ã®ãããã失ãããã
[10.00000_00000_00000_00000_001] * 2^13 x + 0.25ãæ£ç¢ºãªçµæ [1.00000_00000_00000_00000_0001] * 2^14 æ£è¦å [1.00000_00000_00000_00000_000] * 2^14 丸ãçµæ
0.25ã®æ¸ç®ããå ã«ãã£ãå ´åã¯ä¸¸ããèµ·ãããªãã®ã§ãçµæãé£ãéãã
ãããèµ·ããã±ã¼ã¹ã¯ã©ããã£ããã¿ã¼ã³ã ãããã
- 0.25ã«ããå ç®ã®ç¹°ãä¸ãããã«ã¹ã±ã¼ãçã«æä¸ä½ã¾ã§ä¼æ¬ãã
- xã®LSBã1ã§ããã0.25ã®ãããããä¸ä½æ¡ã«ãã
ã¨ããæ¡ä»¶ãæºããã°è¯ãã®ã§ã以ä¸ã®23éãã®ãã¿ã¼ã³ãããå¾ãã
#
ã®é¨åã¯0ã§ã1ã§ãæ§ããªãã
[1.#####_#####_#####_#####_##1] * 2^-2 x [1.00000_00000_00000_00000_000] * 2^-2 0.25 [1.1####_#####_#####_#####_##1] * 2^-1 x [0.10000_00000_00000_00000_000] * 2^-1 0.25 [1.11###_#####_#####_#####_##1] * 2^0 x [0.01000_00000_00000_00000_000] * 2^0 0.25 [1.111##_#####_#####_#####_##1] * 2^1 x [0.00100_00000_00000_00000_000] * 2^1 0.25 ⦠[1.11111_11111_11111_11111_111] * 2^20 x [0.00000_00000_00000_00000_010] * 2^20 0.25
符å·ãéã®å ´åãåæ§ã
(z) NaNã¯NaNã«ãã¦NaNã«ããã
ãã¨ãã¤ã¬ã®ã¥ã©ã¼ãªåçã¨ãã¦ãxãNaNã®å ´åãã¨ããã®ãããå¾ãã NaNã«ã¯ä½ã足ãå¼ããã¦ãNaNã ããNaNã¨NaNãæ¯è¼ããã¨å¿ ãå½ã«ãªãã®ã§ã ããã°ã©ã ã³ã¼ãä¸ã§æ°å¤æ¯è¼ãã¦ããå ´åã¯ãçãããªããã¨ãªãã ãã ãããããã¿ã¼ã³ã§æ¯ã¹ãã°çãããããããªããçãããªããããããªã (NaNãæ§æããããããã¿ã¼ã³ã¯è¤æ°ããã®ã§)ã
ããã¯åé¡ã®ãåãã«ãªããªããã®è§£é次第ã§ããã
ä»ã«ããããª?
å¤åããã§å ¨é¨ã ã¨æããã ãã©ãä»ã®ãã¿ã¼ã³ãè¦ã¤ãããæãã¦ãã ããã
ãªãã大å ã®ãã¹ã課é¡ã¯ãçããpow(2, n) {n > 0} ã®nãåããå½¢ã ã£ããããªã®ã§ã (1)ã®ãã¿ã¼ã³ã®ã¿èæ ®ããã°è¯ãã£ã模æ§ã
Tag: Programming
Post a comment