Changeset 5ce0793 in git for Singular/mpr_complex.cc


Ignore:
Timestamp:
Jun 5, 2000, 2:53:24 PM (24 years ago)
Author:
Wilfred Pohl <pohl@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
Children:
191c94de014986ddfda1bf819a80b8ca4be61eec
Parents:
4a0a5d596d166bd7225fe54833032e8b60423bba
Message:
new zero-check


git-svn-id: file:///usr/local/Singular/svn/trunk@4428 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/mpr_complex.cc

    r4a0a5d5 r5ce0793  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mpr_complex.cc,v 1.19 2000-04-27 10:07:09 obachman Exp $ */
     4/* $Id: mpr_complex.cc,v 1.20 2000-06-05 12:53:24 pohl Exp $ */
    55
    66/*
     
    4040
    4141int dummy=mmInit();
    42 const gmp_float  gmpOne= 1;
    43 const gmp_float gmpMOne= -1;
    44 const gmp_float gmpZero= 0;
     42static const gmp_float  gmpOne= 1;
     43static const gmp_float gmpMOne= -1;
     44static gmp_float gmpRel=0;
     45static gmp_float diff=0;
    4546
    4647
     
    7677  size_t bits= 1 + (size_t) (digits / (log(2)/log(10)));
    7778  bits= bits>64?bits:64;
    78   //gmp_float::setPrecision( bits+EXTRABYTES*8 );
    79   gmp_float::setPrecision( bits+(bits/5) );
     79  gmp_float::setPrecision( bits+bits );
    8080  gmp_float::setEqualBits( bits );
    8181  gmp_output_digits= digits;
     82  mpf_set_default_prec( bits+bits );
     83  mpf_set_ui(*gmpRel.mpfp(),1);
     84  mpf_div_2exp(*gmpRel.mpfp(),*gmpRel.mpfp(),bits);
    8285}
    8386
     
    142145}
    143146
    144 // <gmp_float> == <gmp_float> ?? up to the first gmp_float::gmp_needequal_bits bits
     147// <gmp_float> operator <gmp_float>
     148gmp_float & gmp_float::operator += ( const gmp_float & a )
     149{
     150  gmp_float r = -a;
     151  if (!(*this == r))
     152    mpf_sub( t, t, r.t );
     153  else
     154    mpf_set_d( t, 0.0);
     155  return *this;
     156}
     157gmp_float & gmp_float::operator -= ( const gmp_float & a )
     158{
     159  gmp_float r = a;
     160  if (!(*this == r))
     161    mpf_sub( t, t, r.t );
     162  else
     163    mpf_set_d( t, 0.0);
     164  return *this;
     165}
     166
     167// <gmp_float> == <gmp_float> ??
    145168bool operator == ( const gmp_float & a, const gmp_float & b )
    146169{
    147   //return mpf_cmp( a.t, b.t ) == 0;
    148   return mpf_eq( a.t , b.t , gmp_float::gmp_needequal_bits );
     170  if(mpf_sgn(a.t) != mpf_sgn(b.t))
     171    return false;
     172  mpf_reldiff(diff.t, a.t, b.t);
     173  mpf_abs(diff.t, diff.t);
     174  if(diff < gmpRel)
     175    return true;
     176  else
     177    return false;
     178}
     179// t == 0 ?
     180bool gmp_float::isZero()
     181{
     182  return (mpf_sgn( t ) == 0);
     183}
     184// t == 1 ?
     185bool gmp_float::isOne()
     186{
     187#ifdef  VARIANTE_1
     188  return (mpf_cmp_ui( t , 1 ) == 0);
     189#else
     190  if (mpf_sgn(t) <= 0)
     191    return false;
     192  mpf_reldiff(diff.t, t, gmpOne.t);
     193  mpf_abs(diff.t, diff.t);
     194  if(diff < gmpRel)
     195    return true;
     196  else
     197    return false;
     198#endif
     199}
     200// t == -1 ?
     201bool gmp_float::isMOne()
     202{
     203#ifdef VARIANTE_1
     204  return (mpf_cmp_si( t , -1 ) == 0);
     205#else
     206  if (mpf_sgn(t) >= 0)
     207    return false;
     208  mpf_reldiff(diff.t, t, gmpMOne.t);
     209  mpf_abs(diff.t, diff.t);
     210  if(diff < gmpRel)
     211    return true;
     212  else
     213    return false;
     214#endif
    149215}
    150216bool operator > ( const gmp_float & a, const gmp_float & b )
Note: See TracChangeset for help on using the changeset viewer.