summaryrefslogtreecommitdiff
path: root/extract.c
diff options
context:
space:
mode:
authorjeandel <jeandel@280ebfd0-de03-0410-8827-d642c229c3f4>2000-06-28 08:33:06 +0000
committerjeandel <jeandel@280ebfd0-de03-0410-8827-d642c229c3f4>2000-06-28 08:33:06 +0000
commitf38c3ab9f3c7e6759d94f0100fc72668d891e4e3 (patch)
tree283e20ab9335a648771ca23a2e4086833c93e504 /extract.c
parent5d14d60bf867a62887d12f1bc6fdee043ff089ae (diff)
downloadmpfr-f38c3ab9f3c7e6759d94f0100fc72668d891e4e3.tar.gz
First Release
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@653 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'extract.c')
-rw-r--r--extract.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/extract.c b/extract.c
new file mode 100644
index 000000000..29655dba4
--- /dev/null
+++ b/extract.c
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <math.h>
+#include <stdlib.h>
+
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "mpfr.h"
+#include "assert.h"
+
+
+int
+#if __STDC__
+mpfr_extract(mpz_ptr y, mpfr_srcptr p, int i)
+#else
+mpfr_extract(y,p,i)
+mpz_ptr y;
+mpfr_srcptr p;
+int i;
+#endif
+{
+ int two_i=1 << i;
+ int two_i_2 = i ? two_i / 2 : 1;
+ int size;
+ int j;
+ if (ABSSIZE(p) < two_i){
+ int j;
+ y->_mp_alloc=two_i_2 ;
+ y->_mp_size=two_i_2 ;
+ y->_mp_d = calloc(two_i_2,sizeof( mp_limb_t));
+ assert(y->_mp_d!=NULL);
+ /* attention : initialiser a 0 si on utilise malloc */
+ for(j= 0; j < ABSSIZE(p) - two_i_2 ; j++){
+ y->_mp_d[j + two_i - ABSSIZE(p)] = p->_mp_d[j];
+ }
+ } else
+ {
+ y->_mp_d = p->_mp_d+ABSSIZE(p) - two_i;
+ y->_mp_alloc=two_i_2 ;
+ y->_mp_size=two_i_2 ;
+ }
+ /* if ISNEG(p)
+ CHANGE_SIGN(y);*/
+
+ size = ABSSIZE(y);
+ for (j = 0; j < size; j++)
+ {
+ if (y->_mp_d[j])
+ {
+ if ISNEG(p)
+ mpz_neg(y,y);
+ return 0;
+ }
+ }
+ y->_mp_size=0;
+
+ return 0;
+}
+
+
+