Changeset 045efb in git


Ignore:
Timestamp:
Aug 10, 2011, 7:43:14 PM (13 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', '52dcfddee5ec87d404d5e0fb44f2d627608208f1')
Children:
5ff1d31f3d80f972b5abf4d4435d01cb9b033ffb
Parents:
b1ca9992c1a4e67c4f6161015c9bb3efd24c96f4
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2011-08-10 19:43:14+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 13:19:14+01:00
Message:
ADD: conversion between numbers and mpz_t (GMP integers)
Location:
libpolys/coeffs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/coeffs.h

    rb1ca999 r045efb  
    116116   // general stuff
    117117   numberfunc cfMult, cfSub ,cfAdd ,cfDiv, cfIntDiv, cfIntMod, cfExactDiv;
     118   
    118119   /// init with an integer
    119120   number  (*cfInit)(int i,const coeffs r);
     121
     122   /// init with a GMP integer
     123   number  (*cfInitMPZ)(mpz_t i, const coeffs r);
     124   
    120125   /// how complicated, (0) => 0, or positive
    121126   int     (*cfSize)(number n, const coeffs r);
    122    /// convertion, 0 if impossible
     127   
     128   /// convertion to int, 0 if impossible
    123129   int     (*cfInt)(number &n, const coeffs r);
    124130
     131   /// Converts a non-negative number n into a GMP number, 0 if impossible
     132   void     (*cfMPZ)(mpz_t result, number &n, const coeffs r);
     133   
    125134#ifdef HAVE_RINGS
    126135   int     (*cfDivComp)(number a,number b,const coeffs r);
     
    374383{ assume(r != NULL); assume(r->cfInit!=NULL); return r->cfInit(i,r); }
    375384
     385/// conversion of a GMP integer to number
     386static inline number n_Init(mpz_t n,     const coeffs r)
     387{ assume(r != NULL); assume(r->cfInitMPZ != NULL); return r->cfInitMPZ(n,r); }
     388
    376389/// conversion of n to an int; 0 if not possible
    377390/// in Z/pZ: the representing int lying in (-p/2 .. p/2]
    378391static inline int n_Int(number &n,       const coeffs r)
    379392{ assume(r != NULL); assume(r->cfInt!=NULL); return r->cfInt(n,r); }
     393
     394/// conversion of n to a GMP integer; 0 if not possible
     395static inline void n_MPZ(mpz_t result, number &n,       const coeffs r)
     396{ assume(r != NULL); assume(r->cfMPZ!=NULL); r->cfMPZ(result, n, r); }
     397
    380398
    381399/// in-place negation of n
  • libpolys/coeffs/longrat.cc

    rb1ca999 r045efb  
    542542}
    543543
     544void nlMPZ(mpz_t m, number &n, const coeffs r)
     545{
     546  assume( getCoeffType(r) == ID );
     547   
     548  nlTest(n, r);
     549  nlNormalize(n, r);
     550  if (SR_HDL(n) & SR_INT) mpz_init_set_si(m, SR_TO_INT(n));     /* n fits in an int */
     551  else             mpz_init_set(m, (mpz_ptr)n->z);
     552}
     553
     554
    544555/*2
    545556* convert number to int
     
    20912102}
    20922103
    2093 
    20942104LINLINE number nlInit (int i, const coeffs r)
    20952105{
     
    21022112}
    21032113
     2114
     2115number nlInitMPZ(mpz_t m, const coeffs r)
     2116{
     2117  number z = ALLOC_RNUMBER();
     2118  mpz_init_set(z->z, m);
     2119  mpz_init_set_ui(z->n, 1);
     2120  z->s = 3;
     2121  return z;   
     2122}
    21042123
    21052124/*2
     
    25962615  r->cfExactDiv= nlExactDiv;
    25972616  r->cfInit = nlInit;
     2617  r->cfInitMPZ = nlInitMPZ;
    25982618  r->cfSize  = nlSize;
    25992619  r->cfInt  = nlInt;
     2620  r->cfMPZ = nlMPZ;
     2621 
    26002622  r->cfChineseRemainder=nlChineseRemainder;
    26012623  r->cfFarey=nlFarey;
  • libpolys/coeffs/longrat.h

    rb1ca999 r045efb  
    9090number   nlChineseRemainder(number *x, number *q,int rl, const coeffs C);
    9191number   nlFarey(number nN, number nP, const coeffs CF);
     92
    9293#ifdef LDEBUG
    9394BOOLEAN  nlDBTest(number a, const char *f, const int l);
  • libpolys/coeffs/numbers.cc

    rb1ca999 r045efb  
    144144  Werror("no conversion from bigint to this field");
    145145  return NULL;
     146}
     147
     148/**< [in, out] a bigint number >= 0  */
     149/**< [out] the GMP equivalent    */
     150/// Converts a non-negative bigint number into a GMP number.
     151void ndMPZ(mpz_t result, number &n, const coeffs r)
     152{
     153  mpz_init_set_si( result, n_Int(n, r) );
     154}
     155
     156number ndInitMPZ(mpz_t m, const coeffs r)
     157{
     158  return n_Init( mpz_get_si(m), r);
    146159}
    147160
     
    215228    n->cfLcm  = ndGcd; /* tricky, isn't it ?*/
    216229    n->cfInit_bigint = ndInit_bigint;
     230    n->cfInitMPZ = ndInitMPZ;
     231    n->cfMPZ = ndMPZ;
     232
    217233    //n->cfKillChar = ndKillChar; /* dummy */
    218234    // temp. removed to catch all the coeffs which miss to implement this!
     
    266282    assume(n->cfExactDiv!=NULL);
    267283    assume(n->cfInit!=NULL);
     284    assume(n->cfInitMPZ!=NULL);
    268285    assume(n->cfSize!=NULL);
    269286    assume(n->cfInt!=NULL);
     287    assume(n->cfMPZ!=NULL);
    270288    //assume(n->n->cfDivComp!=NULL);
    271289    //assume(n->cfIsUnit!=NULL);
     
    295313    assume(n->cfName!=NULL);
    296314    assume(n->cfInpMult!=NULL);
    297     //assume(n->cfInit_bigint!=NULL);
     315//    assume(n->cfInit_bigint!=NULL);
    298316    assume(n->cfCoeffWrite != NULL);
    299317#ifdef LDEBUG
Note: See TracChangeset for help on using the changeset viewer.