1 package org.python.core; 3 4 import java.math.BigInteger ; 5 import java.io.Serializable ; 6 7 11 12 public class PyLong extends PyObject 13 { 14 public static final BigInteger minLong = 15 BigInteger.valueOf(Long.MIN_VALUE); 16 public static final BigInteger maxLong = 17 BigInteger.valueOf(Long.MAX_VALUE); 18 public static final BigInteger maxULong = 19 BigInteger.valueOf(1).shiftLeft(64).subtract(BigInteger.valueOf(1)); 20 21 22 23 public static final String exposed_name="long"; 24 25 public static void typeSetup(PyObject dict,PyType.Newstyle marker) { 26 class exposed___abs__ extends PyBuiltinFunctionNarrow { 27 28 private PyLong self; 29 30 public PyObject getSelf() { 31 return self; 32 } 33 34 exposed___abs__(PyLong self,PyBuiltinFunction.Info info) { 35 super(info); 36 this.self=self; 37 } 38 39 public PyBuiltinFunction makeBound(PyObject self) { 40 return new exposed___abs__((PyLong)self,info); 41 } 42 43 public PyObject __call__() { 44 return self.long___abs__(); 45 } 46 47 public PyObject inst_call(PyObject gself) { 48 PyLong self=(PyLong)gself; 49 return self.long___abs__(); 50 } 51 52 } 53 dict.__setitem__("__abs__",new PyMethodDescr("__abs__",PyLong.class,0,0,new exposed___abs__(null,null))); 54 class exposed___float__ extends PyBuiltinFunctionNarrow { 55 56 private PyLong self; 57 58 public PyObject getSelf() { 59 return self; 60 } 61 62 exposed___float__(PyLong self,PyBuiltinFunction.Info info) { 63 super(info); 64 this.self=self; 65 } 66 67 public PyBuiltinFunction makeBound(PyObject self) { 68 return new exposed___float__((PyLong)self,info); 69 } 70 71 public PyObject __call__() { 72 return self.long___float__(); 73 } 74 75 public PyObject inst_call(PyObject gself) { 76 PyLong self=(PyLong)gself; 77 return self.long___float__(); 78 } 79 80 } 81 dict.__setitem__("__float__",new PyMethodDescr("__float__",PyLong.class,0,0,new exposed___float__(null,null))); 82 class exposed___hex__ extends PyBuiltinFunctionNarrow { 83 84 private PyLong self; 85 86 public PyObject getSelf() { 87 return self; 88 } 89 90 exposed___hex__(PyLong self,PyBuiltinFunction.Info info) { 91 super(info); 92 this.self=self; 93 } 94 95 public PyBuiltinFunction makeBound(PyObject self) { 96 return new exposed___hex__((PyLong)self,info); 97 } 98 99 public PyObject __call__() { 100 return self.long___hex__(); 101 } 102 103 public PyObject inst_call(PyObject gself) { 104 PyLong self=(PyLong)gself; 105 return self.long___hex__(); 106 } 107 108 } 109 dict.__setitem__("__hex__",new PyMethodDescr("__hex__",PyLong.class,0,0,new exposed___hex__(null,null))); 110 class exposed___int__ extends PyBuiltinFunctionNarrow { 111 112 private PyLong self; 113 114 public PyObject getSelf() { 115 return self; 116 } 117 118 exposed___int__(PyLong self,PyBuiltinFunction.Info info) { 119 super(info); 120 this.self=self; 121 } 122 123 public PyBuiltinFunction makeBound(PyObject self) { 124 return new exposed___int__((PyLong)self,info); 125 } 126 127 public PyObject __call__() { 128 return self.long___int__(); 129 } 130 131 public PyObject inst_call(PyObject gself) { 132 PyLong self=(PyLong)gself; 133 return self.long___int__(); 134 } 135 136 } 137 dict.__setitem__("__int__",new PyMethodDescr("__int__",PyLong.class,0,0,new exposed___int__(null,null))); 138 class exposed___invert__ extends PyBuiltinFunctionNarrow { 139 140 private PyLong self; 141 142 public PyObject getSelf() { 143 return self; 144 } 145 146 exposed___invert__(PyLong self,PyBuiltinFunction.Info info) { 147 super(info); 148 this.self=self; 149 } 150 151 public PyBuiltinFunction makeBound(PyObject self) { 152 return new exposed___invert__((PyLong)self,info); 153 } 154 155 public PyObject __call__() { 156 return self.long___invert__(); 157 } 158 159 public PyObject inst_call(PyObject gself) { 160 PyLong self=(PyLong)gself; 161 return self.long___invert__(); 162 } 163 164 } 165 dict.__setitem__("__invert__",new PyMethodDescr("__invert__",PyLong.class,0,0,new exposed___invert__(null,null))); 166 class exposed___long__ extends PyBuiltinFunctionNarrow { 167 168 private PyLong self; 169 170 public PyObject getSelf() { 171 return self; 172 } 173 174 exposed___long__(PyLong self,PyBuiltinFunction.Info info) { 175 super(info); 176 this.self=self; 177 } 178 179 public PyBuiltinFunction makeBound(PyObject self) { 180 return new exposed___long__((PyLong)self,info); 181 } 182 183 public PyObject __call__() { 184 return self.long___long__(); 185 } 186 187 public PyObject inst_call(PyObject gself) { 188 PyLong self=(PyLong)gself; 189 return self.long___long__(); 190 } 191 192 } 193 dict.__setitem__("__long__",new PyMethodDescr("__long__",PyLong.class,0,0,new exposed___long__(null,null))); 194 class exposed___neg__ extends PyBuiltinFunctionNarrow { 195 196 private PyLong self; 197 198 public PyObject getSelf() { 199 return self; 200 } 201 202 exposed___neg__(PyLong self,PyBuiltinFunction.Info info) { 203 super(info); 204 this.self=self; 205 } 206 207 public PyBuiltinFunction makeBound(PyObject self) { 208 return new exposed___neg__((PyLong)self,info); 209 } 210 211 public PyObject __call__() { 212 return self.long___neg__(); 213 } 214 215 public PyObject inst_call(PyObject gself) { 216 PyLong self=(PyLong)gself; 217 return self.long___neg__(); 218 } 219 220 } 221 dict.__setitem__("__neg__",new PyMethodDescr("__neg__",PyLong.class,0,0,new exposed___neg__(null,null))); 222 class exposed___oct__ extends PyBuiltinFunctionNarrow { 223 224 private PyLong self; 225 226 public PyObject getSelf() { 227 return self; 228 } 229 230 exposed___oct__(PyLong self,PyBuiltinFunction.Info info) { 231 super(info); 232 this.self=self; 233 } 234 235 public PyBuiltinFunction makeBound(PyObject self) { 236 return new exposed___oct__((PyLong)self,info); 237 } 238 239 public PyObject __call__() { 240 return self.long___oct__(); 241 } 242 243 public PyObject inst_call(PyObject gself) { 244 PyLong self=(PyLong)gself; 245 return self.long___oct__(); 246 } 247 248 } 249 dict.__setitem__("__oct__",new PyMethodDescr("__oct__",PyLong.class,0,0,new exposed___oct__(null,null))); 250 class exposed___pos__ extends PyBuiltinFunctionNarrow { 251 252 private PyLong self; 253 254 public PyObject getSelf() { 255 return self; 256 } 257 258 exposed___pos__(PyLong self,PyBuiltinFunction.Info info) { 259 super(info); 260 this.self=self; 261 } 262 263 public PyBuiltinFunction makeBound(PyObject self) { 264 return new exposed___pos__((PyLong)self,info); 265 } 266 267 public PyObject __call__() { 268 return self.long___pos__(); 269 } 270 271 public PyObject inst_call(PyObject gself) { 272 PyLong self=(PyLong)gself; 273 return self.long___pos__(); 274 } 275 276 } 277 dict.__setitem__("__pos__",new PyMethodDescr("__pos__",PyLong.class,0,0,new exposed___pos__(null,null))); 278 class exposed___add__ extends PyBuiltinFunctionNarrow { 279 280 private PyLong self; 281 282 public PyObject getSelf() { 283 return self; 284 } 285 286 exposed___add__(PyLong self,PyBuiltinFunction.Info info) { 287 super(info); 288 this.self=self; 289 } 290 291 public PyBuiltinFunction makeBound(PyObject self) { 292 return new exposed___add__((PyLong)self,info); 293 } 294 295 public PyObject __call__(PyObject arg0) { 296 PyObject ret=self.long___add__(arg0); 297 if (ret==null) 298 return Py.NotImplemented; 299 return ret; 300 } 301 302 public PyObject inst_call(PyObject gself,PyObject arg0) { 303 PyLong self=(PyLong)gself; 304 PyObject ret=self.long___add__(arg0); 305 if (ret==null) 306 return Py.NotImplemented; 307 return ret; 308 } 309 310 } 311 dict.__setitem__("__add__",new PyMethodDescr("__add__",PyLong.class,1,1,new exposed___add__(null,null))); 312 class exposed___and__ extends PyBuiltinFunctionNarrow { 313 314 private PyLong self; 315 316 public PyObject getSelf() { 317 return self; 318 } 319 320 exposed___and__(PyLong self,PyBuiltinFunction.Info info) { 321 super(info); 322 this.self=self; 323 } 324 325 public PyBuiltinFunction makeBound(PyObject self) { 326 return new exposed___and__((PyLong)self,info); 327 } 328 329 public PyObject __call__(PyObject arg0) { 330 PyObject ret=self.long___and__(arg0); 331 if (ret==null) 332 return Py.NotImplemented; 333 return ret; 334 } 335 336 public PyObject inst_call(PyObject gself,PyObject arg0) { 337 PyLong self=(PyLong)gself; 338 PyObject ret=self.long___and__(arg0); 339 if (ret==null) 340 return Py.NotImplemented; 341 return ret; 342 } 343 344 } 345 dict.__setitem__("__and__",new PyMethodDescr("__and__",PyLong.class,1,1,new exposed___and__(null,null))); 346 class exposed___div__ extends PyBuiltinFunctionNarrow { 347 348 private PyLong self; 349 350 public PyObject getSelf() { 351 return self; 352 } 353 354 exposed___div__(PyLong self,PyBuiltinFunction.Info info) { 355 super(info); 356 this.self=self; 357 } 358 359 public PyBuiltinFunction makeBound(PyObject self) { 360 return new exposed___div__((PyLong)self,info); 361 } 362 363 public PyObject __call__(PyObject arg0) { 364 PyObject ret=self.long___div__(arg0); 365 if (ret==null) 366 return Py.NotImplemented; 367 return ret; 368 } 369 370 public PyObject inst_call(PyObject gself,PyObject arg0) { 371 PyLong self=(PyLong)gself; 372 PyObject ret=self.long___div__(arg0); 373 if (ret==null) 374 return Py.NotImplemented; 375 return ret; 376 } 377 378 } 379 dict.__setitem__("__div__",new PyMethodDescr("__div__",PyLong.class,1,1,new exposed___div__(null,null))); 380 class exposed___divmod__ extends PyBuiltinFunctionNarrow { 381 382 private PyLong self; 383 384 public PyObject getSelf() { 385 return self; 386 } 387 388 exposed___divmod__(PyLong self,PyBuiltinFunction.Info info) { 389 super(info); 390 this.self=self; 391 } 392 393 public PyBuiltinFunction makeBound(PyObject self) { 394 return new exposed___divmod__((PyLong)self,info); 395 } 396 397 public PyObject __call__(PyObject arg0) { 398 PyObject ret=self.long___divmod__(arg0); 399 if (ret==null) 400 return Py.NotImplemented; 401 return ret; 402 } 403 404 public PyObject inst_call(PyObject gself,PyObject arg0) { 405 PyLong self=(PyLong)gself; 406 PyObject ret=self.long___divmod__(arg0); 407 if (ret==null) 408 return Py.NotImplemented; 409 return ret; 410 } 411 412 } 413 dict.__setitem__("__divmod__",new PyMethodDescr("__divmod__",PyLong.class,1,1,new exposed___divmod__(null,null))); 414 class exposed___floordiv__ extends PyBuiltinFunctionNarrow { 415 416 private PyLong self; 417 418 public PyObject getSelf() { 419 return self; 420 } 421 422 exposed___floordiv__(PyLong self,PyBuiltinFunction.Info info) { 423 super(info); 424 this.self=self; 425 } 426 427 public PyBuiltinFunction makeBound(PyObject self) { 428 return new exposed___floordiv__((PyLong)self,info); 429 } 430 431 public PyObject __call__(PyObject arg0) { 432 PyObject ret=self.long___floordiv__(arg0); 433 if (ret==null) 434 return Py.NotImplemented; 435 return ret; 436 } 437 438 public PyObject inst_call(PyObject gself,PyObject arg0) { 439 PyLong self=(PyLong)gself; 440 PyObject ret=self.long___floordiv__(arg0); 441 if (ret==null) 442 return Py.NotImplemented; 443 return ret; 444 } 445 446 } 447 dict.__setitem__("__floordiv__",new PyMethodDescr("__floordiv__",PyLong.class,1,1,new exposed___floordiv__(null,null))); 448 class exposed___lshift__ extends PyBuiltinFunctionNarrow { 449 450 private PyLong self; 451 452 public PyObject getSelf() { 453 return self; 454 } 455 456 exposed___lshift__(PyLong self,PyBuiltinFunction.Info info) { 457 super(info); 458 this.self=self; 459 } 460 461 public PyBuiltinFunction makeBound(PyObject self) { 462 return new exposed___lshift__((PyLong)self,info); 463 } 464 465 public PyObject __call__(PyObject arg0) { 466 PyObject ret=self.long___lshift__(arg0); 467 if (ret==null) 468 return Py.NotImplemented; 469 return ret; 470 } 471 472 public PyObject inst_call(PyObject gself,PyObject arg0) { 473 PyLong self=(PyLong)gself; 474 PyObject ret=self.long___lshift__(arg0); 475 if (ret==null) 476 return Py.NotImplemented; 477 return ret; 478 } 479 480 } 481 dict.__setitem__("__lshift__",new PyMethodDescr("__lshift__",PyLong.class,1,1,new exposed___lshift__(null,null))); 482 class exposed___mod__ extends PyBuiltinFunctionNarrow { 483 484 private PyLong self; 485 486 public PyObject getSelf() { 487 return self; 488 } 489 490 exposed___mod__(PyLong self,PyBuiltinFunction.Info info) { 491 super(info); 492 this.self=self; 493 } 494 495 public PyBuiltinFunction makeBound(PyObject self) { 496 return new exposed___mod__((PyLong)self,info); 497 } 498 499 public PyObject __call__(PyObject arg0) { 500 PyObject ret=self.long___mod__(arg0); 501 if (ret==null) 502 return Py.NotImplemented; 503 return ret; 504 } 505 506 public PyObject inst_call(PyObject gself,PyObject arg0) { 507 PyLong self=(PyLong)gself; 508 PyObject ret=self.long___mod__(arg0); 509 if (ret==null) 510 return Py.NotImplemented; 511 return ret; 512 } 513 514 } 515 dict.__setitem__("__mod__",new PyMethodDescr("__mod__",PyLong.class,1,1,new exposed___mod__(null,null))); 516 class exposed___mul__ extends PyBuiltinFunctionNarrow { 517 518 private PyLong self; 519 520 public PyObject getSelf() { 521 return self; 522 } 523 524 exposed___mul__(PyLong self,PyBuiltinFunction.Info info) { 525 super(info); 526 this.self=self; 527 } 528 529 public PyBuiltinFunction makeBound(PyObject self) { 530 return new exposed___mul__((PyLong)self,info); 531 } 532 533 public PyObject __call__(PyObject arg0) { 534 PyObject ret=self.long___mul__(arg0); 535 if (ret==null) 536 return Py.NotImplemented; 537 return ret; 538 } 539 540 public PyObject inst_call(PyObject gself,PyObject arg0) { 541 PyLong self=(PyLong)gself; 542 PyObject ret=self.long___mul__(arg0); 543 if (ret==null) 544 return Py.NotImplemented; 545 return ret; 546 } 547 548 } 549 dict.__setitem__("__mul__",new PyMethodDescr("__mul__",PyLong.class,1,1,new exposed___mul__(null,null))); 550 class exposed___or__ extends PyBuiltinFunctionNarrow { 551 552 private PyLong self; 553 554 public PyObject getSelf() { 555 return self; 556 } 557 558 exposed___or__(PyLong self,PyBuiltinFunction.Info info) { 559 super(info); 560 this.self=self; 561 } 562 563 public PyBuiltinFunction makeBound(PyObject self) { 564 return new exposed___or__((PyLong)self,info); 565 } 566 567 public PyObject __call__(PyObject arg0) { 568 PyObject ret=self.long___or__(arg0); 569 if (ret==null) 570 return Py.NotImplemented; 571 return ret; 572 } 573 574 public PyObject inst_call(PyObject gself,PyObject arg0) { 575 PyLong self=(PyLong)gself; 576 PyObject ret=self.long___or__(arg0); 577 if (ret==null) 578 return Py.NotImplemented; 579 return ret; 580 } 581 582 } 583 dict.__setitem__("__or__",new PyMethodDescr("__or__",PyLong.class,1,1,new exposed___or__(null,null))); 584 class exposed___radd__ extends PyBuiltinFunctionNarrow { 585 586 private PyLong self; 587 588 public PyObject getSelf() { 589 return self; 590 } 591 592 exposed___radd__(PyLong self,PyBuiltinFunction.Info info) { 593 super(info); 594 this.self=self; 595 } 596 597 public PyBuiltinFunction makeBound(PyObject self) { 598 return new exposed___radd__((PyLong)self,info); 599 } 600 601 public PyObject __call__(PyObject arg0) { 602 PyObject ret=self.long___radd__(arg0); 603 if (ret==null) 604 return Py.NotImplemented; 605 return ret; 606 } 607 608 public PyObject inst_call(PyObject gself,PyObject arg0) { 609 PyLong self=(PyLong)gself; 610 PyObject ret=self.long___radd__(arg0); 611 if (ret==null) 612 return Py.NotImplemented; 613 return ret; 614 } 615 616 } 617 dict.__setitem__("__radd__",new PyMethodDescr("__radd__",PyLong.class,1,1,new exposed___radd__(null,null))); 618 class exposed___rdiv__ extends PyBuiltinFunctionNarrow { 619 620 private PyLong self; 621 622 public PyObject getSelf() { 623 return self; 624 } 625 626 exposed___rdiv__(PyLong self,PyBuiltinFunction.Info info) { 627 super(info); 628 this.self=self; 629 } 630 631 public PyBuiltinFunction makeBound(PyObject self) { 632 return new exposed___rdiv__((PyLong)self,info); 633 } 634 635 public PyObject __call__(PyObject arg0) { 636 PyObject ret=self.long___rdiv__(arg0); 637 if (ret==null) 638 return Py.NotImplemented; 639 return ret; 640 } 641 642 public PyObject inst_call(PyObject gself,PyObject arg0) { 643 PyLong self=(PyLong)gself; 644 PyObject ret=self.long___rdiv__(arg0); 645 if (ret==null) 646 return Py.NotImplemented; 647 return ret; 648 } 649 650 } 651 dict.__setitem__("__rdiv__",new PyMethodDescr("__rdiv__",PyLong.class,1,1,new exposed___rdiv__(null,null))); 652 class exposed___rfloordiv__ extends PyBuiltinFunctionNarrow { 653 654 private PyLong self; 655 656 public PyObject getSelf() { 657 return self; 658 } 659 660 exposed___rfloordiv__(PyLong self,PyBuiltinFunction.Info info) { 661 super(info); 662 this.self=self; 663 } 664 665 public PyBuiltinFunction makeBound(PyObject self) { 666 return new exposed___rfloordiv__((PyLong)self,info); 667 } 668 669 public PyObject __call__(PyObject arg0) { 670 PyObject ret=self.long___rfloordiv__(arg0); 671 if (ret==null) 672 return Py.NotImplemented; 673 return ret; 674 } 675 676 public PyObject inst_call(PyObject gself,PyObject arg0) { 677 PyLong self=(PyLong)gself; 678 PyObject ret=self.long___rfloordiv__(arg0); 679 if (ret==null) 680 return Py.NotImplemented; 681 return ret; 682 } 683 684 } 685 dict.__setitem__("__rfloordiv__",new PyMethodDescr("__rfloordiv__",PyLong.class,1,1,new exposed___rfloordiv__(null,null))); 686 class exposed___rmod__ extends PyBuiltinFunctionNarrow { 687 688 private PyLong self; 689 690 public PyObject getSelf() { 691 return self; 692 } 693 694 exposed___rmod__(PyLong self,PyBuiltinFunction.Info info) { 695 super(info); 696 this.self=self; 697 } 698 699 public PyBuiltinFunction makeBound(PyObject self) { 700 return new exposed___rmod__((PyLong)self,info); 701 } 702 703 public PyObject __call__(PyObject arg0) { 704 PyObject ret=self.long___rmod__(arg0); 705 if (ret==null) 706 return Py.NotImplemented; 707 return ret; 708 } 709 710 public PyObject inst_call(PyObject gself,PyObject arg0) { 711 PyLong self=(PyLong)gself; 712 PyObject ret=self.long___rmod__(arg0); 713 if (ret==null) 714 return Py.NotImplemented; 715 return ret; 716 } 717 718 } 719 dict.__setitem__("__rmod__",new PyMethodDescr("__rmod__",PyLong.class,1,1,new exposed___rmod__(null,null))); 720 class exposed___rmul__ extends PyBuiltinFunctionNarrow { 721 722 private PyLong self; 723 724 public PyObject getSelf() { 725 return self; 726 } 727 728 exposed___rmul__(PyLong self,PyBuiltinFunction.Info info) { 729 super(info); 730 this.self=self; 731 } 732 733 public PyBuiltinFunction makeBound(PyObject self) { 734 return new exposed___rmul__((PyLong)self,info); 735 } 736 737 public PyObject __call__(PyObject arg0) { 738 PyObject ret=self.long___rmul__(arg0); 739 if (ret==null) 740 return Py.NotImplemented; 741 return ret; 742 } 743 744 public PyObject inst_call(PyObject gself,PyObject arg0) { 745 PyLong self=(PyLong)gself; 746 PyObject ret=self.long___rmul__(arg0); 747 if (ret==null) 748 return Py.NotImplemented; 749 return ret; 750 } 751 752 } 753 dict.__setitem__("__rmul__",new PyMethodDescr("__rmul__",PyLong.class,1,1,new exposed___rmul__(null,null))); 754 class exposed___rshift__ extends PyBuiltinFunctionNarrow { 755 756 private PyLong self; 757 758 public PyObject getSelf() { 759 return self; 760 } 761 762 exposed___rshift__(PyLong self,PyBuiltinFunction.Info info) { 763 super(info); 764 this.self=self; 765 } 766 767 public PyBuiltinFunction makeBound(PyObject self) { 768 return new exposed___rshift__((PyLong)self,info); 769 } 770 771 public PyObject __call__(PyObject arg0) { 772 PyObject ret=self.long___rshift__(arg0); 773 if (ret==null) 774 return Py.NotImplemented; 775 return ret; 776 } 777 778 public PyObject inst_call(PyObject gself,PyObject arg0) { 779 PyLong self=(PyLong)gself; 780 PyObject ret=self.long___rshift__(arg0); 781 if (ret==null) 782 return Py.NotImplemented; 783 return ret; 784 } 785 786 } 787 dict.__setitem__("__rshift__",new PyMethodDescr("__rshift__",PyLong.class,1,1,new exposed___rshift__(null,null))); 788 class exposed___rsub__ extends PyBuiltinFunctionNarrow { 789 790 private PyLong self; 791 792 public PyObject getSelf() { 793 return self; 794 } 795 796 exposed___rsub__(PyLong self,PyBuiltinFunction.Info info) { 797 super(info); 798 this.self=self; 799 } 800 801 public PyBuiltinFunction makeBound(PyObject self) { 802 return new exposed___rsub__((PyLong)self,info); 803 } 804 805 public PyObject __call__(PyObject arg0) { 806 PyObject ret=self.long___rsub__(arg0); 807 if (ret==null) 808 return Py.NotImplemented; 809 return ret; 810 } 811 812 public PyObject inst_call(PyObject gself,PyObject arg0) { 813 PyLong self=(PyLong)gself; 814 PyObject ret=self.long___rsub__(arg0); 815 if (ret==null) 816 return Py.NotImplemented; 817 return ret; 818 } 819 820 } 821 dict.__setitem__("__rsub__",new PyMethodDescr("__rsub__",PyLong.class,1,1,new exposed___rsub__(null,null))); 822 class exposed___rtruediv__ extends PyBuiltinFunctionNarrow { 823 824 private PyLong self; 825 826 public PyObject getSelf() { 827 return self; 828 } 829 830 exposed___rtruediv__(PyLong self,PyBuiltinFunction.Info info) { 831 super(info); 832 this.self=self; 833 } 834 835 public PyBuiltinFunction makeBound(PyObject self) { 836 return new exposed___rtruediv__((PyLong)self,info); 837 } 838 839 public PyObject __call__(PyObject arg0) { 840 PyObject ret=self.long___rtruediv__(arg0); 841 if (ret==null) 842 return Py.NotImplemented; 843 return ret; 844 } 845 846 public PyObject inst_call(PyObject gself,PyObject arg0) { 847 PyLong self=(PyLong)gself; 848 PyObject ret=self.long___rtruediv__(arg0); 849 if (ret==null) 850 return Py.NotImplemented; 851 return ret; 852 } 853 854 } 855 dict.__setitem__("__rtruediv__",new PyMethodDescr("__rtruediv__",PyLong.class,1,1,new exposed___rtruediv__(null,null))); 856 class exposed___sub__ extends PyBuiltinFunctionNarrow { 857 858 private PyLong self; 859 860 public PyObject getSelf() { 861 return self; 862 } 863 864 exposed___sub__(PyLong self,PyBuiltinFunction.Info info) { 865 super(info); 866 this.self=self; 867 } 868 869 public PyBuiltinFunction makeBound(PyObject self) { 870 return new exposed___sub__((PyLong)self,info); 871 } 872 873 public PyObject __call__(PyObject arg0) { 874 PyObject ret=self.long___sub__(arg0); 875 if (ret==null) 876 return Py.NotImplemented; 877 return ret; 878 } 879 880 public PyObject inst_call(PyObject gself,PyObject arg0) { 881 PyLong self=(PyLong)gself; 882 PyObject ret=self.long___sub__(arg0); 883 if (ret==null) 884 return Py.NotImplemented; 885 return ret; 886 } 887 888 } 889 dict.__setitem__("__sub__",new PyMethodDescr("__sub__",PyLong.class,1,1,new exposed___sub__(null,null))); 890 class exposed___truediv__ extends PyBuiltinFunctionNarrow { 891 892 private PyLong self; 893 894 public PyObject getSelf() { 895 return self; 896 } 897 898 exposed___truediv__(PyLong self,PyBuiltinFunction.Info info) { 899 super(info); 900 this.self=self; 901 } 902 903 public PyBuiltinFunction makeBound(PyObject self) { 904 return new exposed___truediv__((PyLong)self,info); 905 } 906 907 public PyObject __call__(PyObject arg0) { 908 PyObject ret=self.long___truediv__(arg0); 909 if (ret==null) 910 return Py.NotImplemented; 911 return ret; 912 } 913 914 public PyObject inst_call(PyObject gself,PyObject arg0) { 915 PyLong self=(PyLong)gself; 916 PyObject ret=self.long___truediv__(arg0); 917 if (ret==null) 918 return Py.NotImplemented; 919 return ret; 920 } 921 922 } 923 dict.__setitem__("__truediv__",new PyMethodDescr("__truediv__",PyLong.class,1,1,new exposed___truediv__(null,null))); 924 class exposed___xor__ extends PyBuiltinFunctionNarrow { 925 926 private PyLong self; 927 928 public PyObject getSelf() { 929 return self; 930 } 931 932 exposed___xor__(PyLong self,PyBuiltinFunction.Info info) { 933 super(info); 934 this.self=self; 935 } 936 937 public PyBuiltinFunction makeBound(PyObject self) { 938 return new exposed___xor__((PyLong)self,info); 939 } 940 941 public PyObject __call__(PyObject arg0) { 942 PyObject ret=self.long___xor__(arg0); 943 if (ret==null) 944 return Py.NotImplemented; 945 return ret; 946 } 947 948 public PyObject inst_call(PyObject gself,PyObject arg0) { 949 PyLong self=(PyLong)gself; 950 PyObject ret=self.long___xor__(arg0); 951 if (ret==null) 952 return Py.NotImplemented; 953 return ret; 954 } 955 956 } 957 dict.__setitem__("__xor__",new PyMethodDescr("__xor__",PyLong.class,1,1,new exposed___xor__(null,null))); 958 class exposed___cmp__ extends PyBuiltinFunctionNarrow { 959 960 private PyLong self; 961 962 public PyObject getSelf() { 963 return self; 964 } 965 966 exposed___cmp__(PyLong self,PyBuiltinFunction.Info info) { 967 super(info); 968 this.self=self; 969 } 970 971 public PyBuiltinFunction makeBound(PyObject self) { 972 return new exposed___cmp__((PyLong)self,info); 973 } 974 975 public PyObject __call__(PyObject arg0) { 976 int ret=self.long___cmp__(arg0); 977 if (ret==-2) { 978 throw Py.TypeError("long"+".__cmp__(x,y) requires y to be '"+"long"+"', not a '"+(arg0).getType().fastGetName()+"'"); 979 } 980 return Py.newInteger(ret); 981 } 982 983 public PyObject inst_call(PyObject gself,PyObject arg0) { 984 PyLong self=(PyLong)gself; 985 int ret=self.long___cmp__(arg0); 986 if (ret==-2) { 987 throw Py.TypeError("long"+".__cmp__(x,y) requires y to be '"+"long"+"', not a '"+(arg0).getType().fastGetName()+"'"); 988 } 989 return Py.newInteger(ret); 990 } 991 992 } 993 dict.__setitem__("__cmp__",new PyMethodDescr("__cmp__",PyLong.class,1,1,new exposed___cmp__(null,null))); 994 class exposed___pow__ extends PyBuiltinFunctionNarrow { 995 996 private PyLong self; 997 998 public PyObject getSelf() { 999 return self; 1000 } 1001 1002 exposed___pow__(PyLong self,PyBuiltinFunction.Info info) { 1003 super(info); 1004 this.self=self; 1005 } 1006 1007 public PyBuiltinFunction makeBound(PyObject self) { 1008 return new exposed___pow__((PyLong)self,info); 1009 } 1010 1011 public PyObject __call__(PyObject arg0,PyObject arg1) { 1012 PyObject ret=self.long___pow__(arg0,arg1); 1013 if (ret==null) 1014 return Py.NotImplemented; 1015 return ret; 1016 } 1017 1018 public PyObject inst_call(PyObject gself,PyObject arg0,PyObject arg1) { 1019 PyLong self=(PyLong)gself; 1020 PyObject ret=self.long___pow__(arg0,arg1); 1021 if (ret==null) 1022 return Py.NotImplemented; 1023 return ret; 1024 } 1025 1026 public PyObject __call__(PyObject arg0) { 1027 PyObject ret=self.long___pow__(arg0,null); 1028 if (ret==null) 1029 return Py.NotImplemented; 1030 return ret; 1031 } 1032 1033 public PyObject inst_call(PyObject gself,PyObject arg0) { 1034 PyLong self=(PyLong)gself; 1035 PyObject ret=self.long___pow__(arg0,null); 1036 if (ret==null) 1037 return Py.NotImplemented; 1038 return ret; 1039 } 1040 1041 } 1042 dict.__setitem__("__pow__",new PyMethodDescr("__pow__",PyLong.class,1,2,new exposed___pow__(null,null))); 1043 class exposed___repr__ extends PyBuiltinFunctionNarrow { 1044 1045 private PyLong self; 1046 1047 public PyObject getSelf() { 1048 return self; 1049 } 1050 1051 exposed___repr__(PyLong self,PyBuiltinFunction.Info info) { 1052 super(info); 1053 this.self=self; 1054 } 1055 1056 public PyBuiltinFunction makeBound(PyObject self) { 1057 return new exposed___repr__((PyLong)self,info); 1058 } 1059 1060 public PyObject __call__() { 1061 return new PyString(self.long_toString()); 1062 } 1063 1064 public PyObject inst_call(PyObject gself) { 1065 PyLong self=(PyLong)gself; 1066 return new PyString(self.long_toString()); 1067 } 1068 1069 } 1070 dict.__setitem__("__repr__",new PyMethodDescr("__repr__",PyLong.class,0,0,new exposed___repr__(null,null))); 1071 class exposed___str__ extends PyBuiltinFunctionNarrow { 1072 1073 private PyLong self; 1074 1075 public PyObject getSelf() { 1076 return self; 1077 } 1078 1079 exposed___str__(PyLong self,PyBuiltinFunction.Info info) { 1080 super(info); 1081 this.self=self; 1082 } 1083 1084 public PyBuiltinFunction makeBound(PyObject self) { 1085 return new exposed___str__((PyLong)self,info); 1086 } 1087 1088 public PyObject __call__() { 1089 return new PyString(self.long_toString()); 1090 } 1091 1092 public PyObject inst_call(PyObject gself) { 1093 PyLong self=(PyLong)gself; 1094 return new PyString(self.long_toString()); 1095 } 1096 1097 } 1098 dict.__setitem__("__str__",new PyMethodDescr("__str__",PyLong.class,0,0,new exposed___str__(null,null))); 1099 class exposed___hash__ extends PyBuiltinFunctionNarrow { 1100 1101 private PyLong self; 1102 1103 public PyObject getSelf() { 1104 return self; 1105 } 1106 1107 exposed___hash__(PyLong self,PyBuiltinFunction.Info info) { 1108 super(info); 1109 this.self=self; 1110 } 1111 1112 public PyBuiltinFunction makeBound(PyObject self) { 1113 return new exposed___hash__((PyLong)self,info); 1114 } 1115 1116 public PyObject __call__() { 1117 return Py.newInteger(self.long_hashCode()); 1118 } 1119 1120 public PyObject inst_call(PyObject gself) { 1121 PyLong self=(PyLong)gself; 1122 return Py.newInteger(self.long_hashCode()); 1123 } 1124 1125 } 1126 dict.__setitem__("__hash__",new PyMethodDescr("__hash__",PyLong.class,0,0,new exposed___hash__(null,null))); 1127 dict.__setitem__("__new__",new PyNewWrapper(PyLong.class,"__new__",-1,-1) { 1128 public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String []keywords) { 1129 return long_new(this,init,subtype,args,keywords); 1130 } 1131 }); 1132 } 1133 1134 private java.math.BigInteger value; 1135 1136 public static PyObject long_new(PyObject new_, boolean init, PyType subtype, 1137 PyObject[] args, String [] keywords) { 1138 1139 ArgParser ap = new ArgParser(exposed_name, args, keywords, 1140 new String [] { "x", "base" }, 0); 1141 1142 PyObject x = ap.getPyObject(0, null); 1143 int base = ap.getInt(1, -909); 1144 if (x == null) { 1145 return Py.Zero; 1146 } 1147 1148 Object o = x.__tojava__(BigInteger .class); 1149 if(o != Py.NoConversion) { 1150 return new PyLong((BigInteger )o); 1151 } 1152 1153 if (base == -909) { 1154 return x.__long__(); 1155 } 1156 1157 if (!(x instanceof PyString)) { 1158 throw Py.TypeError("long: can't convert non-string with explicit base"); 1159 } 1160 1161 return ((PyString) x).atol(base); 1162 } 1164 public PyLong(java.math.BigInteger v) { 1165 value = v; 1166 } 1167 1168 public PyLong(double v) { 1169 this(new java.math.BigDecimal (v).toBigInteger()); 1170 } 1171 public PyLong(long v) { 1172 this(java.math.BigInteger.valueOf(v)); 1173 } 1174 public PyLong(String s) { 1175 this(new java.math.BigInteger (s)); 1176 } 1177 1178 public String toString() { 1179 return long_toString(); 1180 } 1181 1182 final String long_toString() { 1183 return value.toString()+"L"; 1184 } 1185 1186 public int hashCode() { 1187 return long_hashCode(); 1188 } 1189 1190 final int long_hashCode() { 1191 return value.intValue(); 1193 } 1194 1195 public boolean __nonzero__() { 1196 return !value.equals(java.math.BigInteger.valueOf(0)); 1197 } 1198 1199 public double doubleValue() { 1200 double v = value.doubleValue(); 1201 if (v == Double.NEGATIVE_INFINITY || v == Double.POSITIVE_INFINITY) { 1202 throw Py.OverflowError("long int too long to convert"); 1203 } 1204 return v; 1205 } 1206 1207 private static final double scaledDoubleValue(BigInteger val, int[] exp){ 1208 double x = 0; 1209 int signum = val.signum(); 1210 byte[] digits; 1211 1212 if (signum >= 0) { 1213 digits = val.toByteArray(); 1214 } else { 1215 digits = val.negate().toByteArray(); 1216 } 1217 1218 int count = 8; 1219 int i = 0; 1220 1221 if (digits[0] == 0) { 1222 i++; 1223 count++; 1224 } 1225 count = count <= digits.length?count:digits.length; 1226 1227 while (i < count) { 1228 x = x * 256 + (digits[i] & 0xff); 1229 i++; 1230 } 1231 exp[0] = digits.length - i; 1232 return signum*x; 1233 } 1234 1235 public double scaledDoubleValue(int[] exp){ 1236 return scaledDoubleValue(value,exp); 1237 } 1238 1239 1240 private long getLong(long min, long max) { 1241 if (value.compareTo(maxLong) <= 0 && value.compareTo(minLong) >= 0) { 1242 long v = value.longValue(); 1243 if (v >= min && v <= max) 1244 return v; 1245 } 1246 throw Py.OverflowError("long int too long to convert"); 1247 } 1248 1249 public long asLong(int index) { 1250 return getLong(Long.MIN_VALUE, Long.MAX_VALUE); 1251 } 1252 1253 public Object __tojava__(Class c) { 1254 try { 1255 if (c == Byte.TYPE || c == Byte .class) { 1256 return new Byte ((byte)getLong(Byte.MIN_VALUE, 1257 Byte.MAX_VALUE)); 1258 } 1259 if (c == Short.TYPE || c == Short .class) { 1260 return new Short ((short)getLong(Short.MIN_VALUE, 1261 Short.MAX_VALUE)); 1262 } 1263 if (c == Integer.TYPE || c == Integer .class) { 1264 return new Integer ((int)getLong(Integer.MIN_VALUE, 1265 Integer.MAX_VALUE)); 1266 } 1267 if (c == Long.TYPE || c == Long .class) { 1268 return new Long (getLong(Long.MIN_VALUE, 1269 Long.MAX_VALUE)); 1270 } 1271 if (c == Float.TYPE || c == Double.TYPE || c == Float .class || 1272 c == Double .class) 1273 { 1274 return __float__().__tojava__(c); 1275 } 1276 if (c == BigInteger .class || c == Number .class || 1277 c == Object .class || c == Serializable .class) 1278 { 1279 return value; 1280 } 1281 } catch (PyException e) { 1282 return Py.NoConversion; 1283 } 1284 return super.__tojava__(c); 1285 } 1286 1287 public int __cmp__(PyObject other) { 1288 return long___cmp__(other); 1289 } 1290 1291 final int long___cmp__(PyObject other) { 1292 if (!canCoerce(other)) 1293 return -2; 1294 return value.compareTo(coerce(other)); 1295 } 1296 1297 public Object __coerce_ex__(PyObject other) { 1298 if (other instanceof PyLong) 1299 return other; 1300 else 1301 if (other instanceof PyInteger) { 1302 return new PyLong(((PyInteger)other).getValue()); 1303 } else { 1304 return Py.None; 1305 } 1306 } 1307 1308 private static final boolean canCoerce(PyObject other) { 1309 return other instanceof PyLong || other instanceof PyInteger; 1310 } 1311 1312 private static final BigInteger coerce(PyObject other) { 1313 if (other instanceof PyLong) 1314 return ((PyLong) other).value; 1315 else if (other instanceof PyInteger) 1316 return java.math.BigInteger.valueOf( 1317 ((PyInteger) other).getValue()); 1318 else 1319 throw Py.TypeError("xxx"); 1320 } 1321 1322 public PyObject __add__(PyObject right) { 1323 return long___add__(right); 1324 } 1325 1326 final PyObject long___add__(PyObject right) { 1327 if (!canCoerce(right)) 1328 return null; 1329 return new PyLong(value.add(coerce(right))); 1330 } 1331 1332 public PyObject __radd__(PyObject left) { 1333 return long___radd__(left); 1334 } 1335 1336 final PyObject long___radd__(PyObject left) { 1337 return __add__(left); 1338 } 1339 1340 public PyObject __sub__(PyObject right) { 1341 return long___sub__(right); 1342 } 1343 1344 final PyObject long___sub__(PyObject right) { 1345 if (!canCoerce(right)) 1346 return null; 1347 return new PyLong(value.subtract(coerce(right))); 1348 } 1349 1350 public PyObject __rsub__(PyObject left) { 1351 return long___rsub__(left); 1352 } 1353 1354 final PyObject long___rsub__(PyObject left) { 1355 return new PyLong(coerce(left).subtract(value)); 1356 } 1357 1358 public PyObject __mul__(PyObject right) { 1359 return long___mul__(right); 1360 } 1361 1362 final PyObject long___mul__(PyObject right) { 1363 if (right instanceof PySequence) 1364 return ((PySequence) right).repeat(coerceInt(this)); 1365 1366 if (!canCoerce(right)) 1367 return null; 1368 return new PyLong(value.multiply(coerce(right))); 1369 } 1370 1371 public PyObject __rmul__(PyObject left) { 1372 return long___rmul__(left); 1373 } 1374 1375 final PyObject long___rmul__(PyObject left) { 1376 if (left instanceof PySequence) 1377 return ((PySequence) left).repeat(coerceInt(this)); 1378 if (!canCoerce(left)) 1379 return null; 1380 return new PyLong(coerce(left).multiply(value)); 1381 } 1382 1383 private BigInteger divide(BigInteger x, BigInteger y) { 1386 BigInteger zero = java.math.BigInteger.valueOf(0); 1387 if (y.equals(zero)) 1388 throw Py.ZeroDivisionError("long division or modulo"); 1389 1390 if (y.compareTo(zero) < 0) { 1391 if (x.compareTo(zero) > 0) 1392 return (x.subtract(y).subtract( 1393 BigInteger.valueOf(1))).divide(y); 1394 } else { 1395 if (x.compareTo(zero) < 0) 1396 return (x.subtract(y).add(BigInteger.valueOf(1))).divide(y); 1397 } 1398 return x.divide(y); 1399 } 1400 1401 public PyObject __div__(PyObject right) { 1402 return long___div__(right); 1403 } 1404 1405 final PyObject long___div__(PyObject right) { 1406 if (!canCoerce(right)) 1407 return null; 1408 if (Options.divisionWarning > 0) 1409 Py.warning(Py.DeprecationWarning, "classic long division"); 1410 return new PyLong(divide(value, coerce(right))); 1411 } 1412 1413 public PyObject __rdiv__(PyObject left) { 1414 return long___rdiv__(left); 1415 } 1416 1417 final PyObject long___rdiv__(PyObject left) { 1418 if (!canCoerce(left)) 1419 return null; 1420 if (Options.divisionWarning > 0) 1421 Py.warning(Py.DeprecationWarning, "classic long division"); 1422 return new PyLong(divide(coerce(left), value)); 1423 } 1424 1425 public PyObject __floordiv__(PyObject right) { 1426 return long___floordiv__(right); 1427 } 1428 1429 final PyObject long___floordiv__(PyObject right) { 1430 if (!canCoerce(right)) 1431 return null; 1432 return new PyLong(divide(value, coerce(right))); 1433 } 1434 1435 public PyObject __rfloordiv__(PyObject left) { 1436 return long___rfloordiv__(left); 1437 } 1438 1439 final PyObject long___rfloordiv__(PyObject left) { 1440 if (!canCoerce(left)) 1441 return null; 1442 return new PyLong(divide(coerce(left), value)); 1443 } 1444 1445 private static final PyFloat true_divide(BigInteger a,BigInteger b) { 1446 int[] ae = new int[1]; 1447 int[] be = new int[1]; 1448 double ad,bd; 1449 1450 ad = scaledDoubleValue(a,ae); 1451 bd = scaledDoubleValue(b,be); 1452 1453 if (bd == 0 ) throw Py.ZeroDivisionError("long division or modulo"); 1454 1455 ad /= bd; 1456 int aexp = ae[0]-be[0]; 1457 1458 if (aexp > Integer.MAX_VALUE/8) { 1459 throw Py.OverflowError("long/long too large for a float"); 1460 } else if ( aexp < -(Integer.MAX_VALUE/8)) { 1461 return new PyFloat(0.0); 1462 } 1463 1464 ad = ad * Math.pow(2.0, aexp*8); 1465 1466 if (Double.isInfinite(ad)) { 1467 throw Py.OverflowError("long/long too large for a float"); 1468 } 1469 1470 return new PyFloat(ad); 1471 } 1472 1473 public PyObject __truediv__(PyObject right) { 1474 return long___truediv__(right); 1475 } 1476 1477 final PyObject long___truediv__(PyObject right) { 1478 if (!canCoerce(right)) 1479 return null; 1480 return true_divide(this.value,coerce(right)); 1481 } 1482 1483 public PyObject __rtruediv__(PyObject left) { 1484 return long___rtruediv__(left); 1485 } 1486 1487 final PyObject long___rtruediv__(PyObject left) { 1488 if (!canCoerce(left)) 1489 return null; 1490 return true_divide(coerce(left),this.value); 1491 } 1492 1493 private BigInteger modulo(BigInteger x, BigInteger y, BigInteger xdivy) { 1494 return x.subtract(xdivy.multiply(y)); 1495 } 1496 1497 public PyObject __mod__(PyObject right) { 1498 return long___mod__(right); 1499 } 1500 1501 final PyObject long___mod__(PyObject right) { 1502 if (!canCoerce(right)) 1503 return null; 1504 BigInteger rightv = coerce(right); 1505 return new PyLong(modulo(value, rightv, divide(value, rightv))); 1506 } 1507 1508 public PyObject __rmod__(PyObject left) { 1509 return long___rmod__(left); 1510 } 1511 1512 final PyObject long___rmod__(PyObject left) { 1513 if (!canCoerce(left)) 1514 return null; 1515 BigInteger leftv = coerce(left); 1516 return new PyLong(modulo(leftv, value, divide(leftv, value))); 1517 } 1518 1519 public PyObject __divmod__(PyObject right) { 1520 return long___divmod__(right); 1521 } 1522 1523 final PyObject long___divmod__(PyObject right) { 1524 if (!canCoerce(right)) 1525 return null; 1526 BigInteger rightv = coerce(right); 1527 1528 BigInteger xdivy = divide(value, rightv); 1529 return new PyTuple(new PyObject[] { 1530 new PyLong(xdivy), 1531 new PyLong(modulo(value, rightv, xdivy)) 1532 }); 1533 } 1534 1535 public PyObject __rdivmod__(PyObject left) { 1536 return long___rdivmod__(left); 1537 } 1538 1539 final PyObject long___rdivmod__(PyObject left) { 1540 if (!canCoerce(left)) 1541 return null; 1542 BigInteger leftv = coerce(left); 1543 1544 BigInteger xdivy = divide(leftv, value); 1545 return new PyTuple(new PyObject[] { 1546 new PyLong(xdivy), 1547 new PyLong(modulo(leftv, value, xdivy)) 1548 }); 1549 } 1550 1551 public PyObject __pow__(PyObject right, PyObject modulo) { 1552 return long___pow__(right, modulo); 1553 } 1554 final PyObject long___pow__(PyObject right, PyObject modulo) { 1555 if (!canCoerce(right)) 1556 return null; 1557 1558 if (modulo != null && !canCoerce(right)) 1559 return null; 1560 return _pow(value, coerce(right), modulo, this, right); 1561 } 1562 1563 public PyObject __rpow__(PyObject left) { 1564 return long___rpow__(left); 1565 } 1566 1567 final PyObject long___rpow__(PyObject left) { 1568 if (!canCoerce(left)) 1569 return null; 1570 return _pow(coerce(left), value, null, left, this); 1571 } 1572 1573 public static PyObject _pow(BigInteger value, BigInteger y, 1574 PyObject modulo, PyObject left, PyObject right) 1575 { 1576 if (y.compareTo(BigInteger.valueOf(0)) < 0) { 1577 if (value.compareTo(BigInteger.valueOf(0)) != 0) 1578 return left.__float__().__pow__(right, modulo); 1579 else 1580 throw Py.ZeroDivisionError("zero to a negative power"); 1581 } 1582 if (modulo == null) 1583 return new PyLong(value.pow(y.intValue())); 1584 else { 1585 1588 BigInteger z = coerce(modulo); 1589 int zi = z.intValue(); 1590 if (zi == 0) 1592 throw Py.ValueError("pow(x, y, z) with z == 0"); 1593 if (zi == 1 || zi == -1) 1594 return new PyLong(0); 1595 1596 if (z.compareTo(BigInteger.valueOf(0)) <= 0) { 1597 1601 y = value.modPow(y, z.negate()); 1602 if (y.compareTo(BigInteger.valueOf(0)) > 0) { 1603 return new PyLong(z.add(y)); 1604 } else { 1605 return new PyLong(y); 1606 } 1607 } else { 1609 return new PyLong(value.modPow(y, z)); 1612 } 1614 } 1615 } 1616 1617 private static final int coerceInt(PyObject other) { 1618 if (other instanceof PyLong) 1619 return (int) ((PyLong) other).getLong( 1620 Integer.MIN_VALUE, Integer.MAX_VALUE); 1621 else if (other instanceof PyInteger) 1622 return ((PyInteger) other).getValue(); 1623 else 1624 throw Py.TypeError("xxx"); 1625 } 1626 1627 public PyObject __lshift__(PyObject right) { 1628 return long___lshift__(right); 1629 } 1630 1631 final PyObject long___lshift__(PyObject right) { 1632 if (!canCoerce(right)) 1633 return null; 1634 int rightv = coerceInt(right); 1635 if(rightv < 0) 1636 throw Py.ValueError("negative shift count"); 1637 return new PyLong(value.shiftLeft(rightv)); 1638 } 1639 1640 public PyObject __rshift__(PyObject right) { 1641 return long___rshift__(right); 1642 } 1643 1644 final PyObject long___rshift__(PyObject right) { 1645 if (!canCoerce(right)) 1646 return null; 1647 int rightv = coerceInt(right); 1648 if(rightv < 0) 1649 throw Py.ValueError("negative shift count"); 1650 return new PyLong(value.shiftRight(rightv)); 1651 } 1652 1653 public PyObject __and__(PyObject right) { 1654 return long___and__(right); 1655 } 1656 1657 final PyObject long___and__(PyObject right) { 1658 if (!canCoerce(right)) 1659 return null; 1660 return new PyLong(value.and(coerce(right))); 1661 } 1662 1663 public PyObject __rand__(PyObject left) { 1664 return long___rand__(left); 1665 } 1666 1667 final PyObject long___rand__(PyObject left) { 1668 if (!canCoerce(left)) 1669 return null; 1670 return new PyLong(coerce(left).and(value)); 1671 } 1672 1673 public PyObject __xor__(PyObject right) { 1674 return long___xor__(right); 1675 } 1676 1677 final PyObject long___xor__(PyObject right) { 1678 if (!canCoerce(right)) 1679 return null; 1680 return new PyLong(value.xor(coerce(right))); 1681 } 1682 1683 public PyObject __rxor__(PyObject left) { 1684 return long___rxor__(left); 1685 } 1686 1687 final PyObject long___rxor__(PyObject left) { 1688 if (!canCoerce(left)) 1689 return null; 1690 return new PyLong(coerce(left).xor(value)); 1691 } 1692 1693 public PyObject __or__(PyObject right) { 1694 return long___or__(right); 1695 } 1696 1697 final PyObject long___or__(PyObject right) { 1698 if (!canCoerce(right)) 1699 return null; 1700 return new PyLong(value.or(coerce(right))); 1701 } 1702 1703 public PyObject __ror__(PyObject left) { 1704 return long___ror__(left); 1705 } 1706 1707 final PyObject long___ror__(PyObject left) { 1708 if (!canCoerce(left)) 1709 return null; 1710 return new PyLong(coerce(left).or(value)); 1711 } 1712 1713 public PyObject __neg__() { 1714 return long___neg__(); 1715 } 1716 1717 final PyObject long___neg__() { 1718 return new PyLong(value.negate()); 1719 } 1720 1721 public PyObject __pos__() { 1722 return long___pos__(); 1723 } 1724 1725 final PyObject long___pos__() { 1726 return this; 1727 } 1728 1729 public PyObject __abs__() { 1730 return long___abs__(); 1731 } 1732 final PyObject long___abs__() { 1733 return new PyLong(value.abs()); 1734 } 1735 1736 public PyObject __invert__() { 1737 return long___invert__(); 1738 } 1739 1740 final PyObject long___invert__() { 1741 return new PyLong(value.not()); 1742 } 1743 1744 public PyObject __int__() { 1745 return long___int__(); 1746 } 1747 1748 final PyObject long___int__() { 1749 long v = value.longValue(); 1750 if (v < Integer.MIN_VALUE || v > Integer.MAX_VALUE) { 1751 return this; 1752 } 1753 return new PyInteger((int)getLong(Integer.MIN_VALUE, 1754 Integer.MAX_VALUE)); 1755 } 1756 1757 1758 public PyLong __long__() { 1759 return long___long__(); 1760 } 1761 1762 final PyLong long___long__() { 1763 return this; 1764 } 1765 1766 public PyFloat __float__() { 1767 return long___float__(); 1768 } 1769 1770 final PyFloat long___float__() { 1771 return new PyFloat(doubleValue()); 1772 } 1773 1774 public PyComplex __complex__() { 1775 return long___complex__(); 1776 } 1777 1778 final PyComplex long___complex__() { 1779 return new PyComplex(doubleValue(), 0.); 1780 } 1781 1782 public PyString __oct__() { 1783 return long___oct__(); 1784 } 1785 1786 final PyString long___oct__() { 1787 String s = value.toString(8); 1788 if (s.startsWith("-")) 1789 return new PyString("-0"+s.substring(1, s.length())+"L"); 1790 else 1791 if (s.startsWith("0")) 1792 return new PyString(s+"L"); 1793 else 1794 return new PyString("0"+s+"L"); 1795 } 1796 1797 public PyString __hex__() { 1798 return long___hex__(); 1799 } 1800 1801 final PyString long___hex__() { 1802 String s = value.toString(16).toUpperCase(); 1803 if (s.startsWith("-")) 1804 return new PyString("-0x"+s.substring(1, s.length())+"L"); 1805 else 1806 return new PyString("0x"+s+"L"); 1807 } 1808 1809 public PyString __str__() { 1810 return Py.newString(value.toString()); 1811 } 1812 1813 public boolean isMappingType() { return false; } 1814 public boolean isSequenceType() { return false; } 1815 1816} 1817 | Popular Tags |