scalar_arithm.C

00001 /*
00002  *  Arithmetical operations for class Scalar
00003  *
00004  */
00005 
00006 /*
00007  *   Copyright (c) 2003-2005 Eric Gourgoulhon & Jerome Novak
00008  *   Copyright (c) 1999-2001 Philippe Grandclement
00009  *
00010  *   This file is part of LORENE.
00011  *
00012  *   LORENE is free software; you can redistribute it and/or modify
00013  *   it under the terms of the GNU General Public License as published by
00014  *   the Free Software Foundation; either version 2 of the License, or
00015  *   (at your option) any later version.
00016  *
00017  *   LORENE is distributed in the hope that it will be useful,
00018  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *   GNU General Public License for more details.
00021  *
00022  *   You should have received a copy of the GNU General Public License
00023  *   along with LORENE; if not, write to the Free Software
00024  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 
00029 char scalar_arithm_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/Scalar/scalar_arithm.C,v 1.8 2005/11/17 15:30:11 e_gourgoulhon Exp $" ;
00030 
00031 /*
00032  * $Id: scalar_arithm.C,v 1.8 2005/11/17 15:30:11 e_gourgoulhon Exp $
00033  * $Log: scalar_arithm.C,v $
00034  * Revision 1.8  2005/11/17 15:30:11  e_gourgoulhon
00035  * Added arithmetics with Mtbl.
00036  *
00037  * Revision 1.7  2004/07/06 13:36:29  j_novak
00038  * Added methods for desaliased product (operator |) only in r direction.
00039  *
00040  * Revision 1.6  2004/02/19 10:55:11  e_gourgoulhon
00041  * Treatment of case ETATUN in  double*Scalar, double/Scalar and
00042  * Scalar/double: added the copy of the spectral bases from the
00043  * input to the result.
00044  *
00045  * Revision 1.5  2003/11/03 22:35:45  e_gourgoulhon
00046  * Changed output comment when dzpuis conflict.
00047  *
00048  * Revision 1.4  2003/10/28 21:34:47  e_gourgoulhon
00049  * Corrected treatment of the case ETATUN in operator+=, operator-= and
00050  * operator*=.
00051  *
00052  * Revision 1.3  2003/10/10 15:57:29  j_novak
00053  * Added the state one (ETATUN) to the class Scalar
00054  *
00055  * Revision 1.2  2003/10/01 13:04:44  e_gourgoulhon
00056  * The method Tensor::get_mp() returns now a reference (and not
00057  * a pointer) onto a mapping.
00058  *
00059  * Revision 1.1  2003/09/24 15:21:45  j_novak
00060  * New version
00061  *
00062  *
00063  * $Header: /cvsroot/Lorene/C++/Source/Tensor/Scalar/scalar_arithm.C,v 1.8 2005/11/17 15:30:11 e_gourgoulhon Exp $
00064  *
00065  */
00066 
00067 // headers C
00068 #include <assert.h>
00069 #include <stdlib.h>
00070 
00071 // headers Lorene
00072 #include "tensor.h"
00073 #include "type_parite.h"
00074 
00075             //********************//
00076             // OPERATEURS UNAIRES //
00077             //********************//
00078 
00079 Scalar operator+(const Scalar & ci) {
00080     return ci ;
00081 }
00082 
00083 Scalar operator-(const Scalar & ci) {
00084 
00085     // Cas particulier
00086     if ((ci.get_etat() == ETATZERO) || (ci.get_etat() == ETATNONDEF)) {
00087     return ci ;
00088     }
00089     
00090     // Cas general
00091     assert( (ci.get_etat() == ETATQCQ) || (ci.get_etat() == ETATUN)) ;  
00092     Scalar r(ci.get_mp()) ; // Scalar resultat
00093     r.set_etat_qcq() ;
00094     r.va = - ci.va ;    
00095     r.set_dzpuis( ci.get_dzpuis() ) ;
00096     
00097     // Termine
00098     return r ;
00099 }
00100 
00101             //**********//
00102             // ADDITION //
00103             //**********//
00104 // Scalar + Scalar
00105 // ---------
00106 Scalar operator+(const Scalar & c1, const Scalar & c2) {
00107     
00108     if (c1.get_etat() == ETATNONDEF) 
00109     return c1 ;
00110     if (c2.get_etat() == ETATNONDEF) 
00111     return c2 ;
00112     assert(c1.get_mp() == c2.get_mp()) ;
00113     
00114     // Cas particuliers
00115     if (c1.get_etat() == ETATZERO) {
00116     return c2 ;
00117     }
00118     if (c2.get_etat() == ETATZERO) {
00119     return c1 ;
00120     }
00121     if (c1.get_etat() == ETATUN) {
00122     return (c2 + double(1)) ;
00123     }
00124     if (c2.get_etat() == ETATUN) {
00125     return (c1 + double(1)) ;
00126     }
00127     assert(c1.get_etat() == ETATQCQ) ;
00128     assert(c2.get_etat() == ETATQCQ) ;
00129   
00130     // Cas general
00131 
00132     if ( c1.dz_nonzero() && c2.dz_nonzero() ) {
00133     if ( c1.get_dzpuis() != c2.get_dzpuis() ) {
00134         cout << "Operation Scalar + Scalar: dzpuis conflict in the external " << endl;
00135         cout << " compactified domain ! " << endl ; 
00136         abort() ;
00137     }
00138     }
00139     
00140     Scalar r(c1) ;      // Le resultat
00141     r.va += c2.va ;
00142     
00143     if (c1.dz_nonzero()) {
00144     r.set_dzpuis( c1.get_dzpuis() ) ; 
00145     }
00146     else{
00147     r.set_dzpuis( c2.get_dzpuis() ) ;   
00148     }
00149 
00150     // Termine
00151     return r ;
00152 }
00153 
00154 // Scalar + Mtbl
00155 // -------------
00156 Scalar operator+(const Scalar& c1, const Mtbl& mi) {
00157     
00158     if ((c1.get_etat() == ETATNONDEF) || (mi.get_etat() == ETATNONDEF)) {
00159         cerr << "Undifined state in Scalar + Mtbl !" << endl ;
00160         abort() ; 
00161     }
00162 
00163     // Cas particuliers
00164 
00165     if (mi.get_etat() == ETATZERO) {
00166     return c1 ;
00167     }
00168 
00169     assert( c1.check_dzpuis(0) ) ; 
00170     
00171     Scalar resu(c1) ;
00172     
00173     if (c1.get_etat() == ETATZERO) {
00174     resu = mi ; 
00175     }
00176     else {
00177       if (c1.get_etat() == ETATUN) {
00178     resu = double(1) + mi ; 
00179       }
00180       else{ 
00181     assert(resu.get_etat() == ETATQCQ) ; // sinon ...
00182     resu.va = resu.va + mi ;
00183       }
00184     }
00185      
00186     resu.set_dzpuis(0) ; 
00187        
00188     return resu ;
00189 }
00190 
00191 // Mtbl + Scalar
00192 // -------------
00193 Scalar operator+(const Mtbl& mi, const Scalar& c1) {
00194 
00195     return c1 + mi ; 
00196 }
00197 
00198 // Scalar + double
00199 // ------------
00200 Scalar operator+(const Scalar& t1, double x)       
00201 {
00202     // Protections
00203     assert(t1.get_etat() != ETATNONDEF) ;
00204     
00205     // Cas particuliers
00206     if (x == double(0)) {
00207     return t1 ;
00208     }
00209 
00210     assert( t1.check_dzpuis(0) ) ; 
00211      
00212     Scalar resu(t1) ;
00213     
00214     if (t1.get_etat() == ETATZERO) {
00215     resu = x ; 
00216     }
00217     else {
00218       if (t1.get_etat() == ETATUN) {
00219     resu = double(1) + x ; 
00220       }
00221       else{ 
00222     assert(resu.get_etat() == ETATQCQ) ; // sinon ...
00223     resu.va = resu.va + x ;
00224       }
00225     }
00226      
00227     resu.set_dzpuis(0) ; 
00228        
00229     return resu ;
00230 }
00231 
00232 // double + Scalar
00233 // ------------
00234 Scalar operator+(double x, const Scalar& t1)       
00235 {
00236     return t1 + x ;
00237 }
00238 
00239 // Scalar + int
00240 // ---------
00241 Scalar operator+(const Scalar& t1, int m)       
00242 {
00243     return t1 + double(m) ;
00244 }
00245 
00246 // int + Scalar
00247 // ---------
00248 Scalar operator+(int m, const Scalar& t1)      
00249 {
00250     return t1 + double(m) ;
00251 }
00252 
00253 
00254 
00255 
00256 
00257             //**************//
00258             // SOUSTRACTION //
00259             //**************//
00260 
00261 // Scalar - Scalar
00262 // ---------
00263 Scalar operator-(const Scalar & c1, const Scalar & c2) {
00264     
00265     if (c1.get_etat() == ETATNONDEF) 
00266     return c1 ;
00267     if (c2.get_etat() == ETATNONDEF) 
00268     return c2 ;
00269     
00270     assert(c1.get_mp() == c2.get_mp()) ;
00271     
00272     // Cas particuliers
00273     if (c1.get_etat() == ETATZERO) {
00274     return -c2 ;
00275     }
00276     if (c2.get_etat() == ETATZERO) {
00277     return c1 ;
00278     }
00279     if (c1.get_etat() == ETATUN) {
00280     return -(c2 - double(1)) ;
00281     }
00282     if (c2.get_etat() == ETATUN) {
00283     return (c1 - double(1)) ;
00284     }
00285     assert(c1.get_etat() == ETATQCQ) ;  // sinon...
00286     assert(c2.get_etat() == ETATQCQ) ;  // sinon...
00287 
00288    // Cas general
00289    if ( c1.dz_nonzero() && c2.dz_nonzero() ) {
00290     if ( c1.get_dzpuis() != c2.get_dzpuis() ) {
00291         cout << "Operation Scalar - Scalar : dzpuis conflict in the external " << endl;
00292         cout << " compactified domain ! " << endl ; 
00293         abort() ;
00294     }
00295     }
00296     
00297     Scalar r(c1) ;      // Le resultat
00298     r.va -= c2.va ;
00299     
00300     if (c1.dz_nonzero()) {
00301     r.set_dzpuis( c1.get_dzpuis() ) ; 
00302     }
00303     else{
00304     r.set_dzpuis( c2.get_dzpuis() ) ;   
00305     }
00306         
00307     // Termine
00308     return r ;
00309 }
00310 
00311 // Scalar - Mtbl
00312 // -------------
00313 Scalar operator-(const Scalar& t1, const Mtbl& mi) {
00314 
00315     // Protections
00316     assert(t1.get_etat() != ETATNONDEF) ;
00317     
00318     // Cas particuliers
00319     if (mi.get_etat() == ETATZERO) {
00320     return t1 ;
00321     }
00322 
00323     assert( t1.check_dzpuis(0) ) ; 
00324     
00325     Scalar resu(t1) ;
00326     
00327     if (t1.get_etat() == ETATZERO) {
00328       resu = - mi ; 
00329     }
00330     else{
00331       if (t1.get_etat() == ETATUN) {
00332     resu = double(1) - mi ; 
00333       }
00334       else{ 
00335     assert(resu.get_etat() == ETATQCQ) ; // sinon ...
00336     resu.va = resu.va - mi ;
00337       }
00338     } 
00339     resu.set_dzpuis(0) ; 
00340 
00341     return resu ;
00342 }
00343 
00344 // Mtbl - Scalar  
00345 // -------------
00346 Scalar operator-(const Mtbl& mi, const Scalar& t1) {
00347 
00348     return - (t1 - mi) ; 
00349 }
00350 
00351 // Scalar - double
00352 // ------------
00353 Scalar operator-(const Scalar& t1, double x)       
00354 {
00355     // Protections
00356     assert(t1.get_etat() != ETATNONDEF) ;
00357     
00358     // Cas particuliers
00359     if (x == double(0)) {
00360     return t1 ;
00361     }
00362 
00363     assert( t1.check_dzpuis(0) ) ; 
00364     
00365     Scalar resu(t1) ;
00366     
00367     if (t1.get_etat() == ETATZERO) {
00368       resu = - x ; 
00369     }
00370     else{
00371       if (t1.get_etat() == ETATUN) {
00372     resu = double(1) - x ; 
00373       }
00374       else{ 
00375     assert(resu.get_etat() == ETATQCQ) ; // sinon ...
00376     resu.va = resu.va - x ;
00377       }
00378     } 
00379     resu.set_dzpuis(0) ; 
00380 
00381     return resu ;
00382 }
00383 
00384 // double - Scalar
00385 // ------------
00386 Scalar operator-(double x, const Scalar& t1)        
00387 {
00388     return - (t1 - x) ;
00389 }
00390 
00391 // Scalar - int
00392 // ---------
00393 Scalar operator-(const Scalar& t1, int m)       
00394 {
00395     return t1 - double(m) ;
00396 }
00397 
00398 // int - Scalar
00399 // ---------
00400 Scalar operator-(int m, const Scalar& t1)       
00401 {
00402     return double(m) - t1 ;
00403 }
00404 
00405 
00406 
00407 
00408 
00409 
00410             //****************//
00411             // MULTIPLICATION //
00412             //****************//
00413 
00414 // Scalar * Scalar
00415 // ---------
00416 Scalar operator*(const Scalar& c1, const Scalar& c2) {
00417     
00418     
00419     // Cas particuliers
00420     if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)){
00421     return c1 ;
00422     }
00423     if ((c2.get_etat() == ETATZERO)|| (c2.get_etat() == ETATNONDEF)) {
00424     return c2 ;
00425     }
00426     if (c1.get_etat() == ETATUN)
00427     return c2 ;
00428     
00429     if (c2.get_etat() == ETATUN)
00430     return c1 ;
00431     
00432     assert(c1.get_etat() == ETATQCQ) ;  // sinon...
00433     assert(c2.get_etat() == ETATQCQ) ;  // sinon...
00434     
00435     // Protection
00436     assert( c1.get_mp() == c2.get_mp() ) ;
00437     
00438     // Cas general
00439     Scalar r(c1) ;      // Le resultat
00440     r.va *= c2.va ;
00441 
00442     r.set_dzpuis( c1.get_dzpuis() + c2.get_dzpuis() ) ;
00443     
00444     // Termine
00445     return r ;
00446 }
00447 
00448 // Scalar % Scalar (multiplication with desaliasing)
00449 // -------------------------------------------
00450 Scalar operator%(const Scalar& c1, const Scalar& c2) {
00451     
00452     
00453     // Cas particuliers
00454     if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)){
00455     return c1 ;
00456     }
00457     if ((c2.get_etat() == ETATZERO)|| (c2.get_etat() == ETATNONDEF)) {
00458     return c2 ;
00459     }
00460     if (c1.get_etat() == ETATUN)
00461     return c2 ;
00462     if (c2.get_etat() == ETATUN)
00463     return c1 ;
00464 
00465     assert(c1.get_etat() == ETATQCQ) ;  // sinon...
00466     assert(c2.get_etat() == ETATQCQ) ;  // sinon...
00467     
00468     // Protection
00469     assert(c1.get_mp() == c2.get_mp()) ;
00470     
00471     // Cas general
00472     Scalar r( c1.get_mp() ) ;       // Le resultat
00473     r.set_etat_qcq() ;
00474     r.va = c1.va % c2.va ;
00475 
00476     r.set_dzpuis( c1.get_dzpuis() + c2.get_dzpuis() ) ;
00477     
00478     // Termine
00479     return r ;
00480 }
00481 
00482 // Scalar | Scalar (multiplication with desaliasing in r)
00483 // ------------------------------------------------------
00484 Scalar operator|(const Scalar& c1, const Scalar& c2) {
00485     
00486     
00487     // Cas particuliers
00488     if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)){
00489     return c1 ;
00490     }
00491     if ((c2.get_etat() == ETATZERO)|| (c2.get_etat() == ETATNONDEF)) {
00492     return c2 ;
00493     }
00494     if (c1.get_etat() == ETATUN)
00495     return c2 ;
00496     if (c2.get_etat() == ETATUN)
00497     return c1 ;
00498 
00499     assert(c1.get_etat() == ETATQCQ) ;  // sinon...
00500     assert(c2.get_etat() == ETATQCQ) ;  // sinon...
00501     
00502     // Protection
00503     assert(c1.get_mp() == c2.get_mp()) ;
00504     
00505     // Cas general
00506     Scalar r( c1.get_mp() ) ;       // Le resultat
00507     r.set_etat_qcq() ;
00508     r.va = c1.va | c2.va ;
00509 
00510     r.set_dzpuis( c1.get_dzpuis() + c2.get_dzpuis() ) ;
00511     
00512     // Termine
00513     return r ;
00514 }
00515 
00516 
00517 // Mtbl * Scalar
00518 // -------------
00519 
00520 Scalar operator*(const Mtbl& mi, const Scalar& c1) {
00521 
00522     // Particular cases 
00523     if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)) {
00524     return c1 ;
00525     }
00526 
00527     Scalar r(c1.get_mp()) ;
00528     if (c1.get_etat() == ETATUN) {
00529       r = mi ;
00530     }
00531     else {
00532       assert(c1.get_etat() == ETATQCQ) ;  // sinon...
00533       
00534       // Cas general
00535       r.set_dzpuis( c1.get_dzpuis() ) ;
00536       
00537       if ( mi.get_etat() == ETATZERO) {
00538     r.set_etat_zero() ;
00539       }
00540       else {
00541     r.set_etat_qcq() ;
00542     r.va = mi * c1.va ;
00543       }
00544     }
00545 
00546     // Termine
00547     return r ;
00548    
00549 }
00550 
00551 // Scalar * Mtbl
00552 // -------------
00553 
00554 Scalar operator*(const Scalar& c1, const Mtbl& mi) {
00555 
00556     return mi * c1 ; 
00557 }
00558 
00559 // double * Scalar
00560 // ------------
00561 Scalar operator*(double a, const Scalar& c1) {
00562     
00563     // Cas particuliers
00564     if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)) {
00565     return c1 ;
00566     }
00567 
00568     if (a == double(1))
00569       return c1 ;
00570 
00571     Scalar r(c1.get_mp()) ;
00572     if (c1.get_etat() == ETATUN) {
00573       r = a ;
00574       r.set_spectral_base(c1.get_spectral_va().get_base()) ; 
00575     }
00576     else {
00577       assert(c1.get_etat() == ETATQCQ) ;  // sinon...
00578       
00579       // Cas general
00580       r.set_dzpuis( c1.get_dzpuis() ) ;
00581       
00582       if ( a == double(0) ) {
00583     r.set_etat_zero() ;
00584       }
00585       else {
00586     r.set_etat_qcq() ;
00587     r.va = a * c1.va ;
00588       }
00589     }
00590 
00591     // Termine
00592     return r ;
00593 }
00594 
00595 
00596 // Scalar * double
00597 // ------------
00598 Scalar operator*(const Scalar& t1, double x)        
00599 {
00600     return x * t1 ;
00601 }
00602 
00603 // Scalar * int
00604 // ---------
00605 Scalar operator*(const Scalar& t1, int m)       
00606 {
00607     return t1 * double(m) ;
00608 }
00609 
00610 // int * Scalar
00611 // ---------
00612 Scalar operator*(int m, const Scalar& t1)       
00613 {
00614     return double(m) * t1 ;
00615 }
00616 
00617 
00618 
00619 
00620 
00621 
00622 
00623             //**********//
00624             // DIVISION //
00625             //**********//
00626 
00627 
00628 // Scalar / Scalar
00629 // ---------
00630 Scalar operator/(const Scalar& c1, const Scalar& c2) {
00631     
00632     // Protections
00633     assert(c1.get_etat() != ETATNONDEF) ;
00634     assert(c2.get_etat() != ETATNONDEF) ;
00635     assert(c1.get_mp() == c2.get_mp()) ;
00636     
00637     // Cas particuliers
00638     if (c2.get_etat() == ETATZERO) {
00639     cout << "Division by 0 in Scalar / Scalar !" << endl ;
00640     abort() ; 
00641     }
00642     if (c1.get_etat() == ETATZERO) {
00643         return c1 ;
00644     }
00645     if (c1.get_etat() == ETATUN)
00646     return double(1)/c2 ;
00647     if (c2.get_etat() == ETATUN)
00648     return c1 ;
00649 
00650     // Cas general
00651     
00652     assert(c1.get_etat() == ETATQCQ) ;  // sinon...
00653     assert(c2.get_etat() == ETATQCQ) ;  // sinon...
00654 
00655     Scalar r(c1.get_mp()) ;     // Le resultat
00656 
00657     r.set_etat_qcq() ;
00658     r.va = c1.va / c2.va ;
00659     
00660     r.set_dzpuis( c1.get_dzpuis() - c2.get_dzpuis() ) ;
00661 
00662     // Termine
00663     return r ;
00664 }
00665 
00666 // Scalar / Mtbl
00667 // -------------
00668 Scalar operator/(const Scalar& c1, const Mtbl& mi) {
00669   
00670     if (c1.get_etat() == ETATNONDEF) return c1 ;
00671     
00672     // Cas particuliers
00673     if ( mi.get_etat() == ETATZERO ) {
00674     cout << "Division by 0 in Scalar / Mtbl !" << endl ;
00675     abort() ;
00676     }
00677     if (c1.get_etat() == ETATZERO) {
00678     return c1 ;
00679     }
00680     Scalar r(c1.get_mp()) ;     // Le resultat
00681 
00682     if (c1.get_etat() == ETATUN) {
00683     r = double(1) / mi ;
00684     }
00685     else {
00686       assert(c1.get_etat() == ETATQCQ) ;  // sinon...
00687 
00688       r.set_etat_qcq() ;
00689       r.va = c1.va / mi ;
00690 
00691       r.set_dzpuis( c1.get_dzpuis() ) ;
00692     }
00693     // Termine
00694     return r ;
00695 }
00696 
00697 
00698 // Mtbl / Scalar
00699 // -------------
00700 Scalar operator/(const Mtbl& mi, const Scalar& c2) {
00701     
00702     if (c2.get_etat() == ETATNONDEF) 
00703     return c2 ;
00704     
00705     if (c2.get_etat() == ETATZERO) {
00706     cout << "Division by 0 in Mtbl / Scalar !" << endl ;
00707     abort() ; 
00708     }
00709     Scalar r(c2.get_mp()) ;     // Le resultat
00710     if (c2.get_etat() == ETATUN) {
00711       r = mi ;
00712     }
00713     else {
00714       assert(c2.get_etat() == ETATQCQ) ;  // sinon...
00715       
00716       r.set_dzpuis( - c2.get_dzpuis() ) ;
00717       
00718       if ( mi.get_etat() == ETATZERO ) {
00719     r.set_etat_zero() ;
00720       }
00721       else {
00722     r.set_etat_qcq() ;
00723     r.va = mi / c2.va ;
00724       }
00725     }
00726 
00727     // Termine
00728     return r ;
00729 }
00730 
00731 
00732 // Scalar / double
00733 // -------------
00734 Scalar operator/(const Scalar& c1, double x) {
00735     
00736     if (c1.get_etat() == ETATNONDEF) 
00737     return c1 ;
00738     
00739     // Cas particuliers
00740     if ( x == double(0) ) {
00741     cout << "Division by 0 in Scalar / double !" << endl ;
00742     abort() ;
00743     }
00744     if (c1.get_etat() == ETATZERO) {
00745     return c1 ;
00746     }
00747     Scalar r(c1.get_mp()) ;     // Le resultat
00748 
00749     if (c1.get_etat() == ETATUN) {
00750     r = double(1)/x ;
00751         r.set_spectral_base(c1.get_spectral_va().get_base()) ; 
00752     }
00753     else {
00754       assert(c1.get_etat() == ETATQCQ) ;  // sinon...
00755 
00756       r.set_etat_qcq() ;
00757       r.va = c1.va / x ;
00758 
00759       r.set_dzpuis( c1.get_dzpuis() ) ;
00760     }
00761     // Termine
00762     return r ;
00763 }
00764 
00765 
00766 // double / Scalar
00767 // ------------
00768 Scalar operator/(double x, const Scalar& c2) {
00769     
00770     if (c2.get_etat() == ETATNONDEF) 
00771     return c2 ;
00772     
00773     if (c2.get_etat() == ETATZERO) {
00774     cout << "Division by 0 in double / Scalar !" << endl ;
00775     abort() ; 
00776     }
00777     Scalar r(c2.get_mp()) ;     // Le resultat
00778     if (c2.get_etat() == ETATUN) {
00779       r = x ;
00780       r.set_spectral_base(c2.get_spectral_va().get_base()) ; 
00781     }
00782     else {
00783       assert(c2.get_etat() == ETATQCQ) ;  // sinon...
00784       
00785       r.set_dzpuis( - c2.get_dzpuis() ) ;
00786       
00787       if ( x == double(0) ) {
00788     r.set_etat_zero() ;
00789       }
00790       else {
00791     r.set_etat_qcq() ;
00792     r.va = x / c2.va ;
00793       }
00794     }
00795 
00796     // Termine
00797     return r ;
00798 }
00799 
00800 
00801 // Scalar / int
00802 // ---------
00803 Scalar operator/(const Scalar& c1, int m) {
00804     
00805     return c1 / double(m) ; 
00806 
00807 }
00808 
00809 
00810 // int / Scalar
00811 // ---------
00812 Scalar operator/(int m, const Scalar& c2) {
00813 
00814     return double(m) / c2 ;
00815 
00816 }
00817 
00818             //*******************//
00819             // operateurs +=,... //
00820             //*******************//
00821 
00822 //---------
00823 //  += Scalar
00824 //---------
00825 
00826 void Scalar::operator+=(const Scalar & ci) {
00827     
00828     // Protection
00829     assert(mp == &(ci.get_mp()) ) ;     // meme mapping
00830     if (etat == ETATNONDEF) 
00831     return ;
00832  
00833     // Cas particulier
00834     if (ci.get_etat() == ETATZERO) {
00835     return ;
00836     }
00837     
00838     if (ci.get_etat() == ETATNONDEF) {
00839     set_etat_nondef() ;
00840     return ;
00841     }
00842         
00843     // Cas general
00844     
00845 
00846     if ( dz_nonzero() && ci.dz_nonzero() ) {
00847         if ( dzpuis != ci.dzpuis ) {
00848             cout << "Operation += Scalar : dzpuis conflict in the external " << endl;
00849             cout << " compactified domain ! " << endl ; 
00850             abort() ;
00851         }
00852     }
00853     
00854     if (etat == ETATZERO) {
00855         (*this) = ci ;
00856     }
00857     else {
00858         va += ci.va ;
00859         if (etat == ETATUN) {
00860             etat = ETATQCQ ;    // since the case ci.etat == ETATZERO
00861         }                       //  has been treated above                      
00862         
00863         assert(etat == ETATQCQ) ; 
00864     
00865         if( ci.dz_nonzero() ) {
00866             set_dzpuis(ci.dzpuis) ; 
00867         }
00868     }
00869     // Menage (a ne faire qu'a la fin seulement)
00870     del_deriv() ;
00871 
00872     
00873 }
00874 
00875 //---------
00876 //  -= Scalar
00877 //---------
00878 
00879 void Scalar::operator-=(const Scalar & ci) {
00880     
00881     // Protection
00882     assert(mp == &(ci.get_mp()) ) ;     // meme mapping
00883     if (etat == ETATNONDEF) 
00884     return ;
00885  
00886     // Cas particulier
00887     if (ci.get_etat() == ETATZERO) {
00888     return ;
00889     }
00890     
00891     if (ci.get_etat() == ETATNONDEF) {
00892     set_etat_nondef() ;
00893     return ;
00894     }
00895     
00896     // Cas general
00897     if ( dz_nonzero() && ci.dz_nonzero() ) {
00898     if ( dzpuis != ci.dzpuis ) {
00899         cout << "Operation -= Scalar : dzpuis conflict in the external " << endl;
00900         cout << " compactified domain ! " << endl ; 
00901         abort() ;
00902     }
00903     }
00904     
00905 
00906     if (etat == ETATZERO) {
00907         (*this) = -ci ;
00908     }
00909     else {
00910         va -= ci.va ;
00911 
00912         if (etat == ETATUN) {
00913             etat = ETATQCQ ;    // since the case ci.etat == ETATZERO
00914         }                       //  has been treated above                      
00915         
00916         assert(etat == ETATQCQ) ; 
00917 
00918         if( ci.dz_nonzero() ) {
00919             set_dzpuis(ci.dzpuis) ; 
00920         }
00921     }
00922     // Menage (a ne faire qu'a la fin seulement)
00923     del_deriv() ;
00924 }
00925 
00926 //---------
00927 //  *= Scalar
00928 //---------
00929 
00930 void Scalar::operator*=(const Scalar & ci) {
00931     
00932     // Protection
00933     assert(mp == &(ci.get_mp()) ) ;     // meme mapping
00934     if (etat == ETATNONDEF) 
00935     return ;
00936  
00937     // Cas particulier
00938     if (ci.get_etat() == ETATZERO) {
00939     set_etat_zero() ;
00940     return ;
00941     }
00942     
00943     if (etat == ETATZERO) {
00944     return ; 
00945     }
00946     
00947     if (ci.get_etat() == ETATUN) {
00948     return ;
00949     }
00950     
00951     if (etat == ETATUN) {
00952         operator=(ci) ; 
00953         return ; 
00954     }
00955     
00956     if (ci.get_etat() == ETATNONDEF) {
00957     set_etat_nondef() ;
00958     return ;
00959     }
00960         
00961     // Cas general
00962     
00963     assert(etat == ETATQCQ) ; // sinon....
00964     
00965     va *= ci.va ;
00966  
00967     dzpuis += ci.dzpuis ;    
00968 
00969     // Menage (a ne faire qu'a la fin seulement)
00970     del_deriv() ;
00971 
00972 }

Generated on Tue Feb 7 01:35:19 2012 for LORENE by  doxygen 1.4.6