Changeset baa707d in git


Ignore:
Timestamp:
Jul 2, 1999, 5:01:43 PM (24 years ago)
Author:
Moritz Wenk <wenk@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
78315991a696a660dd3d43059499d754ccf8c669
Parents:
1ce62fa5979699f05bc8ccbc453b8bfdafd92c1c
Message:
*wenk: fixed ngfRead and complex number output


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

Legend:

Unmodified
Added
Removed
  • Singular/gnumpfl.cc

    r1ce62fa rbaa707d  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: gnumpfl.cc,v 1.5 1999-07-02 14:28:52 Singular Exp $ */
     4/* $Id: gnumpfl.cc,v 1.6 1999-07-02 15:01:42 wenk Exp $ */
    55/*
    66* ABSTRACT: computations with GMP floating-point numbers
     
    242242  if ( exp == 0 )
    243243  {
    244     nNew(u);
    245     *(gmp_float*)u= (gmp_float)1.0;
     244    gmp_float* n = new gmp_float(1);
     245    *u=(number)n;
    246246    return;
    247247  }
     
    251251    if ( x == NULL )
    252252    {
    253       *(gmp_float*)(*u) = (gmp_float)0.0;
     253      gmp_float* n = new gmp_float();
     254      *u=(number)n;
    254255    }
    255256    else
    256257    {
    257       *(gmp_float*)(*u) = *(gmp_float*)x;
     258      gmp_float* n = new gmp_float();
     259      *n= *(gmp_float*)x;
     260      *u=(number)n;
    258261    }
    259262    return;
     
    262265  ngfPower(x,exp-1,u);
    263266
    264   *(gmp_float*)(*u) *= *(gmp_float*)x;
     267  gmp_float *n=new gmp_float();
     268  *n=*(gmp_float*)x;
     269  *(gmp_float*)(*u) *= *(gmp_float*)n;
    265270
    266271}
     
    347352  // eat floats (mantissa) like:
    348353  //   0.394394993, 102.203003008,  .300303032
    349   while ((*s >= '0' && *s <= '9')||(*s == '.'))
    350   {
    351     s++;
    352   }
     354  while ((*s >= '0' && *s <= '9')||(*s == '.')) s++;
     355
    353356  // eat the exponent, starts with 'e' followed by '+', '-'
    354   // or no sign and digits, like:
    355   //  e1322, e-202, e+393
    356   if ( (s != start) && (*s == 'e') )
    357   {
    358     s++;
    359     if ( (*s=='-') || (*s=='+') ) s++;
    360     while ((*s >= '0' && *s <= '9'))
    361     {
    362       s++;
    363     }
     357  // and digits, like:
     358  //   e-202, e+393
     359  if ( (s != start) && (*s == 'e') && ((*(s+1) == '+') || (*(s+1) == '-')) )
     360  {
     361    s=s+2; // eat e and sign
     362    while ((*s >= '0' && *s <= '9')) s++;
    364363  }
    365364
  • Singular/mpr_complex.cc

    r1ce62fa rbaa707d  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mpr_complex.cc,v 1.9 1999-07-02 14:28:53 Singular Exp $ */
     4/* $Id: mpr_complex.cc,v 1.10 1999-07-02 15:01:43 wenk Exp $ */
    55
    66/*
     
    278278  if ( strlen(in) == 0 )
    279279  {
    280     *size= 2*sizeof(char)+10;
     280    *size= 2*sizeof(char);
    281281    out= (char*)AllocL( *size );
    282282    strcpy(out,"0");
     
    291291      int eexponent= (exponent >= 0) ? 0 : -exponent;
    292292      int eeexponent= (exponent >= 0) ? exponent : 0;
    293       *size= (strlen(in)+5+eexponent) * sizeof(char) + 10;
     293      *size= (strlen(in)+15+eexponent) * sizeof(char);
    294294      out= (char*)AllocL(*size);
    295       memset(out,'\0',*size);
     295      memset(out,0,*size);
    296296
    297297      strcpy(out,csign);
     
    311311    else if ( exponent+sign > (int)strlen(in) )
    312312    {
    313       *size= (strlen(in)+exponent+2)*sizeof(char)+10;
     313      *size= (strlen(in)+exponent+12)*sizeof(char);
    314314      out= (char*)AllocL(*size);
     315      memset(out,0,*size);
    315316      sprintf(out,"%s%s",csign,in+sign);
    316317      memset(out+strlen(out),'0',exponent-strlen(in)+sign);
     
    320321      *size= (strlen(in)+2) * sizeof(char) + 10;
    321322      out= (char*)AllocL(*size);
     323      memset(out,0,*size);
    322324      sprintf(out,"%s%s",csign,in+sign);
    323325    }
     
    335337      *size= (strlen(in)+12+c) * sizeof(char) + 10;
    336338      out= (char*)AllocL(*size);
     339      memset(out,0,*size);
    337340      sprintf(out,"%s0.%se%d",csign,in+sign,(unsigned int)exponent);
    338341//      }
     
    504507  if ( !c.imag().isZero() )
    505508  {
    506     in_real=floatToStr( c.real(), oprec );         // get real part
     509
     510      in_real=floatToStr( c.real(), oprec );         // get real part
    507511    in_imag=floatToStr( abs(c.imag()), oprec );    // get imaginary part
    508512
     
    512516      out=(char*)AllocL(len);
    513517      memset(out,0,len);
    514       sprintf(out,"%s%s%s*%s",in_real,c.imag().sign()>=0?"+":"-",currRing->parameter[0],in_imag);
     518      if (  !c.real().isZero() )
     519        sprintf(out,"(%s%s%s*%s)",in_real,c.imag().sign()>=0?"+":"-",currRing->parameter[0],in_imag);
     520      else
     521        sprintf(out,"(%s%s*%s)",c.imag().sign()>=0?"":"-",currRing->parameter[0],in_imag);
    515522    }
    516523    else
     
    519526      out=(char*)AllocL( len );
    520527      memset(out,0,len);
    521       sprintf(out,"%s%s%s",in_real,c.imag().sign()>=0?" + I ":" - I ",in_imag);
     528      if (  !c.real().isZero() )
     529        sprintf(out,"(%s%s%s)",in_real,c.imag().sign()>=0?"+I*":"-I*",in_imag);
     530      else
     531        sprintf(out,"(%s%s)",c.imag().sign()>=0?"I*":"-I*",in_imag);
    522532    }
    523533    FreeL( (ADDRESS) in_real );
    524534    FreeL( (ADDRESS) in_imag );
    525535  }
    526   else
     536  else 
    527537  {
    528538    out= floatToStr( c.real(), oprec );
    529539  }
     540
    530541  return out;
    531542}
Note: See TracChangeset for help on using the changeset viewer.