[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bug in mpfr_pow() function
From: |
Kees-Jan van der Kolk |
Subject: |
Bug in mpfr_pow() function |
Date: |
Wed, 28 Apr 2004 15:58:05 +0200 (CEST) |
Hello,
I just ran into a bug in the mpfr_pow() function, in gmp version
4.1.2 (configured with --enable-mpfr). When mpfr_pow() is given a
negative integer exponent, it treats the exponent as if it were
positive:
mpfr_pow(10, 3) -> gives 1000, ok
mpfr_pow(10, -3) -> gives 1000, not ok
When using non-integer (floating point) arguments to mpfr_pow(), the
function seems to behave correctly.
A test-program is given below. Compilation and linking was done with:
# gcc -o mpfrbug mpfrbug.c -lmpfr -lgmp
Gcc version 3.3 was used.
Of course, a workaround is easy to come up with, but it would be nice
if the problem was fixed in a future release. Thank you in advance.
Kind regards,
Kees-Jan van der Kolk
Delft University of Technology
http://space.tudelft.nl
---[file: mpfrbug.c]--------------------------------------------------
#include <stdio.h>
#include <gmp.h>
#include <mpfr.h>
int main(int argc, char** argv)
{
mpfr_t v1;
mpfr_t v2;
mpfr_t v3;
mpfr_init(v1);
mpfr_init(v2);
mpfr_init(v3);
mpfr_set_d(v1, 10, GMP_RNDN);
mpfr_set_d(v2, -3, GMP_RNDN);
mpfr_pow(v3, v1, v2, GMP_RNDN);
fprintf(stdout, "should be 0.001: ");
mpfr_out_str(stdout, 10, 0, v3, GMP_RNDN);
fprintf(stdout, "\n");
mpfr_clear(v1);
mpfr_clear(v2);
mpfr_clear(v3);
return 0;
}
----------------------------------------------------------------------
- Bug in mpfr_pow() function,
Kees-Jan van der Kolk <=