A C library for '''M'''ultiple-'''P'''recision '''F'''loating-point computations with correct '''R'''ounding. http://www.mpfr.org/mpfr500.png http://www.mpfr.org/ [GMP]¸¦ »ç¿ëÇÑ ½Ç¼öÀü¿ë ¶óÀ̺귯¸® == ¿¹Á¦ == from http://www.mpfr.org/sample.html ´ÙÀ½Àº 200-bit Á¤¹Ðµµ(precision)·Î 1+1/1!+1/2!+...+1/100!¸¦ ±¸ÇÏ´Â ÇÁ·Î±×·¥ÀÔ´Ï´Ù. {{{mpfr_t s, t, u;}}} ¼¼°³ÀÇ s, t, u ½Ç¼ö¸¦ Á¤ÀÇ {{{mpfr_init2 (t, 200);}}} 200-bit Á¤¹Ðµµ·Î ÃʱâÈ­ {{{mpfr_set_d (t, 1.0, GMP_RNDD);}}} º¯¼ö t¿¡ doubleÇü º¯¼ö 1.0À» Áý¾î³ÖµÇ, -InfinityÂÊ(downward rounding) ¹Ý¿Ã¸²À» Çϵµ·Ï ÇÑ´Ù. (ÀÌ °æ¿ì ¹Ý¿Ã¸²ÀÌ ÀϾÁö ¾Ê´Âµ¥, 1Àº 200ºñÆ®¿¡¼­ Á¤È®ÇÏ°Ô 1·Î Ç¥ÇöµÇ±â ¶§¹®. {{{mpfr_mul_ui (t, t, i, GMP_RNDU);}}} t¿¡ unsigned intÀÎ i¸¦ °öÇؼ­ t¿¡ ³Ö´Â´Ù. °á°ú°ªÀº +InfinityÂÊ (upward rounding) {{{mpfr_div (u, u, t, GMP_RNDD);}}} u¸¦ t·Î ³ª´«´Ù. °á°ú´Â -InfinityÂÊÀ¸·Î ¹Ý¿Ã¸²ÇÏ°í u¿¡ ÀúÀåÇÑ´Ù. {{{mpfr_out_str (stdout, 10, 0, s, GMP_RNDD);}}} 10À» base·Î ÇÏ´Â Ãâ·ÂÀ» s·Î -InfinityÂÊÀ¸·Î ¹Ý¿Ã¸². ¼¼¹ø° ÀÎÀÚ 0Àº ÇÁ¸°Æ®µÉ ¼ýÀÚ¸¦ ÀÚµ¿À¸·Î ¼³Á¤Çϵµ·Ï ÇÑ´Ù. {{{mpfr_clear}}} MPFR¿¡¼­ »ç¿ëµÈ °ø°£À» Áö¿î´Ù. {{{#!vim c #include #include #include int main (void) { unsigned int i; mpfr_t s, t, u; mpfr_init2 (t, 200); mpfr_set_d (t, 1.0, GMP_RNDD); mpfr_init2 (s, 200); mpfr_set_d (s, 1.0, GMP_RNDD); mpfr_init2 (u, 200); for (i = 1; i <= 100; i++) { mpfr_mul_ui (t, t, i, GMP_RNDU); mpfr_set_d (u, 1.0, GMP_RNDD); mpfr_div (u, u, t, GMP_RNDD); mpfr_add (s, s, u, GMP_RNDD); } printf ("Sum is "); mpfr_out_str (stdout, 10, 0, s, GMP_RNDD); putchar ('\n'); mpfr_clear (s); mpfr_clear (t); mpfr_clear (u); return 0; } }}} °á°ú {{{ $ ./sample Sum is 2.718281828459045235360287471352662497757247093699959574966913 }}}