Changeset bf29a4 in git


Ignore:
Timestamp:
Dec 21, 2000, 2:22:01 PM (23 years ago)
Author:
Wilfred Pohl <pohl@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
5dab69d5a393466d9560045523c22692fb9c1323
Parents:
bfbc32c19cef318430013cfd78dc6aa9af738067
Message:
MapLongR


git-svn-id: file:///usr/local/Singular/svn/trunk@4970 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Singular/longrat.cc

    rbfbc32 rbf29a4  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: longrat.cc,v 1.34 2000-12-15 18:49:32 Singular Exp $ */
     4/* $Id: longrat.cc,v 1.35 2000-12-21 13:22:00 pohl Exp $ */
    55/*
    66* ABSTRACT: computation with long rational numbers (Hubert Grassmann)
     
    121121}
    122122
    123 //static number nlMapLongR(number from);
     123static number nlMapLongR(number from);
    124124static number nlMapR(number from);
    125125
     
    139139    return nlMapR;
    140140  }
    141 //  if (rField_is_long_R(r))
    142 //  {
    143 //    nMap = nlMapLongR; /* long R -> Q */
    144 //    return TRUE;
    145 //  }
     141  if (rField_is_long_R(src))
     142  {
     143    return nlMapLongR; /* long R -> Q */
     144  }
    146145  return NULL;
    147146}
     
    279278  nlNormalize(r);
    280279  return r;
     280}
     281
     282static number nlMapLongR(number from)
     283{
     284  gmp_float *ff=(gmp_float*)from;
     285  mpf_t *f=ff->_mpfp();
     286  number res;
     287  lint *dest,*ndest;
     288  int size, i,negative;
     289  int e,al,bl;
     290  mp_ptr qp,dd,nn;
     291
     292  size = (*f)[0]._mp_size;
     293  if (size == 0)
     294    return nlInit(0);
     295  if(size<0)
     296  {
     297    negative = 1;
     298    size = -size;
     299  }
     300  else
     301    negative = 0;
     302
     303  qp = (*f)[0]._mp_d;
     304  while(qp[0]==0)
     305  {
     306    qp++;
     307    size--;
     308  }
     309
     310  e=(*f)[0]._mp_exp-size;
     311  res = (number)omAllocBin(rnumber_bin);
     312#if defined(LDEBUG)
     313  res->debug=123456;
     314#endif
     315  dest = &(res->z);
     316
     317  if (e<0)
     318  {
     319    al = dest->_mp_size = size;
     320    if (al<2) al = 2;
     321    dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
     322    for (i=0;i<size;i++) dd[i] = qp[i];
     323    bl = 1-e;
     324    nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
     325    nn[bl-1] = 1;
     326    for (i=bl-2;i>=0;i--) nn[i] = 0;
     327    ndest = &(res->n);
     328    ndest->_mp_d = nn;
     329    ndest->_mp_alloc = ndest->_mp_size = bl;
     330    res->s = 0;
     331  }
     332  else
     333  {
     334    al = dest->_mp_size = size+e;
     335    if (al<2) al = 2;
     336    dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
     337    for (i=0;i<size;i++) dd[i+e] = qp[i];
     338    for (i=0;i<e;i++) dd[i] = 0;
     339    res->s = 3;
     340  }
     341
     342  dest->_mp_d = dd;
     343  dest->_mp_alloc = al;
     344  if (negative) dest->_mp_size = -dest->_mp_size;
     345
     346  if (res->s==0)
     347    nlNormalize(res);
     348  else if (mpz_size1(&res->z)<=MP_SMALL)
     349  {
     350    int ui=(int)mpz_get_si(&res->z);
     351    if ((((ui<<3)>>3)==ui)
     352       && (mpz_cmp_si(&res->z,(long)ui)==0))
     353    {
     354       mpz_clear(&res->z);
     355       omFreeBin((ADDRESS)res, rnumber_bin);
     356       return INT_TO_SR(ui);
     357    }
     358  }
     359#if defined(LDEBUG)
     360  nlTest(res);
     361#endif
     362  return res;
    281363}
    282364
  • Singular/modulop.cc

    rbfbc32 rbf29a4  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: modulop.cc,v 1.23 2000-12-15 18:49:34 Singular Exp $ */
     4/* $Id: modulop.cc,v 1.24 2000-12-21 13:22:01 pohl Exp $ */
    55/*
    66* ABSTRACT: numbers modulo p (<=32003)
     
    1515#include "numbers.h"
    1616#include "longrat.h"
     17#include "mpr_complex.h"
    1718#include "ring.h"
    1819#include "modulop.h"
     
    289290}
    290291
    291 
    292292#ifdef LDEBUG
    293293BOOLEAN npDBTest (number a, char *f, int l)
     
    316316  i%=npPrimeM;
    317317  return (number)i;
     318}
     319
     320static number npMapLongR(number from)
     321{
     322  gmp_float *ff=(gmp_float*)from;
     323  mpf_t *f=ff->_mpfp();
     324  number res;
     325  lint *dest,*ndest;
     326  int size,i;
     327  int e,al,bl,iz,in;
     328  mp_ptr qp,dd,nn;
     329
     330  size = (*f)[0]._mp_size;
     331  if (size == 0)
     332    return npInit(0);
     333  if(size<0)
     334    size = -size;
     335
     336  qp = (*f)[0]._mp_d;
     337  while(qp[0]==0)
     338  {
     339    qp++;
     340    size--;
     341  }
     342
     343  if(npPrimeM>2)
     344    e=(*f)[0]._mp_exp-size;
     345  else
     346    e=0;
     347  res = (number)omAllocBin(rnumber_bin);
     348#if defined(LDEBUG)
     349  res->debug=123456;
     350#endif
     351  dest = &(res->z);
     352
     353  if (e<0)
     354  {
     355    al = dest->_mp_size = size;
     356    if (al<2) al = 2;
     357    dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
     358    for (i=0;i<size;i++) dd[i] = qp[i];
     359    bl = 1-e;
     360    nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
     361    nn[bl-1] = 1;
     362    for (i=bl-2;i>=0;i--) nn[i] = 0;
     363    ndest = &(res->n);
     364    ndest->_mp_d = nn;
     365    ndest->_mp_alloc = ndest->_mp_size = bl;
     366    res->s = 0;
     367    in=mpz_mmod_ui(NULL,ndest,npPrimeM);
     368    mpz_clear(ndest);
     369  }
     370  else
     371  {
     372    al = dest->_mp_size = size+e;
     373    if (al<2) al = 2;
     374    dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
     375    for (i=0;i<size;i++) dd[i+e] = qp[i];
     376    for (i=0;i<e;i++) dd[i] = 0;
     377    res->s = 3;
     378  }
     379
     380  dest->_mp_d = dd;
     381  dest->_mp_alloc = al;
     382  iz=mpz_mmod_ui(NULL,dest,npPrimeM);
     383  mpz_clear(dest);
     384  omFreeBin((ADDRESS)res, rnumber_bin);
     385  if(res->s==0)
     386    iz=(int)npDiv((number)iz,(number)in);
     387  return (number)iz;
    318388}
    319389
     
    336406    }
    337407  }
     408  if (rField_is_long_R(src))
     409  {
     410    return npMapLongR;
     411  }
    338412  return NULL;      /* default */
    339413}
Note: See TracChangeset for help on using the changeset viewer.