对于C中的项目,我尝试使用GNU MPFR Library
但我不明白mpfrúprintf函数的功能。
例如,对于代码:

mpfr_t x;
mpfr_init( x );
mpfr_set_str( x, "213598703592091008239502270499962879705109534182641740644", 10, MPFR_RNDN);
mpfr_printf( "%.0RF\n", x );
mpfr_printf( "%.0RNf\n", x );
mpfr_printf( "%.0R*f\n", MPFR_RNDN, x );

显示所有mpfr_printf的值21358703592090931365528757017222135729894633163374592
很明显它的价值不同。。。但我不知道为什么?
我不能使用The GNU Multiple Precision Arithmetic Library,因为我需要像“log”和“exp”这样的MPFR函数。
我也尝试过用不同的取整模式来代替“MPFRúRNDN”,但没有一个有效。

最佳答案

这三个mpfr_printf语句都是等价的。(我想你拿到了)

mpfr_printf( "%.0RF\n", x );

舍入到最接近的值(默认值)
mpfr_printf( "%.0RNf\n", x );

四舍五入到最近(因为“RN”)
mpfr_printf( "%.0R*f\n", MPFR_RNDN, x );

四舍五入到最近(因为“MPFR_RNDN”)

09-10 04:47
查看更多