00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 char cmp_arithm_C[] = "$Header: /cvsroot/Lorene/C++/Source/Cmp/cmp_arithm.C,v 1.3 2003/06/20 13:59:59 f_limousin Exp $" ;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 #include <assert.h>
00087 #include <stdlib.h>
00088
00089
00090 #include "cmp.h"
00091 #include "type_parite.h"
00092
00093
00094
00095
00096
00097 Cmp operator+(const Cmp & ci) {
00098 return ci ;
00099 }
00100
00101 Cmp operator-(const Cmp & ci) {
00102
00103
00104 if ((ci.get_etat() == ETATZERO) || (ci.get_etat() == ETATNONDEF)) {
00105 return ci ;
00106 }
00107
00108
00109 assert(ci.get_etat() == ETATQCQ) ;
00110 Cmp r(ci.get_mp()) ;
00111 r.set_etat_qcq() ;
00112 r.va = - ci.va ;
00113 r.set_dzpuis( ci.get_dzpuis() ) ;
00114
00115
00116 return r ;
00117 }
00118
00119
00120
00121
00122
00123
00124 Cmp operator+(const Cmp & c1, const Cmp & c2) {
00125
00126 if (c1.get_etat() == ETATNONDEF)
00127 return c1 ;
00128 if (c2.get_etat() == ETATNONDEF)
00129 return c2 ;
00130 assert(c1.get_mp() == c2.get_mp()) ;
00131
00132
00133 if (c1.get_etat() == ETATZERO) {
00134 return c2 ;
00135 }
00136 if (c2.get_etat() == ETATZERO) {
00137 return c1 ;
00138 }
00139 assert(c1.get_etat() == ETATQCQ) ;
00140 assert(c2.get_etat() == ETATQCQ) ;
00141
00142
00143
00144 if ( c1.dz_nonzero() && c2.dz_nonzero() ) {
00145 if ( c1.get_dzpuis() != c2.get_dzpuis() ) {
00146 cout << "Operation Cmp + Cmp forbidden in the external " << endl;
00147 cout << " compactified domain ! " << endl ;
00148 abort() ;
00149 }
00150 }
00151
00152 Cmp r(c1) ;
00153 r.va += c2.va ;
00154
00155 if (c1.dz_nonzero()) {
00156 r.set_dzpuis( c1.get_dzpuis() ) ;
00157 }
00158 else{
00159 r.set_dzpuis( c2.get_dzpuis() ) ;
00160 }
00161
00162
00163 return r ;
00164 }
00165
00166
00167
00168 Cmp operator+(const Cmp& t1, double x)
00169 {
00170
00171 assert(t1.get_etat() != ETATNONDEF) ;
00172
00173
00174 if (x == double(0)) {
00175 return t1 ;
00176 }
00177
00178 assert( t1.check_dzpuis(0) ) ;
00179
00180 Cmp resu(t1) ;
00181
00182 if (t1.get_etat() == ETATZERO) {
00183 resu = x ;
00184 }
00185 else{
00186 assert(resu.get_etat() == ETATQCQ) ;
00187 resu.va = resu.va + x ;
00188 }
00189
00190 resu.set_dzpuis(0) ;
00191
00192 return resu ;
00193 }
00194
00195
00196
00197 Cmp operator+(double x, const Cmp& t1)
00198 {
00199 return t1 + x ;
00200 }
00201
00202
00203
00204 Cmp operator+(const Cmp& t1, int m)
00205 {
00206 return t1 + double(m) ;
00207 }
00208
00209
00210
00211 Cmp operator+(int m, const Cmp& t1)
00212 {
00213 return t1 + double(m) ;
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 Cmp operator-(const Cmp & c1, const Cmp & c2) {
00227
00228 if (c1.get_etat() == ETATNONDEF)
00229 return c1 ;
00230 if (c2.get_etat() == ETATNONDEF)
00231 return c2 ;
00232
00233 assert(c1.get_mp() == c2.get_mp()) ;
00234
00235
00236 if (c1.get_etat() == ETATZERO) {
00237 return -c2 ;
00238 }
00239 if (c2.get_etat() == ETATZERO) {
00240 return c1 ;
00241 }
00242 assert(c1.get_etat() == ETATQCQ) ;
00243 assert(c2.get_etat() == ETATQCQ) ;
00244
00245
00246 if ( c1.dz_nonzero() && c2.dz_nonzero() ) {
00247 if ( c1.get_dzpuis() != c2.get_dzpuis() ) {
00248 cout << "Operation Cmp - Cmp forbidden in the external " << endl;
00249 cout << " compactified domain ! " << endl ;
00250 abort() ;
00251 }
00252 }
00253
00254 Cmp r(c1) ;
00255 r.va -= c2.va ;
00256
00257 if (c1.dz_nonzero()) {
00258 r.set_dzpuis( c1.get_dzpuis() ) ;
00259 }
00260 else{
00261 r.set_dzpuis( c2.get_dzpuis() ) ;
00262 }
00263
00264
00265 return r ;
00266 }
00267
00268
00269
00270 Cmp operator-(const Cmp& t1, double x)
00271 {
00272
00273 assert(t1.get_etat() != ETATNONDEF) ;
00274
00275
00276 if (x == double(0)) {
00277 return t1 ;
00278 }
00279
00280 assert( t1.check_dzpuis(0) ) ;
00281
00282 Cmp resu(t1) ;
00283
00284 if (t1.get_etat() == ETATZERO) {
00285 resu = - x ;
00286 }
00287 else{
00288 assert(resu.get_etat() == ETATQCQ) ;
00289 resu.va = resu.va - x ;
00290 }
00291
00292 resu.set_dzpuis(0) ;
00293
00294 return resu ;
00295 }
00296
00297
00298
00299 Cmp operator-(double x, const Cmp& t1)
00300 {
00301 return - (t1 - x) ;
00302 }
00303
00304
00305
00306 Cmp operator-(const Cmp& t1, int m)
00307 {
00308 return t1 - double(m) ;
00309 }
00310
00311
00312
00313 Cmp operator-(int m, const Cmp& t1)
00314 {
00315 return double(m) - t1 ;
00316 }
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 Cmp operator*(const Cmp& c1, const Cmp& c2) {
00330
00331
00332
00333 if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)){
00334 return c1 ;
00335 }
00336 if ((c2.get_etat() == ETATZERO)|| (c2.get_etat() == ETATNONDEF)) {
00337 return c2 ;
00338 }
00339 assert(c1.get_etat() == ETATQCQ) ;
00340 assert(c2.get_etat() == ETATQCQ) ;
00341
00342
00343 assert(*(c1.get_mp()) == *(c2.get_mp())) ;
00344
00345
00346 Cmp r(c1) ;
00347 r.va *= c2.va ;
00348
00349 r.set_dzpuis( c1.get_dzpuis() + c2.get_dzpuis() ) ;
00350
00351
00352 return r ;
00353 }
00354
00355
00356
00357 Cmp operator%(const Cmp& c1, const Cmp& c2) {
00358
00359
00360
00361 if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)){
00362 return c1 ;
00363 }
00364 if ((c2.get_etat() == ETATZERO)|| (c2.get_etat() == ETATNONDEF)) {
00365 return c2 ;
00366 }
00367 assert(c1.get_etat() == ETATQCQ) ;
00368 assert(c2.get_etat() == ETATQCQ) ;
00369
00370
00371 assert(c1.get_mp() == c2.get_mp()) ;
00372
00373
00374 Cmp r( c1.get_mp() ) ;
00375 r.set_etat_qcq() ;
00376 r.va = c1.va % c2.va ;
00377
00378 r.set_dzpuis( c1.get_dzpuis() + c2.get_dzpuis() ) ;
00379
00380
00381 return r ;
00382 }
00383
00384
00385
00386
00387
00388
00389 Cmp operator*(double a, const Cmp& c1) {
00390
00391
00392 if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)) {
00393 return c1 ;
00394 }
00395
00396 assert(c1.get_etat() == ETATQCQ) ;
00397
00398
00399 Cmp r(c1.get_mp()) ;
00400 r.set_dzpuis( c1.get_dzpuis() ) ;
00401
00402 if ( a == double(0) ) {
00403 r.set_etat_zero() ;
00404 }
00405 else {
00406 r.set_etat_qcq() ;
00407 r.va = a * c1.va ;
00408 }
00409
00410
00411
00412 return r ;
00413 }
00414
00415
00416
00417
00418 Cmp operator*(const Cmp& t1, double x)
00419 {
00420 return x * t1 ;
00421 }
00422
00423
00424
00425 Cmp operator*(const Cmp& t1, int m)
00426 {
00427 return t1 * double(m) ;
00428 }
00429
00430
00431
00432 Cmp operator*(int m, const Cmp& t1)
00433 {
00434 return double(m) * t1 ;
00435 }
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450 Cmp operator/(const Cmp& c1, const Cmp& c2) {
00451
00452
00453 assert(c1.get_etat() != ETATNONDEF) ;
00454 assert(c2.get_etat() != ETATNONDEF) ;
00455 assert(c1.get_mp() == c2.get_mp()) ;
00456
00457
00458 if (c2.get_etat() == ETATZERO) {
00459 cout << "Division by 0 in Cmp / Cmp !" << endl ;
00460 abort() ;
00461 }
00462 if (c1.get_etat() == ETATZERO) {
00463 return c1 ;
00464 }
00465
00466
00467
00468 assert(c1.get_etat() == ETATQCQ) ;
00469 assert(c2.get_etat() == ETATQCQ) ;
00470
00471 Cmp r(c1.get_mp()) ;
00472
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
00479 return r ;
00480 }
00481
00482
00483
00484 Cmp operator/(const Cmp& c1, double x) {
00485
00486 if (c1.get_etat() == ETATNONDEF)
00487 return c1 ;
00488
00489
00490 if ( x == double(0) ) {
00491 cout << "Division by 0 in Cmp / double !" << endl ;
00492 abort() ;
00493 }
00494 if (c1.get_etat() == ETATZERO) {
00495 return c1 ;
00496 }
00497
00498 assert(c1.get_etat() == ETATQCQ) ;
00499
00500 Cmp r(c1.get_mp()) ;
00501
00502 r.set_etat_qcq() ;
00503 r.va = c1.va / x ;
00504
00505 r.set_dzpuis( c1.get_dzpuis() ) ;
00506
00507
00508 return r ;
00509 }
00510
00511
00512
00513
00514 Cmp operator/(double x, const Cmp& c2) {
00515
00516 if (c2.get_etat() == ETATNONDEF)
00517 return c2 ;
00518
00519 if (c2.get_etat() == ETATZERO) {
00520 cout << "Division by 0 in Cmp / Cmp !" << endl ;
00521 abort() ;
00522 }
00523
00524
00525 assert(c2.get_etat() == ETATQCQ) ;
00526
00527 Cmp r(c2.get_mp()) ;
00528 r.set_dzpuis( - c2.get_dzpuis() ) ;
00529
00530 if ( x == double(0) ) {
00531 r.set_etat_zero() ;
00532 }
00533 else {
00534 r.set_etat_qcq() ;
00535 r.va = x / c2.va ;
00536 }
00537
00538
00539 return r ;
00540 }
00541
00542
00543
00544
00545 Cmp operator/(const Cmp& c1, int m) {
00546
00547 return c1 / double(m) ;
00548
00549 }
00550
00551
00552
00553
00554 Cmp operator/(int m, const Cmp& c2) {
00555
00556 return double(m) / c2 ;
00557
00558 }
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568 void Cmp::operator+=(const Cmp & ci) {
00569
00570
00571 assert(mp == ci.get_mp()) ;
00572 if (etat == ETATNONDEF)
00573 return ;
00574
00575
00576 if (ci.get_etat() == ETATZERO) {
00577 return ;
00578 }
00579
00580 if (ci.get_etat() == ETATNONDEF) {
00581 set_etat_nondef() ;
00582 return ;
00583 }
00584
00585
00586
00587
00588 if ( dz_nonzero() && ci.dz_nonzero() ) {
00589 if ( dzpuis != ci.dzpuis ) {
00590 cout << "Operation += Cmp forbidden in the external " << endl;
00591 cout << " compactified domain ! " << endl ;
00592 abort() ;
00593 }
00594 }
00595
00596 if (etat == ETATZERO) {
00597 (*this) = ci ;
00598 }
00599 else {
00600 va += ci.va ;
00601
00602 if( ci.dz_nonzero() ) {
00603 set_dzpuis(ci.dzpuis) ;
00604 }
00605 }
00606
00607 del_deriv() ;
00608
00609
00610 }
00611
00612
00613
00614
00615
00616 void Cmp::operator-=(const Cmp & ci) {
00617
00618
00619 assert(mp == ci.get_mp()) ;
00620 if (etat == ETATNONDEF)
00621 return ;
00622
00623
00624 if (ci.get_etat() == ETATZERO) {
00625 return ;
00626 }
00627
00628 if (ci.get_etat() == ETATNONDEF) {
00629 set_etat_nondef() ;
00630 return ;
00631 }
00632
00633
00634 if ( dz_nonzero() && ci.dz_nonzero() ) {
00635 if ( dzpuis != ci.dzpuis ) {
00636 cout << "Operation -= Cmp forbidden in the external " << endl;
00637 cout << " compactified domain ! " << endl ;
00638 abort() ;
00639 }
00640 }
00641
00642
00643 if (etat == ETATZERO) {
00644 (*this) = -ci ;
00645 }
00646 else {
00647 va -= ci.va ;
00648
00649 if( ci.dz_nonzero() ) {
00650 set_dzpuis(ci.dzpuis) ;
00651 }
00652 }
00653
00654 del_deriv() ;
00655 }
00656
00657
00658
00659
00660
00661 void Cmp::operator*=(const Cmp & ci) {
00662
00663
00664 assert(mp == ci.get_mp()) ;
00665 if (etat == ETATNONDEF)
00666 return ;
00667
00668
00669 if (ci.get_etat() == ETATZERO) {
00670 set_etat_zero() ;
00671 return ;
00672 }
00673
00674 if (etat == ETATZERO) {
00675 return ;
00676 }
00677
00678 if (ci.get_etat() == ETATNONDEF) {
00679 set_etat_nondef() ;
00680 return ;
00681 }
00682
00683
00684
00685 assert(etat == ETATQCQ) ;
00686
00687 va *= ci.va ;
00688
00689 dzpuis += ci.dzpuis ;
00690
00691
00692 del_deriv() ;
00693
00694 }