Changeset 210852 in git


Ignore:
Timestamp:
May 29, 2010, 5:45:24 PM (14 years ago)
Author:
Mohamed Barakat <mohamed.barakat@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b52fc4b2495505785981d640dcf7eb3e456778ef')
Children:
5b702faf0ba7a3d669f0c92068b7320cf1a40a4e
Parents:
4c09bbcd5e80cefbcef0abdd5891aad7a7ba2f72
git-author:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2010-05-29 17:45:24+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 11:54:58+01:00
Message:
started adapting gnumpfl.{h,cc}
Location:
coeffs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • coeffs/gnumpc.cc

    r4c09bb r210852  
    535535  assume( getCoeffType(aRing) ==  n_Zp );
    536536
    537   if ( from != NULL)
     537  if ( from != NULL )
    538538    return ngcInit(npInt(from, aRing), r);
    539539  else
    540540    return NULL;
    541541}
    542 
    543 
    544542
    545543static number ngcCopyMap(number from, const coeffs aRing, const coeffs r)
     
    557555}
    558556
    559 
    560557nMapFunc ngcSetMap(const coeffs src, const coeffs dst)
    561558{
    562559  assume( getCoeffType(dst) == ID );
    563560
    564   if(nField_is_Q(src))
     561  if (nField_is_Q(src))
    565562  {
    566563    return ngcMapQ;
     
    574571    return ngcCopyMap;
    575572  }
    576   if(nField_is_R(src))
     573  if (nField_is_R(src))
    577574  {
    578575    return ngcMapR;
     
    585582}
    586583
    587 
  • coeffs/gnumpfl.cc

    r4c09bb r210852  
    2323//ring ngfMapRing; // to be used also in gnumpc.cc
    2424
     25/// Our Type!
     26static const n_coeffType ID = n_gnump_R;
     27
    2528static number ngfMapP(number from, const coeffs src, const coeffs dst)
    2629{
     
    5255}
    5356
    54 nMapFunc ngfSetMap(const ring src, const ring dst)
    55 {
    56   if (rField_is_Q(src))
    57   {
    58     return ngfMapQ;
    59   }
    60   if (rField_is_long_R(src))
    61   {
    62     return ngfCopy;
    63   }
    64   if (rField_is_R(src))
    65   {
    66     return ngfMapR;
    67   }
    68   if (rField_is_Zp(src))
    69   {
    70     ngfMapRing=src;
    71     return ngfMapP;
    72   }
    73   if (rField_is_long_C(src))
    74   {
    75     return ngfMapC;
    76   }
    77   return NULL;
    78 }
    79 
    8057/*2
    8158* n := i
     
    8360number ngfInit (int i, const coeffs r)
    8461{
     62  assume( getCoeffType(r) == ID );
     63 
    8564  gmp_float* n= new gmp_float( (double)i );
    8665  return (number)n;
     
    9271int ngfInt(number &i, const coeffs r)
    9372{
     73  assume( getCoeffType(r) == ID );
     74 
    9475  double d=(double)*(gmp_float*)i;
    9576  if (d<0.0)
     
    11596void ngfDelete (number * a, const coeffs r)
    11697{
     98  assume( getCoeffType(r) == ID );
     99 
    117100  if ( *a != NULL )
    118101  {
     
    127110number ngfCopy(number a, const coeffs r)
    128111{
     112  assume( getCoeffType(r) == ID );
     113 
    129114  gmp_float* b= new gmp_float( *(gmp_float*)a );
    130115  return (number)b;
     
    136121number ngfNeg (number a, const coeffs r)
    137122{
     123  assume( getCoeffType(r) == ID );
     124 
    138125  *(gmp_float*)a= -(*(gmp_float*)a);
    139126  return (number)a;
     
    143130* 1/a
    144131*/
    145 number ngfInvers(number a, const coeffs R)
    146 {
    147   gmp_float* r= NULL;
     132number ngfInvers(number a, const coeffs r)
     133{
     134  assume( getCoeffType(r) == ID );
     135 
     136  gmp_float* f= NULL;
    148137  if (((gmp_float*)a)->isZero() )
    149138  {
     
    162151number ngfAdd (number a, number b, const coeffs R)
    163152{
     153  assume( getCoeffType(R) == ID );
     154 
    164155  gmp_float* r= new gmp_float( (*(gmp_float*)a) + (*(gmp_float*)b) );
    165156  return (number)r;
     
    171162number ngfSub (number a, number b, const coeffs R)
    172163{
     164  assume( getCoeffType(R) == ID );
     165 
    173166  gmp_float* r= new gmp_float( (*(gmp_float*)a) - (*(gmp_float*)b) );
    174167  return (number)r;
     
    180173number ngfMult (number a, number b, const coeffs R)
    181174{
     175  assume( getCoeffType(R) == ID );
     176 
    182177  gmp_float* r= new gmp_float( (*(gmp_float*)a) * (*(gmp_float*)b) );
    183178  return (number)r;
     
    189184number ngfDiv (number a, number b, const coeffs r)
    190185{
     186  assume( getCoeffType(r) == ID );
     187 
    191188  if ( ((gmp_float*)b)->isZero() )
    192189  {
     
    204201number ngfPower (number x, int exp, const coeffs r)
    205202{
     203  assume( getCoeffType(r) == ID );
     204 
    206205  if ( exp == 0 )
    207206  {
     
    234233BOOLEAN ngfIsZero (number a, const coeffs r)
    235234{
     235  assume( getCoeffType(r) == ID );
     236 
    236237  return ( ((gmp_float*)a)->isZero() );
    237238}
     
    242243BOOLEAN ngfGreaterZero (number a, const coeffs r)
    243244{
     245  assume( getCoeffType(r) == ID );
     246 
    244247  return (((gmp_float*)a)->sign() > 0);
    245248}
     
    250253BOOLEAN ngfGreater (number a, number b, const coeffs r)
    251254{
     255  assume( getCoeffType(r) == ID );
     256 
    252257  return ( (*(gmp_float*)a) > (*(gmp_float*)b) );
    253258}
     
    258263BOOLEAN ngfEqual (number a, number b, const coeffs r)
    259264{
     265  assume( getCoeffType(r) == ID );
     266 
    260267  return ( (*(gmp_float*)a) == (*(gmp_float*)b) );
    261268}
     
    266273BOOLEAN ngfIsOne (number a, const coeffs r)
    267274{
     275  assume( getCoeffType(r) == ID );
     276 
    268277  return ((gmp_float*)a)->isOne();
    269278}
     
    274283BOOLEAN ngfIsMOne (number a, const coeffs r)
    275284{
     285  assume( getCoeffType(r) == ID );
     286 
    276287  return ((gmp_float*)a)->isMOne();
    277288}
     
    305316const char * ngfRead (const char * start, number * a, const coeffs r)
    306317{
     318  assume( getCoeffType(r) == ID );
     319 
    307320  char *s= (char *)start;
    308321
     
    362375void ngfWrite (number &a, const coeffs r)
    363376{
     377  assume( getCoeffType(r) == ID );
     378 
     379  extern size_t gmp_output_digits;
    364380  char *out;
    365381  if ( a != NULL )
    366382  {
    367     out= floatToStr(*(gmp_float*)a,gmp_output_digits);
     383    out= floatToStr(*(gmp_float*)a, gmp_output_digits, r);
    368384    StringAppendS(out);
    369385    //omFreeSize((void *)out, (strlen(out)+1)* sizeof(char) );
     
    376392}
    377393
     394static BOOLEAN ngfCoeffsEqual(const coeffs r, n_coeffType n, int)
     395{
     396  assume( getCoeffType(r) == ID );
     397 
     398  return (n == ID);
     399};
     400
     401void ngfInitChar(coeffs n, int)
     402{
     403  assume( getCoeffType(n) == ID );
     404
     405  n->cfDelete  = ngfDelete;
     406  n->nNormalize=ndNormalize;
     407  n->cfInit   = ngfInit;
     408  n->n_Int    = ngfInt;
     409  n->nAdd     = ngfAdd;
     410  n->nSub     = ngfSub;
     411  n->nMult    = ngfMult;
     412  n->nDiv     = ngfDiv;
     413  n->nExactDiv= ngfDiv;
     414  n->nNeg     = ngfNeg;
     415  n->nInvers  = ngfInvers;
     416  n->cfCopy   = ngfCopy;
     417  n->nGreater = ngfGreater;
     418  n->nEqual   = ngfEqual;
     419  n->nIsZero  = ngfIsZero;
     420  n->nIsOne   = ngfIsOne;
     421  n->nIsMOne  = ngfIsMOne;
     422  n->nGreaterZero = ngfGreaterZero;
     423  n->cfWrite  = ngfWrite;
     424  n->nRead    = ngfRead;
     425  n->nPower   = ngfPower;
     426  n->cfSetMap = ngfSetMap;
     427#ifdef LDEBUG
     428  n->nDBTest  = ndDBTest; // not yet implemented: ngfDBTest
     429#endif
     430
     431number ngfMapQ(number from, const coeffs aRing, const coeffs r)
     432{
     433  assume( getCoeffType(r) == ID );
     434  assume( getCoeffType(aRing) == n_Q );
     435 
     436  if ( from != NULL )
     437  {
     438    gmp_float *res=new gmp_float(numberFieldToFloat(from,QTOF));
     439    return (number)res;
     440  }
     441  else
     442    return NULL;
     443}
     444
     445static number ngfMapR(number from, const coeffs aRing, const coeffs r)
     446{
     447  assume( getCoeffType(r) == ID );
     448  assume( getCoeffType(aRing) == n_R );
     449 
     450  if ( from != NULL )
     451  {
     452    gmp_float *res=new gmp_float((double)nrFloat(from));
     453    return (number)res;
     454  }
     455  else
     456    return NULL;
     457}
     458
     459static number ngfMapP(number from, const coeffs aRing, const coeffs r)
     460{
     461  assume( getCoeffType(r) == ID );
     462  assume( getCoeffType(aRing) ==  n_Zp );
     463 
     464  if ( from != NULL )
     465    return ngfInit(npInt(from,src), dst);
     466  else
     467    return NULL;
     468}
     469
     470static number ngfMapC(number from, const coeffs aRing, const coeffs r)
     471{
     472  assume( getCoeffType(r) == ID );
     473  assume( getCoeffType(aRing) ==  n_long_C );
     474 
     475  if ( (from != NULL) || ((gmp_complex*)from)->real().isZero() )
     476  {
     477    gmp_float *res=new gmp_float(((gmp_complex*)from)->real());
     478    return (number)res;
     479  }
     480  else
     481    return NULL;
     482}
     483
     484nMapFunc ngfSetMap(const coeffs src, const coeffs dst)
     485{
     486  assume( getCoeffType(dst) == ID );
     487 
     488  if (nField_is_Q(src))
     489  {
     490    return ngfMapQ;
     491  }
     492  if (nField_is_long_R(src))
     493  {
     494    return ngfCopy;
     495  }
     496  if (nField_is_R(src))
     497  {
     498    return ngfMapR;
     499  }
     500  if (nField_is_long_C(src))
     501  {
     502    return ngfMapC;
     503  }
     504  if (nField_is_Zp(src))
     505  {
     506    return ngfMapP;
     507  }
     508  return NULL;
     509}
     510
     511
  • coeffs/gnumpfl.h

    r4c09bb r210852  
    1010#include "coeffs.h"
    1111
     12/// Get a mapping function from src into the domain of this type:
     13nMapFunc  ngfSetMap(const coeffs src, const coeffs dst);
     14
     15/// Initialize r
     16void ngfInitChar(coeffs r, int);
     17
     18/// test, whether r is an instance of nInitCoeffs(n, parameter) */
     19static BOOLEAN ngfCoeffsEqual(const coeffs r, n_coeffType n, int parameter);
     20
     21
     22/* // Private interface should be hidden!!!
     23/// Note: MAY NOT WORK AS EXPECTED!
    1224BOOLEAN  ngfGreaterZero(number za, const coeffs r);
    1325BOOLEAN  ngfGreater(number a, number b, const coeffs r);
     
    2537number   ngfDiv(number a, number b, const coeffs r);
    2638void     ngfPower(number x, int exp, number *lu, const coeffs r);
    27 number   ngfCopy(number a);
     39number   ngfCopy(number a, const coeffs r);
    2840number   ngf_Copy(number a, coeffs r);
    2941const char *   ngfRead (const char *s, number *a, const coeffs r);
     
    3244void     ngfDelete(number *a, const coeffs r);
    3345
    34 nMapFunc  ngfSetMap(const coeffs src, const coeffs dst);
    35 
    3646void setGMPFloatDigits( size_t digits, size_t rest );
    3747number ngfMapQ(number from, const coeffs r);
     48*/
    3849#endif
Note: See TracChangeset for help on using the changeset viewer.