Changeset 527ac8 in git
- Timestamp:
- Jun 27, 2000, 2:10:29 PM (24 years ago)
- Branches:
- (u'spielwiese', '4a9821a93ffdc22a6696668bd4f6b8c9de3e6c5f')
- Children:
- 6fc7629b829f4a03989472dd474d746be74e241d
- Parents:
- 6e5e20e2ab7029c2c8cd3a2eeb25ed3fb548f75f
- Location:
- Singular
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/mpr_complex.cc
r6e5e20 r527ac8 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: mpr_complex.cc,v 1.2 3 2000-06-26 08:11:10pohl Exp $ */4 /* $Id: mpr_complex.cc,v 1.24 2000-06-27 12:10:29 pohl Exp $ */ 5 5 6 6 /* … … 588 588 gmp_complex operator * ( const gmp_complex & a, const gmp_complex & b ) 589 589 { 590 return gmp_complex( a.r eal() * b.real() - a.imag() * b.imag(),591 a.r eal() * b.imag() + a.imag() * b.real());590 return gmp_complex( a.r * b.r - a.i * b.i, 591 a.r * b.i + a.i * b.r); 592 592 } 593 593 gmp_complex operator / ( const gmp_complex & a, const gmp_complex & b ) 594 594 { 595 gmp_float ar = abs(b.real()); 596 gmp_float ai = abs(b.imag()); 597 gmp_float nr, ni, t, d; 598 if (ar <= ai) 599 { 600 t = b.real() / b.imag(); 601 d = b.imag() * ((gmp_float)1 + t*t); 602 nr = (a.real() * t + a.imag()) / d; 603 ni = (a.imag() * t - a.real()) / d; 604 } 605 else 606 { 607 t = b.imag() / b.real(); 608 d = b.real() * ((gmp_float)1 + t*t); 609 nr = (a.real() + a.imag() * t) / d; 610 ni = (a.imag() - a.real() * t) / d; 611 } 612 return gmp_complex( nr, ni ); 595 gmp_float d = b.r*b.r + b.i*b.i; 596 return gmp_complex( (a.r * b.r + a.i * b.i) / d, 597 (a.i * b.r - a.r * b.i) / d); 613 598 } 614 599 … … 636 621 gmp_complex & gmp_complex::operator /= ( const gmp_complex & b ) 637 622 { 638 gmp_float ar = abs(b.r); 639 gmp_float ai = abs(b.i); 640 gmp_float nr, ni, t, d; 641 if (ar <= ai) 642 { 643 t = b.r / b.i; 644 d = b.i * ((gmp_float)1 + t*t); 645 nr = (r * t + i) / d; 646 ni = (i * t - r) / d; 647 } 648 else 649 { 650 t = b.i / b.r; 651 d = b.r * ((gmp_float)1 + t*t); 652 nr = (r + i * t) / d; 653 ni = (i - r * t) / d; 654 } 655 r = nr; 656 i = ni; 623 gmp_float d = b.r*b.r + b.i*b.i; 624 r = (r * b.r + i * b.i) / d; 625 i = (i * b.r - r * b.i) / d; 657 626 return *this; 658 627 } … … 688 657 // converts a gmp_complex to a string ( <real part> + I * <imaginary part> ) 689 658 // 690 char *complexToStr( constgmp_complex & c, const unsigned int oprec )659 char *complexToStr( gmp_complex & c, const unsigned int oprec ) 691 660 { 692 661 char *out,*in_imag,*in_real; 693 662 663 c.SmallToZero(); 694 664 if ( !c.imag().isZero() ) 695 665 { … … 756 726 } 757 727 728 void gmp_complex::SmallToZero() 729 { 730 gmp_float ar=this->real(); 731 gmp_float ai=this->imag(); 732 if (ar.isZero() || ai.isZero()) return; 733 mpf_abs(*ar.mpfp(), *ar.mpfp()); 734 mpf_abs(*ai.mpfp(), *ai.mpfp()); 735 mpf_set_prec(*ar.mpfp(), 32); 736 mpf_set_prec(*ai.mpfp(), 32); 737 if (ar > ai) 738 { 739 mpf_div(*ai.mpfp(), *ai.mpfp(), *ar.mpfp()); 740 if (ai < gmpRel) this->imag(0.0); 741 } 742 else 743 { 744 mpf_div(*ar.mpfp(), *ar.mpfp(), *ai.mpfp()); 745 if (ar < gmpRel) this->real(0.0); 746 } 747 } 748 758 749 //%e 759 750 -
Singular/mpr_complex.h
r6e5e20 r527ac8 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: mpr_complex.h,v 1.1 3 2000-06-26 08:02:23pohl Exp $ */6 /* $Id: mpr_complex.h,v 1.14 2000-06-27 12:10:29 pohl Exp $ */ 7 7 8 8 /* … … 286 286 inline void real( gmp_float val ) { r = val; } 287 287 inline void imag( gmp_float val ) { i = val; } 288 289 void SmallToZero(); 288 290 }; 289 291 … … 347 349 } 348 350 349 char *complexToStr( constgmp_complex & c, const unsigned int oprec );351 char *complexToStr( gmp_complex & c, const unsigned int oprec ); 350 352 //<- 351 353
Note: See TracChangeset
for help on using the changeset viewer.