åçªã§ãã, ä¸è¨ã®ã³ã¼ããå®è¡ããã¨ãéãã®ã¯ã©ã¡ãã§ããã. ã¾ãæ¼ç®çµæã¯ã©ããªãã¨äºæ³ããã¾ãã. double calcd(int n) { double ret = 0; for (int i = 1; i < n; i++) { ret += 1 / double(i); } return ret; } float calcf(int n) { float ret = 0; for (int i = 1; i < n; i++) { ret += 1 / float(i); } return ret; } int main() { printf("calcf=%.15f\n", calcf(100000000)); printf("calcd=%.15f\n", calcd(100000000)); } floatåã¯é ã? ãã
âå精度浮åå°æ°ç¹æ¼ç®ã®4ã¤ã®ãã¤ã³ã NVIDIAã¯ãCUDAã¨G80ã¢ã¼ããã¯ãã£ã«ãã£ã¦ããã¤ããã©ã¼ãã³ã¹ã³ã³ãã¥ã¼ãã£ã³ã°(HPC)ã§ããç¨åº¦ã®æåã®è¶³ããããæ´ãã ãããããNVIDIAã«ã¨ã£ã¦ãå精度浮åå°æ°ç¹æ¼ç®ã®ãµãã¼ãã¯ãæ¬ ãããªãè¦ç´ ã ãHPCã®ã¢ããªã±ã¼ã·ã§ã³ã§ã¯ãå精度ãå¿ è¦ã¨ãªãå±é¢ãããããã ãGPUã³ã³ãã¥ã¼ãã£ã³ã°åãã®Tesla製åã§ã¯ãå精度æ¼ç®ã¯ã«ã®ã¨ãªãã¨è¨ã£ã¦ãããããããã¾ã§ããå精度ã®å£ã«ãã£ã¦ç§»æ¤ã§ããªãã£ãã¢ããªã±ã¼ã·ã§ã³ãããªããã£ããã¨NVIDIAã¯å¿ è¦æ§ã強調ããã åé¡ã¯ãç¾ç¶ã®ãªã¢ã«ã¿ã¤ã ã°ã©ãã£ãã¯ã¹ã§ã¯ãå精度(32-bit)ã¾ã§ã®æµ®åå°æ°ç¹æ¼ç®ããå¿ è¦ã¨ãããªããã¨ããã®ãããããã¾ã§ã®GPUã¯å精度æ¼ç®ã¦ãããããå®è£ ãã¦ããããGPUã§ã®å精度æ¼ç®ã®ãµãã¼ãã«ã¯ãããã¤ãã®ãã¤ã³ãã¨çåç¹ãããã (1)IEEE 75
SCMã®è¬ SCMã®æµ®åå°æ°ç¹æ¸ãåºãã¢ã«ã´ãªãºã ã¯ãSteele&White ("How to print floating-point numbers accurately, SIGPLAN '90, pp.112-123) ã«ç¤ºããã¦ããFP^3ã¢ã«ã´ãªãºã ã¨åºæ¬çã«åãã§ããã ããªãã¡ãæ¸ãåºãããæ°å¤v (v ï¼ 0) ã«å¯¾ãã¦ã ( m - ε) à 10^e ⦠v ⦠( m + ε) à 10^e 1 ⦠m ï¼ 10 ε ã¯ä¸ã®å¼ã®æç«ãããæãå°ããæ£ã®æµ®åå°æ°ç¹æ° ã¨ãªãm, ε, e ãæ±ãã 1. m ã®æ´æ°é¨ãæ¸ãåºãã 2. ε ⦠mã®å°æ°é¨ ⦠1.0 - ε ãªã m â (mã®å°æ°é¨)Ã10.0 ε â ε à 10.0 ã¨ãã¦ã1.ããç¹°ãè¿ã 3. ããã§ãªããã°ã mã®å°æ°é¨ ï¼ 0.5 ãªã ãã®ã¾ã¾çµäº mã®å°æ°é¨ ï¼ 0.5 ãªãæå¾ã®
æµ®åå°æ°ç¹æ¼ç®ã§ã¯ã¾ã£ã話 æµ®åå°æ°ç¹æ¼ç®ã®ãããã¡ãªåé¡ã§ã¯ã¾ãã¾ããã ãããã調ã¹ã¦ãããã¡ã« x86 ç¹æã®ã¡ãã£ã¨ããããã ç¾è±¡ã«ééããã®ã§ç´¹ä»ãããã¨æãã¾ãã ãã¼ã»ã³ãã¼ã¸ã®è¨ç® ç°¡å㪠C ã®ããã°ã©ã ã§ãã¼ã»ã³ãã¼ã¸ãè¨ç®ãããã¨æãã 次ã®ãããªã³ã¼ããæ¸ãã¾ããã int x, y; ... int a = (double)x / y * 100; int a = x * 100 / y ã¨ããªãã®ã¯ã x ã大ããå ´åã« x * 100 ã ãªã¼ãã¼ããã¼ãèµ·ãã (INT_MAX ãè¶ãã) ããã§ãã ãã®ã³ã¼ãã¯ä¸è¦ãæå¾ éãã«åãã¦ããã®ã§ããã ãã°ãã使ã£ã¦ããã¨ãæå ã®ç°å¢ã§ã¯ x = 53, y = 100 ã®ã¨ãã« a 㯠53 ã§ã¯ãªã 52 ã«ãªããã¨ã«æ°ã¥ãã¾ããã ããã¯æ¬¡ã®çç±ã«ããã¾ãã å¼ã®æåã® (double)53 / 10
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}