Changeset 246d15 in git
- Timestamp:
- Feb 14, 2011, 4:50:05 PM (13 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- c880c179f5777247d29dc13017c11fc651c7c366
- Parents:
- 6185cc201360857550a263f9769d0c21aca8d208
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/longrat.cc
r6185cc r246d15 7 7 */ 8 8 9 #include <kernel/mod2.h> 10 #include <kernel/structs.h> 11 #include <kernel/longrat.h> 12 13 // 64 bit version: 14 #if 0 15 #define MAX_NUM_SIZE 60 16 #define POW_2_28 0x10000000000000L 17 #define LONG long 18 #else 19 #define MAX_NUM_SIZE 28 20 #define POW_2_28 (1L<<28) 21 #define LONG int 22 #endif 23 24 static inline number nlShort3(number x) // assume x->s==3 25 { 26 assume(x->s==3); 27 if ((mpz_cmp_ui(x->z,(long)0)==0) 28 || (mpz_size1(x->z)<=MP_SMALL)) 29 { 30 LONG ui=mpz_get_si(x->z); 31 if ((((ui<<3)>>3)==ui) 32 && (mpz_cmp_si(x->z,(long)ui)==0)) 33 { 34 mpz_clear(x->z); 35 omFreeBin((ADDRESS)x, rnumber_bin); 36 return INT_TO_SR(ui); 37 } 38 } 39 return x; 40 } 41 9 42 #ifndef LONGRAT_CC 10 43 #define LONGRAT_CC … … 12 45 #include <string.h> 13 46 #include <float.h> 14 #include <kernel/mod2.h>15 #include <kernel/structs.h>16 47 #include <omalloc/omalloc.h> 17 48 #include <kernel/febase.h> … … 21 52 #include <kernel/shortfl.h> 22 53 #include <kernel/mpr_complex.h> 23 #include <kernel/longrat.h>24 54 25 55 … … 85 115 #ifndef P_NUMBERS_H 86 116 117 number nlShort3_noinline(number x) // assume x->s==3 118 { 119 return nlShort3(x); 120 } 121 87 122 omBin rnumber_bin = omGetSpecBin(sizeof(snumber)); 88 123 … … 126 161 //mpz_init_set_ui(&z->n,1); 127 162 z->s = 3; 128 if ((mpz_cmp_ui(z->z,(long)0)==0) 129 || (mpz_size1(z->z)<=MP_SMALL)) 130 { 131 int ui=(int)mpz_get_si(z->z); 132 if ((((ui<<3)>>3)==ui) 133 && (mpz_cmp_si(z->z,(long)ui)==0)) 134 { 135 mpz_clear(z->z); 136 omFreeBin((ADDRESS)z, rnumber_bin); 137 return INT_TO_SR(ui); 138 } 139 } 163 z=nlShort3(z); 140 164 return z; 141 165 } … … 152 176 mpz_init_set_ui(z->z,(unsigned long) from); 153 177 z->s = 3; 154 if ((mpz_cmp_ui(z->z,(long)0)==0) 155 || (mpz_size1(z->z)<=MP_SMALL)) 156 { 157 int ui=(int)mpz_get_si(z->z); 158 if ((((ui<<3)>>3)==ui) 159 && (mpz_cmp_si(z->z,(long)ui)==0)) 160 { 161 mpz_clear(z->z); 162 omFreeBin((ADDRESS)z, rnumber_bin); 163 return INT_TO_SR(ui); 164 } 165 } 178 z=nlShort3(z); 166 179 return z; 167 180 } … … 216 229 if ((((long)a)&3L)==1L) 217 230 { 218 if ((((( long)a)<<1)>>1)!=((long)a))231 if (((((LONG)(long)a)<<1)>>1)!=((LONG)(long)a)) 219 232 { 220 233 Print(" !!longrat:arith:%lx in %s:%d\n",(long)a, f,l); … … 264 277 //} 265 278 if (mpz_size1(a->z)>MP_SMALL) return TRUE; 266 intui=(int)mpz_get_si(a->z);279 LONG ui=(int)mpz_get_si(a->z); 267 280 if ((((ui<<3)>>3)==ui) 268 281 && (mpz_cmp_si(a->z,(long)ui)==0)) … … 276 289 #endif 277 290 278 number nlRInit ( inti);291 number nlRInit (long i); 279 292 280 293 static number nlMapR(number from) … … 372 385 if (res->s==0) 373 386 nlNormalize(res); 374 else if (mpz_size1(res->z)<=MP_SMALL)387 else 375 388 { 376 389 // res is new, res->ref is 1 377 int ui=(int)mpz_get_si(res->z); 378 if ((((ui<<3)>>3)==ui) 379 && (mpz_cmp_si(res->z,(long)ui)==0)) 380 { 381 mpz_clear(res->z); 382 #if defined(LDEBUG) 383 res->debug=654324; 384 #endif 385 omFreeBin((ADDRESS)res, rnumber_bin); 386 return INT_TO_SR(ui); 387 } 388 } 389 #if defined(LDEBUG) 390 res=nlShort3(res); 391 } 390 392 nlTest(res); 391 #endif392 393 return res; 393 394 } … … 489 490 int nlInt(number &i, const ring r) 490 491 { 491 #ifdef LDEBUG492 492 nlTest(i); 493 #endif494 493 nlNormalize(i); 495 494 if (SR_HDL(i) &SR_INT) return SR_TO_INT(i); … … 520 519 number nlBigInt(number &i) 521 520 { 522 #ifdef LDEBUG523 521 nlTest(i); 524 #endif525 522 nlNormalize(i); 526 523 if (SR_HDL(i) &SR_INT) return (i); … … 531 528 number tmp=nlRInit(1); 532 529 MPZ_DIV(tmp->z,i->z,i->n); 533 if (mpz_size1(tmp->z)<=MP_SMALL) 534 { 535 int ui=mpz_get_si(tmp->z); 536 if ((((ui<<3)>>3)==ui) 537 && (mpz_cmp_si(tmp->z,(long)ui)==0)) 538 { 539 mpz_clear(tmp->z); 540 #if defined(LDEBUG) 541 tmp->debug=654324; 542 #endif 543 omFreeBin((ADDRESS)tmp, rnumber_bin); 544 return INT_TO_SR(ui); 545 } 546 } 530 tmp=nlShort3(tmp); 547 531 return tmp; 548 532 } … … 553 537 number nlInvers(number a) 554 538 { 555 #ifdef LDEBUG556 539 nlTest(a); 557 #endif558 540 number n; 559 541 if (SR_HDL(a) & SR_INT) 560 542 { 561 if ((a==INT_TO_SR(1 )) || (a==INT_TO_SR(-1)))543 if ((a==INT_TO_SR(1L)) || (a==INT_TO_SR(-1L))) 562 544 { 563 545 return a; … … 583 565 mpz_init_set_si(n->n,(long)-SR_TO_INT(a)); 584 566 } 585 #ifdef LDEBUG586 567 nlTest(n); 587 #endif588 568 return n; 589 569 } … … 609 589 mpz_clear(n->n); 610 590 n->s=3; 611 if (mpz_size1(n->z)<=MP_SMALL) 612 { 613 int ui=(int)mpz_get_si(n->z); 614 if ((((ui<<3)>>3)==ui) 615 && (mpz_cmp_si(n->z,(long)ui)==0)) 616 { 617 mpz_clear(n->z); 618 #if defined(LDEBUG) 619 n->debug=654324; 620 #endif 621 omFreeBin((ADDRESS)n, rnumber_bin); 622 n=INT_TO_SR(ui); 623 } 624 } 591 n=nlShort3(n); 625 592 } 626 593 break; … … 639 606 } 640 607 } 641 #ifdef LDEBUG642 608 nlTest(n); 643 #endif644 609 return n; 645 610 } … … 662 627 { 663 628 /* the small int -(1<<28) divided by -1 is the large int (1<<28) */ 664 if ((a==INT_TO_SR(-( 1<<28)))&&(b==INT_TO_SR(-1)))665 { 666 return nlRInit( 1<<28);667 } 668 intaa=SR_TO_INT(a);669 intbb=SR_TO_INT(b);629 if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L))) 630 { 631 return nlRInit(POW_2_28); 632 } 633 long aa=SR_TO_INT(a); 634 long bb=SR_TO_INT(b); 670 635 return INT_TO_SR(aa/bb); 671 636 } … … 692 657 omFreeBin((ADDRESS)bb, rnumber_bin); 693 658 } 694 if (mpz_size1(u->z)<=MP_SMALL) 695 { 696 int ui=(int)mpz_get_si(u->z); 697 if ((((ui<<3)>>3)==ui) 698 && (mpz_cmp_si(u->z,(long)ui)==0)) 699 { 700 mpz_clear(u->z); 701 #if defined(LDEBUG) 702 u->debug=654324; 703 #endif 704 omFreeBin((ADDRESS)u, rnumber_bin); 705 u=INT_TO_SR(ui); 706 } 707 } 708 #ifdef LDEBUG 659 u=nlShort3(u); 709 660 nlTest(u); 710 #endif711 661 return u; 712 662 } … … 728 678 { 729 679 /* the small int -(1<<28) divided by -1 is the large int (1<<28) */ 730 if ((a==INT_TO_SR(-( 1<<28)))&&(b==INT_TO_SR(-1)))731 { 732 return nlRInit( 1<<28);733 } 734 intaa=SR_TO_INT(a);735 intbb=SR_TO_INT(b);680 if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L))) 681 { 682 return nlRInit(POW_2_28); 683 } 684 long aa=SR_TO_INT(a); 685 long bb=SR_TO_INT(b); 736 686 return INT_TO_SR(aa/bb); 737 687 } … … 739 689 { 740 690 /* the small int -(1<<28) divided by 2^28 is 1 */ 741 if (a==INT_TO_SR(-( 1<<28)))742 { 743 if(mpz_cmp_si(b->z,( long)(1<<28))==0)691 if (a==INT_TO_SR(-(POW_2_28))) 692 { 693 if(mpz_cmp_si(b->z,(POW_2_28))==0) 744 694 { 745 695 return INT_TO_SR(-1); … … 773 723 omFreeBin((ADDRESS)bb, rnumber_bin); 774 724 } 775 if (mpz_size1(u->z)<=MP_SMALL) 776 { 777 int ui=(int)mpz_get_si(u->z); 778 if ((((ui<<3)>>3)==ui) 779 && (mpz_cmp_si(u->z,(long)ui)==0)) 780 { 781 mpz_clear(u->z); 782 #if defined(LDEBUG) 783 u->debug=654324; 784 #endif 785 omFreeBin((ADDRESS)u, rnumber_bin); 786 u=INT_TO_SR(ui); 787 } 788 } 789 #ifdef LDEBUG 725 u=nlShort3(u); 790 726 nlTest(u); 791 #endif792 727 return u; 793 728 } … … 819 754 if ((long)b>0L) 820 755 { 821 inti=(-SR_TO_INT(a))%SR_TO_INT(b);822 if ( i != 0 ) i = (SR_TO_INT(b))-i;756 long i=(-SR_TO_INT(a))%SR_TO_INT(b); 757 if ( i != 0L ) i = (SR_TO_INT(b))-i; 823 758 return INT_TO_SR(i); 824 759 } 825 760 else 826 761 { 827 inti=(-SR_TO_INT(a))%(-SR_TO_INT(b));828 if ( i != 0 ) i = (-SR_TO_INT(b))-i;762 long i=(-SR_TO_INT(a))%(-SR_TO_INT(b)); 763 if ( i != 0L ) i = (-SR_TO_INT(b))-i; 829 764 return INT_TO_SR(i); 830 765 } … … 872 807 mpz_add(u->z,u->z,b->z); 873 808 } 874 if (mpz_size1(u->z)<=MP_SMALL) 875 { 876 int ui=(int)mpz_get_si(u->z); 877 if ((((ui<<3)>>3)==ui) 878 && (mpz_cmp_si(u->z,(long)ui)==0)) 879 { 880 mpz_clear(u->z); 881 #if defined(LDEBUG) 882 u->debug=654324; 883 #endif 884 omFreeBin((ADDRESS)u, rnumber_bin); 885 u=INT_TO_SR(ui); 886 } 887 } 888 #ifdef LDEBUG 809 u=nlShort3(u); 889 810 nlTest(u); 890 #endif891 811 return u; 892 812 } … … 911 831 if (SR_HDL(a) & SR_HDL(b) & SR_INT) 912 832 { 913 inti=SR_TO_INT(a);914 intj=SR_TO_INT(b);915 intr=i%j;833 long i=SR_TO_INT(a); 834 long j=SR_TO_INT(b); 835 long r=i%j; 916 836 if (r==0) 917 837 { … … 986 906 { 987 907 mpz_clear(u->n); 988 if (mpz_size1(u->z)<=MP_SMALL)989 {990 int ui=(int)mpz_get_si(u->z);991 if ((((ui<<3)>>3)==ui)992 && (mpz_cmp_si(u->z,(long)ui)==0))993 {994 mpz_clear(u->z);995 omFreeBin((ADDRESS)u, rnumber_bin);996 return INT_TO_SR(ui);997 }998 }999 908 u->s=3; 1000 }1001 #ifdef LDEBUG 909 u=nlShort3(u); 910 } 1002 911 nlTest(u); 1003 #endif1004 912 return u; 1005 913 } … … 1013 921 if (!nlIsZero(x)) 1014 922 { 1015 #ifdef LDEBUG1016 923 nlTest(x); 1017 #endif1018 924 number aa=NULL; 1019 925 if (SR_HDL(x) & SR_INT) … … 1044 950 } 1045 951 (*u)->s = x->s; 1046 if (((*u)->s==3) && (mpz_size1((*u)->z)<=MP_SMALL)) 1047 { 1048 int ui=(int)mpz_get_si((*u)->z); 1049 if ((((ui<<3)>>3)==ui) 1050 && (mpz_cmp_si((*u)->z,(long)ui)==0)) 1051 { 1052 mpz_clear((*u)->z); 1053 omFreeBin((ADDRESS)*u, rnumber_bin); 1054 *u=INT_TO_SR(ui); 1055 } 1056 } 952 if ((*u)->s==3) *u=nlShort3(*u); 1057 953 if (aa!=NULL) 1058 954 { … … 1075 971 BOOLEAN nlGreaterZero (number a) 1076 972 { 1077 #ifdef LDEBUG1078 973 nlTest(a); 1079 #endif 1080 if (SR_HDL(a) & SR_INT) return SR_HDL(a)>1 /* represents number(0) */; 974 if (SR_HDL(a) & SR_INT) return SR_HDL(a)>1L /* represents number(0) */; 1081 975 return (!mpz_isNeg(a->z)); 1082 976 } … … 1087 981 BOOLEAN nlGreater (number a, number b) 1088 982 { 1089 #ifdef LDEBUG1090 983 nlTest(a); 1091 984 nlTest(b); 1092 #endif1093 985 number r; 1094 986 BOOLEAN rr; … … 1108 1000 nlTest(a); 1109 1001 #endif 1110 //if (SR_HDL(a) & SR_INT) return (a==INT_TO_SR(-1 ));1002 //if (SR_HDL(a) & SR_INT) return (a==INT_TO_SR(-1L)); 1111 1003 //return FALSE; 1112 return (a==INT_TO_SR(-1 ));1004 return (a==INT_TO_SR(-1L)); 1113 1005 } 1114 1006 … … 1119 1011 { 1120 1012 number result; 1121 #ifdef LDEBUG1122 1013 nlTest(a); 1123 1014 nlTest(b); 1124 #endif1125 1015 //nlNormalize(a); 1126 1016 //nlNormalize(b); 1127 if ((a==INT_TO_SR(1 ))||(a==INT_TO_SR(-1))1128 || (b==INT_TO_SR(1 ))||(b==INT_TO_SR(-1)))1129 return INT_TO_SR(1 );1017 if ((a==INT_TO_SR(1L))||(a==INT_TO_SR(-1L)) 1018 || (b==INT_TO_SR(1L))||(b==INT_TO_SR(-1L))) 1019 return INT_TO_SR(1L); 1130 1020 if (a==INT_TO_SR(0)) /* gcd(0,b) ->b */ 1131 1021 return nlCopy(b); … … 1134 1024 if (SR_HDL(a) & SR_HDL(b) & SR_INT) 1135 1025 { 1136 inti=SR_TO_INT(a);1137 intj=SR_TO_INT(b);1138 if((i==0 )||(j==0))1026 long i=SR_TO_INT(a); 1027 long j=SR_TO_INT(b); 1028 if((i==0L)||(j==0L)) 1139 1029 return INT_TO_SR(1); 1140 intl;1030 long l; 1141 1031 i=ABS(i); 1142 1032 j=ABS(j); … … 1146 1036 i=j; 1147 1037 j=l; 1148 } while (l!=0 );1038 } while (l!=0L); 1149 1039 return INT_TO_SR(i); 1150 1040 } … … 1154 1044 { 1155 1045 unsigned long t=mpz_gcd_ui(NULL,b->z,ABS(SR_TO_INT(a))); 1156 return INT_TO_SR( (int)t);1046 return INT_TO_SR(t); 1157 1047 } 1158 1048 else … … 1160 1050 { 1161 1051 unsigned long t=mpz_gcd_ui(NULL,a->z,ABS(SR_TO_INT(b))); 1162 return INT_TO_SR( (int)t);1052 return INT_TO_SR(t); 1163 1053 } 1164 1054 else … … 1167 1057 mpz_init(result->z); 1168 1058 mpz_gcd(result->z,a->z,b->z); 1169 if (mpz_size1(result->z)<=MP_SMALL)1170 {1171 int ui=(int)mpz_get_si(result->z);1172 if ((((ui<<3)>>3)==ui)1173 && (mpz_cmp_si(result->z,(long)ui)==0))1174 {1175 mpz_clear(result->z);1176 omFreeBin((ADDRESS)result, rnumber_bin);1177 return INT_TO_SR(ui);1178 }1179 }1180 1059 result->s = 3; 1181 1060 #ifdef LDEBUG 1182 1061 result->debug=123456; 1183 nlTest(result);1184 1062 #endif 1185 } 1063 result=nlShort3(result); 1064 } 1065 nlTest(result); 1186 1066 return result; 1187 1067 } … … 1201 1081 _nlDelete_NoImm(&x); 1202 1082 return INT_TO_SR(1); 1203 }1204 }1205 return x;1206 }1207 number nlShort3(number x) // assume x->s==31208 {1209 assume(x->s==3);1210 if ((mpz_cmp_ui(x->z,(long)0)==0)1211 || (mpz_size1(x->z)<=MP_SMALL))1212 {1213 int ui=(int)mpz_get_si(x->z);1214 if ((((ui<<3)>>3)==ui)1215 && (mpz_cmp_si(x->z,(long)ui)==0))1216 {1217 mpz_clear(x->z);1218 omFreeBin((ADDRESS)x, rnumber_bin);1219 return INT_TO_SR(ui);1220 1083 } 1221 1084 } … … 1238 1101 if (x->s==3) 1239 1102 { 1240 x=nlShort3 (x);1103 x=nlShort3_noinline(x); 1241 1104 return; 1242 1105 } … … 1246 1109 { 1247 1110 mpz_clear(x->n); 1248 if (mpz_size1(x->z)<=MP_SMALL)1249 {1250 int ui=(int)mpz_get_si(x->z);1251 if ((((ui<<3)>>3)==ui)1252 && (mpz_cmp_si(x->z,(long)ui)==0))1253 {1254 mpz_clear(x->z);1255 #if defined(LDEBUG)1256 x->debug=654324;1257 #endif1258 omFreeBin((ADDRESS)x, rnumber_bin);1259 x=INT_TO_SR(ui);1260 return;1261 }1262 }1263 1111 x->s=3; 1112 x=nlShort3(x); 1264 1113 } 1265 1114 else … … 1281 1130 { 1282 1131 mpz_clear(x->n); 1283 if (mpz_size1(x->z)<=MP_SMALL)1284 {1285 int ui=(int)mpz_get_si(x->z);1286 if ((((ui<<3)>>3)==ui)1287 && (mpz_cmp_si(x->z,(long)ui)==0))1288 {1289 mpz_clear(x->z);1290 mpz_clear(gcd);1291 #if defined(LDEBUG)1292 x->debug=654324;1293 #endif1294 omFreeBin((ADDRESS)x, rnumber_bin);1295 x=INT_TO_SR(ui);1296 return;1297 }1298 }1299 1132 x->s=3; 1133 x=nlShort3_noinline(x); 1300 1134 } 1301 1135 } … … 1303 1137 } 1304 1138 } 1305 #ifdef LDEBUG1306 1139 nlTest(x); 1307 #endif1308 1140 } 1309 1141 … … 1314 1146 { 1315 1147 number result; 1316 #ifdef LDEBUG1317 1148 nlTest(a); 1318 1149 nlTest(b); 1319 #endif1320 1150 if ((SR_HDL(b) & SR_INT) 1321 1151 || (b->s==3)) … … 1353 1183 mpz_mul(result->z,b->n,a->z); 1354 1184 mpz_clear(gcd); 1355 if (mpz_size1(result->z)<=MP_SMALL) 1356 { 1357 int ui=(int)mpz_get_si(result->z); 1358 if ((((ui<<3)>>3)==ui) 1359 && (mpz_cmp_si(result->z,(long)ui)==0)) 1360 { 1361 mpz_clear(result->z); 1362 omFreeBin((ADDRESS)result, rnumber_bin); 1363 return INT_TO_SR(ui); 1364 } 1365 } 1366 #ifdef LDEBUG 1185 result=nlShort3(result); 1367 1186 nlTest(result); 1368 #endif1369 1187 return result; 1370 1188 } … … 1374 1192 if (SR_HDL(n) & SR_INT) 1375 1193 { 1376 inti=SR_TO_INT(n);1377 if (i<0 ) return (p-((-i)%p));1378 return i% p;1194 long i=SR_TO_INT(n); 1195 if (i<0L) return (((long)p)-((-i)%((long)p))); 1196 return i%((long)p); 1379 1197 } 1380 1198 int iz=(int)mpz_fdiv_ui(n->z,(unsigned long)p); … … 1398 1216 { 1399 1217 // Hier brauche ich einfach die GMP Zahl 1400 #ifdef LDEBUG1401 1218 nlTest(i); 1402 #endif1403 1219 nlNormalize(i); 1404 1220 if (SR_HDL(i) & SR_INT) 1405 1221 { 1406 mpz_set_si((mpz_ptr) n, (long)SR_TO_INT(i));1222 mpz_set_si((mpz_ptr) n, SR_TO_INT(i)); 1407 1223 return; 1408 1224 } … … 1436 1252 #endif 1437 1253 mpz_init_set(u->z,n->n); 1438 { 1439 int ui=(int)mpz_get_si(u->z); 1440 if ((((ui<<3)>>3)==ui) 1441 && (mpz_cmp_si(u->z,(long)ui)==0)) 1442 { 1443 mpz_clear(u->z); 1444 omFreeBin((ADDRESS)u, rnumber_bin); 1445 return INT_TO_SR(ui); 1446 } 1447 } 1254 u=nlShort3_noinline(u); 1448 1255 return u; 1449 1256 } … … 1474 1281 if (n->s!=3) 1475 1282 { 1476 int ui=(int)mpz_get_si(u->z); 1477 if ((((ui<<3)>>3)==ui) 1478 && (mpz_cmp_si(u->z,(long)ui)==0)) 1479 { 1480 mpz_clear(u->z); 1481 omFreeBin((ADDRESS)u, rnumber_bin); 1482 return INT_TO_SR(ui); 1483 } 1283 u=nlShort3_noinline(u); 1484 1284 } 1485 1285 return u; … … 1544 1344 { 1545 1345 assume(!((SR_HDL(a) & SR_INT)||(a==NULL))); 1546 #ifdef LDEBUG1547 1346 nlTest(a); 1548 #endif1549 1347 number b=(number)omAllocBin(rnumber_bin); 1550 1348 #if defined(LDEBUG) … … 1561 1359 } 1562 1360 b->s = a->s; 1563 #ifdef LDEBUG1564 1361 nlTest(b); 1565 #endif1566 1362 return b; 1567 1363 } … … 1589 1385 { 1590 1386 mpz_neg(a->z,a->z); 1591 if ((a->s==3) && (mpz_size1(a->z)<=MP_SMALL)) 1592 { 1593 int ui=(int)mpz_get_si(a->z); 1594 if ((((ui<<3)>>3)==ui) 1595 && (mpz_cmp_si(a->z,(long)ui)==0)) 1596 { 1597 mpz_clear(a->z); 1598 omFreeBin((ADDRESS)a, rnumber_bin); 1599 a=INT_TO_SR(ui); 1600 } 1601 } 1602 } 1603 #ifdef LDEBUG 1387 if (a->s==3) 1388 { 1389 a=nlShort3(a); 1390 } 1391 } 1604 1392 nlTest(a); 1605 #endif1606 1393 return a; 1607 1394 } … … 1660 1447 return INT_TO_SR(0); 1661 1448 } 1662 //u->s = 3;1663 if (mpz_size1(u->z)<=MP_SMALL)1664 {1665 int ui=(int)mpz_get_si(u->z);1666 if ((((ui<<3)>>3)==ui)1667 && (mpz_cmp_si(u->z,(long)ui)==0))1668 {1669 mpz_clear(u->z);1670 omFreeBin((ADDRESS)u, rnumber_bin);1671 return INT_TO_SR(ui);1672 }1673 }1674 1449 u->s = 3; 1450 u=nlShort3(u); 1675 1451 break; 1676 1452 } … … 1772 1548 return INT_TO_SR(0); 1773 1549 } 1774 if (mpz_size1(u->z)<=MP_SMALL)1775 {1776 int ui=(int)mpz_get_si(u->z);1777 if ((((ui<<3)>>3)==ui)1778 && (mpz_cmp_si(u->z,(long)ui)==0))1779 {1780 mpz_clear(u->z);1781 omFreeBin((ADDRESS)u, rnumber_bin);1782 return INT_TO_SR(ui);1783 }1784 }1785 1550 u->s = 3; 1551 u=nlShort3(u); 1786 1552 break; 1787 1553 } … … 1791 1557 } 1792 1558 } 1793 #ifdef LDEBUG1794 1559 nlTest(u); 1795 #endif1796 1560 return u; 1797 1561 } … … 1850 1614 return INT_TO_SR(0); 1851 1615 } 1852 if (mpz_size1(u->z)<=MP_SMALL)1853 {1854 int ui=(int)mpz_get_si(u->z);1855 if ((((ui<<3)>>3)==ui)1856 && (mpz_cmp_si(u->z,(long)ui)==0))1857 {1858 mpz_clear(u->z);1859 omFreeBin((ADDRESS)u, rnumber_bin);1860 return INT_TO_SR(ui);1861 }1862 }1863 1616 u->s = 3; 1617 u=nlShort3(u); 1864 1618 break; 1865 1619 } … … 1910 1664 return INT_TO_SR(0); 1911 1665 } 1912 //u->s = 3;1913 if (mpz_size1(u->z)<=MP_SMALL)1914 {1915 int ui=(int)mpz_get_si(u->z);1916 if ((((ui<<3)>>3)==ui)1917 && (mpz_cmp_si(u->z,(long)ui)==0))1918 {1919 mpz_clear(u->z);1920 omFreeBin((ADDRESS)u, rnumber_bin);1921 return INT_TO_SR(ui);1922 }1923 }1924 1666 u->s = 3; 1667 u=nlShort3(u); 1925 1668 break; 1926 1669 } … … 2029 1772 return INT_TO_SR(0); 2030 1773 } 2031 //u->s = 3;2032 if (mpz_size1(u->z)<=MP_SMALL)2033 {2034 int ui=(int)mpz_get_si(u->z);2035 if ((((ui<<3)>>3)==ui)2036 && (mpz_cmp_si(u->z,(long)ui)==0))2037 {2038 mpz_clear(u->z);2039 omFreeBin((ADDRESS)u, rnumber_bin);2040 return INT_TO_SR(ui);2041 }2042 }2043 1774 u->s = 3; 1775 u=nlShort3(u); 2044 1776 break; 2045 1777 } … … 2049 1781 } 2050 1782 } 2051 #ifdef LDEBUG2052 1783 nlTest(u); 2053 #endif2054 1784 return u; 2055 1785 } … … 2063 1793 #endif 2064 1794 u->s=3; 2065 mpz_init_set_si(u->z,(long)SR_TO_INT(a)); 2066 mpz_mul_si(u->z,u->z,(long)SR_TO_INT(b)); 2067 #ifdef LDEBUG 1795 mpz_init_set_si(u->z,SR_TO_INT(a)); 1796 mpz_mul_si(u->z,u->z,SR_TO_INT(b)); 2068 1797 nlTest(u); 2069 #endif2070 1798 return u; 2071 1799 } … … 2120 1848 else //u->s==3 2121 1849 { 2122 if (mpz_size1(u->z)<=MP_SMALL) 2123 { 2124 int ui=(int)mpz_get_si(u->z); 2125 if ((((ui<<3)>>3)==ui) 2126 && (mpz_cmp_si(u->z,(long)ui)==0)) 2127 { 2128 mpz_clear(u->z); 2129 omFreeBin((ADDRESS)u, rnumber_bin); 2130 return INT_TO_SR(ui); 2131 } 2132 } 1850 u=nlShort3(u); 2133 1851 } 2134 1852 } … … 2180 1898 } 2181 1899 } 2182 #ifdef LDEBUG2183 1900 nlTest(u); 2184 #endif2185 1901 return u; 2186 1902 } … … 2189 1905 * z := i 2190 1906 */ 2191 number nlRInit ( inti)1907 number nlRInit (long i) 2192 1908 { 2193 1909 number z=(number)omAllocBin(rnumber_bin); … … 2195 1911 z->debug=123456; 2196 1912 #endif 2197 mpz_init_set_si(z->z, (long)i);1913 mpz_init_set_si(z->z,i); 2198 1914 z->s = 3; 2199 1915 return z; … … 2257 1973 LINLINE BOOLEAN nlEqual (number a, number b) 2258 1974 { 2259 #ifdef LDEBUG2260 1975 nlTest(a); 2261 1976 nlTest(b); 2262 #endif2263 1977 // short - short 2264 1978 if (SR_HDL(a) & SR_HDL(b) & SR_INT) return a==b; … … 2270 1984 { 2271 1985 number n; 2272 if ( ((i << 3) >> 3) == i ) n=INT_TO_SR(i);2273 else n=nlRInit(i);2274 #ifdef LDEBUG 1986 LONG ii=(LONG)i; 1987 if ( ((ii << 3) >> 3) == ii ) n=INT_TO_SR(ii); 1988 else n=nlRInit(ii); 2275 1989 nlTest(n); 2276 #endif2277 1990 return n; 2278 1991 } … … 2317 2030 if (*a!=NULL) 2318 2031 { 2319 #ifdef LDEBUG2320 2032 nlTest(*a); 2321 #endif2322 2033 if ((SR_HDL(*a) & SR_INT)==0) 2323 2034 { … … 2333 2044 LINLINE number nlNeg (number a) 2334 2045 { 2335 #ifdef LDEBUG2336 2046 nlTest(a); 2337 #endif2338 2047 if(SR_HDL(a) &SR_INT) 2339 2048 { 2340 2049 int r=SR_TO_INT(a); 2341 if (r==(-( 1<<28))) a=nlRInit(1<<28);2050 if (r==(-(POW_2_28))) a=nlRInit(POW_2_28); 2342 2051 else a=INT_TO_SR(-r); 2343 2052 return a; … … 2354 2063 if (SR_HDL(a) & SR_HDL(b) & SR_INT) 2355 2064 { 2356 int r=SR_HDL(a)+SR_HDL(b)-1;2065 LONG r=SR_HDL(a)+SR_HDL(b)-1L; 2357 2066 if ( ((r << 1) >> 1) == r ) 2358 2067 return (number)(long)r; … … 2364 2073 2365 2074 number nlShort1(number a); 2366 number nlShort3 (number a);2075 number nlShort3_noinline(number x); 2367 2076 2368 2077 LINLINE number nlInpAdd (number a, number b, const ring r) … … 2370 2079 if (SR_HDL(a) & SR_HDL(b) & SR_INT) 2371 2080 { 2372 int r=SR_HDL(a)+SR_HDL(b)-1;2081 LONG r=SR_HDL(a)+SR_HDL(b)-1L; 2373 2082 if ( ((r << 1) >> 1) == r ) 2374 2083 return (number)(long)r; … … 2400 2109 mpz_sub_ui(a->z,a->z,-SR_TO_INT(b)); 2401 2110 a->s = 3; 2402 a=nlShort3(a); 2403 //nlNormalize(a); 2111 a=nlShort3_noinline(a); 2404 2112 break; 2405 2113 } … … 2439 2147 // result cannot be 0, if coeffs are normalized 2440 2148 u->s = 3; 2441 u=nlShort3 (u);2149 u=nlShort3_noinline(u); 2442 2150 break; 2443 2151 } 2444 2152 } 2445 #ifdef LDEBUG2446 2153 nlTest(u); 2447 #endif2448 2154 return u; 2449 2155 } … … 2508 2214 mpz_add(a->z,a->z,b->z); 2509 2215 a->s = 3; 2510 a=nlShort3 (a);2216 a=nlShort3_noinline(a); 2511 2217 break; 2512 2218 } … … 2515 2221 } 2516 2222 } 2517 #ifdef LDEBUG2518 2223 nlTest(a); 2519 #endif2520 2224 return a; 2521 2225 } … … 2524 2228 LINLINE number nlMult (number a, number b) 2525 2229 { 2526 #ifdef LDEBUG2527 2230 nlTest(a); 2528 2231 nlTest(b); 2529 #endif 2232 2530 2233 if (a==INT_TO_SR(0)) return INT_TO_SR(0); 2531 2234 if (b==INT_TO_SR(0)) return INT_TO_SR(0); 2532 2235 if (SR_HDL(a) & SR_HDL(b) & SR_INT) 2533 2236 { 2534 int r=(SR_HDL(a)-1)*(SR_HDL(b)>>1);2535 if ((r/(SR_HDL(b)>>1))==(SR_HDL(a)-1 ))2237 LONG r=(SR_HDL(a)-1L)*(SR_HDL(b)>>1); 2238 if ((r/(SR_HDL(b)>>1))==(SR_HDL(a)-1L)) 2536 2239 { 2537 2240 number u=((number) ((r>>1)+SR_INT)); 2538 if ((( SR_HDL(u)<<1)>>1)==SR_HDL(u)) return (u);2241 if (((((LONG)SR_HDL(u))<<1)>>1)==SR_HDL(u)) return (u); 2539 2242 return nlRInit(SR_HDL(u)>>2); 2540 2243 } … … 2552 2255 if (SR_HDL(a) & SR_HDL(b) & SR_INT) 2553 2256 { 2554 intr=SR_HDL(a)-SR_HDL(b)+1;2257 LONG r=SR_HDL(a)-SR_HDL(b)+1; 2555 2258 if ( ((r << 1) >> 1) == r ) 2556 2259 { 2557 return (number) r;2260 return (number)(long)r; 2558 2261 } 2559 2262 else … … 2578 2281 { 2579 2282 mpz_gcd(a->z,a->z,b->z); 2580 if (mpz_size1(a->z)<=MP_SMALL) 2581 { 2582 int ui=(int)mpz_get_si(a->z); 2583 if ((((ui<<3)>>3)==ui) 2584 && (mpz_cmp_si(a->z,(long)ui)==0)) 2585 { 2586 mpz_clear(a->z); 2587 omFreeBin((ADDRESS)a, rnumber_bin); 2588 a=INT_TO_SR(ui); 2589 } 2590 } 2283 a=nlShort3_noinline(a); 2591 2284 } 2592 2285 } … … 2626 2319 } 2627 2320 MPZ_DIV(a->z,a->z,b->z); 2628 if (mpz_size1(a->z)<=MP_SMALL) 2629 { 2630 int ui=(int)mpz_get_si(a->z); 2631 if ((((ui<<3)>>3)==ui) 2632 && (mpz_cmp_si(a->z,(long)ui)==0)) 2633 { 2634 mpz_clear(a->z); 2635 omFreeBin((ADDRESS)a, rnumber_bin); 2636 a=INT_TO_SR(ui); 2637 } 2638 } 2321 a=nlShort3_noinline(a); 2639 2322 } 2640 2323 } … … 2752 2435 if (mpz_size1(&r->z)<=MP_SMALL) 2753 2436 { 2754 intui=(int)mpz_get_si(&r->z);2437 LONG ui=(int)mpz_get_si(&r->z); 2755 2438 if ((((ui<<3)>>3)==ui) 2756 2439 && (mpz_cmp_si(x->z,(long)ui)==0))
Note: See TracChangeset
for help on using the changeset viewer.