diff options
author | hanrot <hanrot@280ebfd0-de03-0410-8827-d642c229c3f4> | 1999-06-09 18:03:33 +0000 |
---|---|---|
committer | hanrot <hanrot@280ebfd0-de03-0410-8827-d642c229c3f4> | 1999-06-09 18:03:33 +0000 |
commit | 0cf5fc5ea4b5ed46b454d3bf3adc620d9fff2d32 (patch) | |
tree | 62d12a119f5dfc15abe2f6d298617e174a0a06af /set_prec.c | |
parent | 8d21dd7188076894a6f65e510797c8c6928e474f (diff) | |
download | mpfr-0cf5fc5ea4b5ed46b454d3bf3adc620d9fff2d32.tar.gz |
Initial revision
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'set_prec.c')
-rw-r--r-- | set_prec.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/set_prec.c b/set_prec.c new file mode 100644 index 000000000..a044a5344 --- /dev/null +++ b/set_prec.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "mpfr.h" + +void +#if __STDC__ +mpfr_set_prec (mpfr_t x, unsigned long int p, unsigned char rnd_mode) +#else +mpfr_set_prec (x, p, rnd_mode) + mpfr_t x; + unsigned long int p; + unsigned char rnd_mode; +#endif +{ + unsigned long xsize,oldp,oldsize; mp_limb_t *old; + + if (p==0) { + printf("*** cannot set precision to 0 bits\n"); exit(1); + } + + oldp = x -> _mp_prec; + oldsize = (oldp-1)/BITS_PER_MP_LIMB + 1; + if (SIGN(x)<0) oldsize = oldsize ^ (1<<31); + xsize = (p - 1)/BITS_PER_MP_LIMB + 1; /* new limb size */ + + old = x -> _mp_d; + x -> _mp_d = (mp_ptr) (*_mp_allocate_func) + (xsize * BYTES_PER_MP_LIMB); + x -> _mp_prec = p; + mpfr_round_raw(x -> _mp_d, old, rnd_mode, oldsize, p); + SIZE(x) = (SIGN(x)>0) ? xsize : (xsize ^ (1<<31)); + + (*_mp_free_func) (old, 1 + ((oldp-1)>>3)); +} + +unsigned long int +#if __STDC__ +mpfr_get_prec (mpfr_t x) +#else +mpfr_set_prec (x) + mpfr_t x; +#endif +{ + return x -> _mp_prec; +} |