001/** 002 * AbstractUnlimitedIntegerPrimitive.java 003 * 004 * Copyright (c) 2004-2012, Nicole C. Tedesco. All rights reserved. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 007 * use this file except in compliance with the License. You may obtain a copy of 008 * the License at: 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 014 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 015 * License for the specific language governing permissions and limitations under 016 * the License. 017 */ 018 019package net.sf.jaccumulator.unlimiteds; 020 021import java.math.BigDecimal; 022import java.math.BigInteger; 023import java.util.NoSuchElementException; 024 025import net.sf.jaccumulator.Domain; 026import net.sf.jaccumulator.StructureStrategy; 027import net.sf.jaccumulator.doubles.DoublePrimitive; 028import net.sf.jaccumulator.lex.To; 029import net.sf.jaccumulator.primitives.AbstractNumericPrimitive; 030import net.sf.jaccumulator.primitives.Constant; 031import net.sf.jaccumulator.primitives.Primitive; 032import net.sf.jaccumulator.primitives.SealedPrimitive; 033import net.sf.jaccumulator.reals.Real; 034import net.sf.jaccumulator.reals.SealedReal; 035import net.sf.jaccumulator.scalars.NumericPrecision; 036import net.sf.jaccumulator.scalars.RoundingStrategy; 037import net.sf.jaccumulator.scalars.Scalar; 038import net.sf.jaccumulator.scalars.SealedScalar; 039 040/** 041 * Abstract unlimited {@link BigInteger integer} precision {@link Primitive 042 * primitive} implementation 043 * 044 * @param <PRIMITIVE> 045 * this primitive type (used to facilitate operation chaining on write 046 * operations) 047 * @since JCXell 1.0 048 * @author Nicole Tedesco (<a 049 * href="mailto:Nicole@NicoleTedesco.com">Nicole@NicoleTedesco.com</a>) 050 */ 051public abstract class AbstractUnlimitedIntegerPrimitive<PRIMITIVE extends Primitive<PRIMITIVE>> 052 extends 053 AbstractNumericPrimitive<PRIMITIVE> 054{ 055 private static final long serialVersionUID = 8484320393026232886L; 056 057 public AbstractUnlimitedIntegerPrimitive() 058 { 059 this(BigInteger.ZERO); 060 } 061 062 public AbstractUnlimitedIntegerPrimitive( final BigDecimal aValue ) 063 { 064 this(aValue.toBigInteger()); 065 } 066 067 public AbstractUnlimitedIntegerPrimitive( final BigInteger aValue ) 068 { 069 super(NumericPrecision.UNLIMITED_INTEGER); 070 this.setReal(aValue); 071 } 072 073 public AbstractUnlimitedIntegerPrimitive( final boolean aValue ) 074 { 075 this(Constant.toUnlimitedInteger(aValue)); 076 } 077 078 public AbstractUnlimitedIntegerPrimitive( final byte aValue ) 079 { 080 this(BigInteger.valueOf(aValue)); 081 } 082 083 public AbstractUnlimitedIntegerPrimitive( final char aValue ) 084 { 085 this(BigInteger.valueOf(aValue)); 086 } 087 088 public AbstractUnlimitedIntegerPrimitive( final Domain aDomain ) 089 { 090 this(aDomain, BigInteger.ZERO); 091 } 092 093 public AbstractUnlimitedIntegerPrimitive( 094 final Domain aDomain, 095 final BigInteger aValue ) 096 { 097 super(aDomain, NumericPrecision.UNLIMITED_INTEGER); 098 this.setReal(aValue); 099 } 100 101 public AbstractUnlimitedIntegerPrimitive( final double aValue ) 102 { 103 this(Constant.toUnlimitedDecimal(aValue).toBigInteger()); 104 } 105 106 public AbstractUnlimitedIntegerPrimitive( final float aValue ) 107 { 108 this(Constant.toUnlimitedDecimal(aValue).toBigInteger()); 109 } 110 111 public AbstractUnlimitedIntegerPrimitive( final int aValue ) 112 { 113 this(BigInteger.valueOf(aValue)); 114 } 115 116 public AbstractUnlimitedIntegerPrimitive( final long aValue ) 117 { 118 this(BigInteger.valueOf(aValue)); 119 } 120 121 public AbstractUnlimitedIntegerPrimitive( final SealedPrimitive<?> aValue ) 122 { 123 this(aValue.toUnlimitedInteger()); 124 } 125 126 public AbstractUnlimitedIntegerPrimitive( final SealedReal<?> aValue ) 127 { 128 this(aValue.toUnlimitedInteger()); 129 } 130 131 public AbstractUnlimitedIntegerPrimitive( final short aValue ) 132 { 133 this(BigInteger.valueOf(aValue)); 134 } 135 136 public AbstractUnlimitedIntegerPrimitive( final String aValue ) 137 { 138 this(); 139 To.REAL.reactToText(aValue, this); 140 } 141 142 @Override 143 public final PRIMITIVE absoluteValue() 144 throws UnsupportedOperationException, 145 ArithmeticException, 146 IllegalArgumentException 147 { 148 return this.setReal(this.toUnlimitedInteger().abs()); 149 } 150 151 @Override 152 public final PRIMITIVE and( final boolean aValue ) 153 throws UnsupportedOperationException, 154 IllegalArgumentException, 155 ArithmeticException 156 { 157 return this.and(Constant.toUnlimitedInteger(aValue)); 158 } 159 160 @Override 161 public final PRIMITIVE and( final byte aValue ) 162 throws UnsupportedOperationException, 163 IllegalArgumentException, 164 ArithmeticException 165 { 166 return this.and(BigInteger.valueOf(aValue)); 167 } 168 169 @Override 170 public final PRIMITIVE and( final char aValue ) 171 throws UnsupportedOperationException, 172 IllegalArgumentException, 173 ArithmeticException 174 { 175 return this.and(BigInteger.valueOf(aValue)); 176 } 177 178 @Override 179 public final PRIMITIVE and( final int aValue ) 180 throws UnsupportedOperationException, 181 IllegalArgumentException, 182 ArithmeticException 183 { 184 return this.and(BigInteger.valueOf(aValue)); 185 } 186 187 @Override 188 public final PRIMITIVE and( final long aValue ) 189 throws UnsupportedOperationException, 190 IllegalArgumentException, 191 ArithmeticException 192 { 193 return this.and(BigInteger.valueOf(aValue)); 194 } 195 196 @Override 197 public final PRIMITIVE and( final short aValue ) 198 throws UnsupportedOperationException, 199 IllegalArgumentException, 200 ArithmeticException 201 { 202 return this.and(BigInteger.valueOf(aValue)); 203 } 204 205 @Override 206 public final boolean booleanPostDecrement() 207 throws UnsupportedOperationException, 208 ArithmeticException, 209 IllegalArgumentException 210 { 211 return To.booleanValue(this.unlimitedIntegerPostDecrement()); 212 } 213 214 @Override 215 public final boolean booleanPostIncrement() 216 throws UnsupportedOperationException, 217 ArithmeticException, 218 IllegalArgumentException 219 { 220 return To.booleanValue(this.unlimitedIntegerPostIncrement()); 221 } 222 223 @Override 224 public final boolean booleanValue() 225 { 226 return To.booleanValue(this.toUnlimitedInteger()); 227 } 228 229 @Override 230 public final byte bytePostDecrement() 231 throws UnsupportedOperationException, 232 ArithmeticException, 233 IllegalArgumentException 234 { 235 return this.unlimitedIntegerPostDecrement().byteValue(); 236 } 237 238 @Override 239 public final byte bytePostIncrement() 240 throws UnsupportedOperationException, 241 ArithmeticException, 242 IllegalArgumentException 243 { 244 return this.unlimitedIntegerPostIncrement().byteValue(); 245 } 246 247 @Override 248 public final byte byteValue() 249 { 250 return this.toUnlimitedInteger().byteValue(); 251 } 252 253 @Override 254 public final char charPostDecrement() 255 throws UnsupportedOperationException, 256 ArithmeticException, 257 IllegalArgumentException 258 { 259 return (char)this.unlimitedIntegerPostDecrement().intValue(); 260 } 261 262 @Override 263 public final char charPostIncrement() 264 throws UnsupportedOperationException, 265 ArithmeticException, 266 IllegalArgumentException 267 { 268 return (char)this.unlimitedIntegerPostIncrement().intValue(); 269 } 270 271 @Override 272 public final char charValue() 273 { 274 return (char)this.toUnlimitedInteger().intValue(); 275 } 276 277 @Override 278 public final PRIMITIVE cube() 279 throws UnsupportedOperationException, 280 IllegalArgumentException, 281 ArithmeticException 282 { 283 final BigInteger myValue = this.toUnlimitedInteger(); 284 return this.setReal(myValue.pow(3)); 285 } 286 287 @Override 288 public final PRIMITIVE difference( final boolean aValue ) 289 throws UnsupportedOperationException, 290 IllegalArgumentException, 291 ArithmeticException 292 { 293 return this.difference(Constant.toUnlimitedInteger(aValue)); 294 } 295 296 @Override 297 public final PRIMITIVE difference( final byte aValue ) 298 throws UnsupportedOperationException, 299 IllegalArgumentException, 300 ArithmeticException 301 { 302 return this.difference(BigInteger.valueOf(aValue)); 303 } 304 305 @Override 306 public final PRIMITIVE difference( final char aValue ) 307 throws UnsupportedOperationException, 308 IllegalArgumentException, 309 ArithmeticException 310 { 311 return this.difference(BigInteger.valueOf(aValue)); 312 } 313 314 @Override 315 public final PRIMITIVE difference( final double aValue ) 316 throws UnsupportedOperationException, 317 IllegalArgumentException, 318 ArithmeticException 319 { 320 return this.difference(Constant.toUnlimitedDecimal(aValue)); 321 } 322 323 @Override 324 public final PRIMITIVE difference( final float aValue ) 325 throws UnsupportedOperationException, 326 IllegalArgumentException, 327 ArithmeticException 328 { 329 return this.difference(Constant.toUnlimitedDecimal(aValue)); 330 } 331 332 @Override 333 public final PRIMITIVE difference( final int aValue ) 334 throws UnsupportedOperationException, 335 IllegalArgumentException, 336 ArithmeticException 337 { 338 return this.difference(BigInteger.valueOf(aValue)); 339 } 340 341 @Override 342 public final PRIMITIVE difference( final long aValue ) 343 throws UnsupportedOperationException, 344 IllegalArgumentException, 345 ArithmeticException 346 { 347 return this.difference(BigInteger.valueOf(aValue)); 348 } 349 350 @Override 351 public final PRIMITIVE difference( final short aValue ) 352 throws UnsupportedOperationException, 353 IllegalArgumentException, 354 ArithmeticException 355 { 356 return this.difference(BigInteger.valueOf(aValue)); 357 } 358 359 @Override 360 public final double doublePostDecrement() 361 throws UnsupportedOperationException, 362 ArithmeticException, 363 IllegalArgumentException 364 { 365 return this.unlimitedIntegerPostDecrement().doubleValue(); 366 } 367 368 @Override 369 public final double doublePostIncrement() 370 throws UnsupportedOperationException, 371 ArithmeticException, 372 IllegalArgumentException 373 { 374 return this.unlimitedIntegerPostIncrement().doubleValue(); 375 } 376 377 @Override 378 public final double doubleValue() 379 { 380 return this.toUnlimitedInteger().doubleValue(); 381 } 382 383 @Override 384 public final float floatPostDecrement() 385 throws UnsupportedOperationException, 386 ArithmeticException, 387 IllegalArgumentException 388 { 389 return this.unlimitedIntegerPostDecrement().floatValue(); 390 } 391 392 @Override 393 public final float floatPostIncrement() 394 throws UnsupportedOperationException, 395 ArithmeticException, 396 IllegalArgumentException 397 { 398 return this.unlimitedIntegerPostIncrement().floatValue(); 399 } 400 401 @Override 402 public final float floatValue() 403 { 404 return this.toUnlimitedInteger().floatValue(); 405 } 406 407 @Override 408 public final StructureStrategy getStructureStrategy() 409 { 410 return StructureStrategy.BITS; 411 } 412 413 @Override 414 public final int hashCode() 415 { 416 return this.toUnlimitedInteger().hashCode(); 417 } 418 419 @Override 420 @SuppressWarnings( "unchecked" ) 421 public final <R extends Real<?>> R inducePostDecrement( final R aTarget ) 422 throws NullPointerException, 423 NoSuchElementException, 424 UnsupportedOperationException, 425 IllegalStateException 426 { 427 return (R)aTarget.setReal(this.unlimitedIntegerPostDecrement()); 428 } 429 430 @Override 431 @SuppressWarnings( "unchecked" ) 432 public final <S extends Scalar<?>> S inducePostDecrement( final S aTarget ) 433 throws NullPointerException, 434 NoSuchElementException, 435 UnsupportedOperationException, 436 IllegalStateException 437 { 438 return (S)aTarget.setScalar(this.doublePostDecrement()); 439 } 440 441 @Override 442 @SuppressWarnings( "unchecked" ) 443 public final <R extends Real<?>> R inducePostIncrement( final R aTarget ) 444 throws NullPointerException, 445 NoSuchElementException, 446 UnsupportedOperationException, 447 IllegalStateException 448 { 449 return (R)aTarget.setReal(this.unlimitedIntegerPostIncrement()); 450 } 451 452 @Override 453 @SuppressWarnings( "unchecked" ) 454 public final <S extends Scalar<?>> S inducePostIncrement( final S aTarget ) 455 throws NullPointerException, 456 NoSuchElementException, 457 UnsupportedOperationException, 458 IllegalStateException 459 { 460 return (S)aTarget.setScalar(this.doublePostIncrement()); 461 } 462 463 @Override 464 @SuppressWarnings( "unchecked" ) 465 public final <R extends Real<?>> R induceRealMaximum( final R aTarget ) 466 { 467 return (R)aTarget.setScalar(Long.MAX_VALUE); 468 } 469 470 @Override 471 @SuppressWarnings( "unchecked" ) 472 public final <R extends Real<?>> R induceRealMinimum( final R aTarget ) 473 { 474 return (R)aTarget.setScalar(Long.MIN_VALUE); 475 } 476 477 @Override 478 @SuppressWarnings( "unchecked" ) 479 public final <R extends Real<?>> R induceRealValue( final R aTarget ) 480 { 481 return (R)aTarget.setReal(this.toUnlimitedInteger()); 482 } 483 484 @Override 485 @SuppressWarnings( "unchecked" ) 486 public final <S extends Scalar<?>> S induceScalarMaximum( final S aTarget ) 487 { 488 return (S)aTarget.setScalar(Long.MAX_VALUE); 489 } 490 491 @Override 492 @SuppressWarnings( "unchecked" ) 493 public final <S extends Scalar<?>> S induceScalarMinimum( final S aTarget ) 494 { 495 return (S)aTarget.setScalar(Long.MIN_VALUE); 496 } 497 498 @Override 499 @SuppressWarnings( "unchecked" ) 500 public final <S extends Scalar<?>> S induceScalarValue( final S aTarget ) 501 { 502 return (S)aTarget.setScalar(this.longValue()); 503 } 504 505 @Override 506 public final int intPostDecrement() 507 throws UnsupportedOperationException, 508 ArithmeticException, 509 IllegalArgumentException 510 { 511 return this.unlimitedIntegerPostDecrement().intValue(); 512 } 513 514 @Override 515 public final int intPostIncrement() 516 throws UnsupportedOperationException, 517 ArithmeticException, 518 IllegalArgumentException 519 { 520 return this.unlimitedIntegerPostIncrement().intValue(); 521 } 522 523 @Override 524 public final int intValue() 525 { 526 return this.toUnlimitedInteger().intValue(); 527 } 528 529 @Override 530 public PRIMITIVE invalidate() 531 throws UnsupportedOperationException, 532 ArithmeticException, 533 IllegalArgumentException 534 { 535 return this.setZero(); 536 } 537 538 @Override 539 public final PRIMITIVE inverse() 540 throws UnsupportedOperationException, 541 ArithmeticException, 542 IllegalArgumentException 543 { 544 return this.setReal(BigInteger.ONE.divide(this.toUnlimitedInteger())); 545 } 546 547 @Override 548 public final boolean isFinite() 549 { 550 return true; 551 } 552 553 @Override 554 public final boolean isInfinity() 555 { 556 return false; 557 } 558 559 @Override 560 public final boolean isInvalid() 561 { 562 return false; 563 } 564 565 @Override 566 public final boolean isMaximum() 567 { 568 return false; 569 } 570 571 @Override 572 public final boolean isMinimum() 573 { 574 return false; 575 } 576 577 @Override 578 public final boolean isModulo() 579 { 580 return false; 581 } 582 583 @Override 584 public final boolean isNegative() 585 { 586 return this.toUnlimitedInteger().signum() < 0; 587 } 588 589 @Override 590 public final boolean isNegativeFinite() 591 { 592 return this.isNegative(); 593 } 594 595 @Override 596 public final boolean isNegativeInfinity() 597 { 598 return false; 599 } 600 601 @Override 602 public final boolean isPositive() 603 { 604 return 0 < this.toUnlimitedInteger().signum(); 605 } 606 607 @Override 608 public final boolean isPositiveFinite() 609 { 610 return this.isPositive(); 611 } 612 613 @Override 614 public final boolean isPositiveInfinity() 615 { 616 return false; 617 } 618 619 @Override 620 public final boolean isReal() 621 { 622 return true; 623 } 624 625 @Override 626 public final boolean isUnity() 627 { 628 return this.toUnlimitedInteger().compareTo(BigInteger.ONE) == 0; 629 } 630 631 @Override 632 public final boolean isZero() 633 { 634 return this.toUnlimitedInteger().signum() == 0; 635 } 636 637 @Override 638 public final long longPostDecrement() 639 throws UnsupportedOperationException, 640 ArithmeticException, 641 IllegalArgumentException 642 { 643 return this.unlimitedIntegerPostDecrement().longValue(); 644 } 645 646 @Override 647 public final long longPostIncrement() 648 throws UnsupportedOperationException, 649 ArithmeticException, 650 IllegalArgumentException 651 { 652 return this.unlimitedIntegerPostIncrement().longValue(); 653 } 654 655 @Override 656 public final long longValue() 657 { 658 return this.toUnlimitedInteger().longValue(); 659 } 660 661 @Override 662 public final PRIMITIVE mod( final boolean aValue ) 663 throws UnsupportedOperationException, 664 IllegalArgumentException, 665 ArithmeticException 666 { 667 return this.mod(Constant.toUnlimitedInteger(aValue)); 668 } 669 670 @Override 671 public final PRIMITIVE mod( final byte aValue ) 672 throws UnsupportedOperationException, 673 IllegalArgumentException, 674 ArithmeticException 675 { 676 return this.mod(BigInteger.valueOf(aValue)); 677 } 678 679 @Override 680 public final PRIMITIVE mod( final char aValue ) 681 throws UnsupportedOperationException, 682 IllegalArgumentException, 683 ArithmeticException 684 { 685 return this.mod(BigInteger.valueOf(aValue)); 686 } 687 688 @Override 689 public final PRIMITIVE mod( final double aValue ) 690 throws UnsupportedOperationException, 691 IllegalArgumentException, 692 ArithmeticException 693 { 694 return this.mod(Constant.toUnlimitedDecimal(aValue)); 695 } 696 697 @Override 698 public final PRIMITIVE mod( final float aValue ) 699 throws UnsupportedOperationException, 700 IllegalArgumentException, 701 ArithmeticException 702 { 703 return this.mod(Constant.toUnlimitedDecimal(aValue)); 704 } 705 706 @Override 707 public final PRIMITIVE mod( final int aValue ) 708 throws UnsupportedOperationException, 709 IllegalArgumentException, 710 ArithmeticException 711 { 712 return this.mod(BigInteger.valueOf(aValue)); 713 } 714 715 @Override 716 public final PRIMITIVE mod( final long aValue ) 717 throws UnsupportedOperationException, 718 IllegalArgumentException, 719 ArithmeticException 720 { 721 return this.mod(BigInteger.valueOf(aValue)); 722 } 723 724 @Override 725 public final PRIMITIVE mod( final short aValue ) 726 throws UnsupportedOperationException, 727 IllegalArgumentException, 728 ArithmeticException 729 { 730 return this.mod(BigInteger.valueOf(aValue)); 731 } 732 733 @Override 734 public final PRIMITIVE negate() 735 throws UnsupportedOperationException, 736 ArithmeticException, 737 IllegalArgumentException 738 { 739 return this.setReal(this.toUnlimitedInteger().negate()); 740 } 741 742 @Override 743 public final PRIMITIVE not() 744 throws UnsupportedOperationException, 745 IllegalArgumentException, 746 ArithmeticException 747 { 748 return this.setReal(this.toUnlimitedInteger().not()); 749 } 750 751 @Override 752 public final PRIMITIVE or( final BigInteger aValue ) 753 throws UnsupportedOperationException, 754 IllegalArgumentException, 755 ArithmeticException 756 { 757 return this.setReal(this.toUnlimitedInteger().or(aValue)); 758 } 759 760 @Override 761 public final PRIMITIVE or( final boolean aValue ) 762 throws UnsupportedOperationException, 763 IllegalArgumentException, 764 ArithmeticException 765 { 766 return this.or(Constant.toUnlimitedInteger(aValue)); 767 } 768 769 @Override 770 public final PRIMITIVE or( final byte aValue ) 771 throws UnsupportedOperationException, 772 IllegalArgumentException, 773 ArithmeticException 774 { 775 return this.or(BigInteger.valueOf(aValue)); 776 } 777 778 @Override 779 public final PRIMITIVE or( final char aValue ) 780 throws UnsupportedOperationException, 781 IllegalArgumentException, 782 ArithmeticException 783 { 784 return this.or(BigInteger.valueOf(aValue)); 785 } 786 787 @Override 788 public final PRIMITIVE or( final int aValue ) 789 throws UnsupportedOperationException, 790 IllegalArgumentException, 791 ArithmeticException 792 { 793 return this.or(BigInteger.valueOf(aValue)); 794 } 795 796 @Override 797 public final PRIMITIVE or( final long aValue ) 798 throws UnsupportedOperationException, 799 IllegalArgumentException, 800 ArithmeticException 801 { 802 return this.or(BigInteger.valueOf(aValue)); 803 } 804 805 @Override 806 public final PRIMITIVE or( final short aValue ) 807 throws UnsupportedOperationException, 808 IllegalArgumentException, 809 ArithmeticException 810 { 811 return this.or(BigInteger.valueOf(aValue)); 812 } 813 814 @Override 815 public final PRIMITIVE product( final boolean aValue ) 816 throws UnsupportedOperationException, 817 IllegalArgumentException, 818 ArithmeticException 819 { 820 return this.product(Constant.toUnlimitedInteger(aValue)); 821 } 822 823 @Override 824 public final PRIMITIVE product( final byte aValue ) 825 throws UnsupportedOperationException, 826 IllegalArgumentException, 827 ArithmeticException 828 { 829 return this.product(BigInteger.valueOf(aValue)); 830 } 831 832 @Override 833 public final PRIMITIVE product( final char aValue ) 834 throws UnsupportedOperationException, 835 IllegalArgumentException, 836 ArithmeticException 837 { 838 return this.product(BigInteger.valueOf(aValue)); 839 } 840 841 @Override 842 public final PRIMITIVE product( final double aValue ) 843 throws UnsupportedOperationException, 844 IllegalArgumentException, 845 ArithmeticException 846 { 847 return this.product(Constant.toUnlimitedDecimal(aValue)); 848 } 849 850 @Override 851 public final PRIMITIVE product( final float aValue ) 852 throws UnsupportedOperationException, 853 IllegalArgumentException, 854 ArithmeticException 855 { 856 return this.product(Constant.toUnlimitedDecimal(aValue)); 857 } 858 859 @Override 860 public final PRIMITIVE product( final int aValue ) 861 throws UnsupportedOperationException, 862 IllegalArgumentException, 863 ArithmeticException 864 { 865 return this.product(BigInteger.valueOf(aValue)); 866 } 867 868 @Override 869 public final PRIMITIVE product( final long aValue ) 870 throws UnsupportedOperationException, 871 IllegalArgumentException, 872 ArithmeticException 873 { 874 return this.product(BigInteger.valueOf(aValue)); 875 } 876 877 @Override 878 public final PRIMITIVE product( final short aValue ) 879 throws UnsupportedOperationException, 880 IllegalArgumentException, 881 ArithmeticException 882 { 883 return this.product(BigInteger.valueOf(aValue)); 884 } 885 886 @Override 887 public final PRIMITIVE quotient( final BigDecimal aValue ) 888 throws UnsupportedOperationException, 889 IllegalArgumentException, 890 ArithmeticException 891 { 892 return this.setReal(this.toUnlimitedDecimal().divideToIntegralValue( 893 aValue)); 894 } 895 896 @Override 897 public final PRIMITIVE quotient( final boolean aValue ) 898 throws UnsupportedOperationException, 899 IllegalArgumentException, 900 ArithmeticException 901 { 902 return this.quotient(Constant.toUnlimitedInteger(aValue)); 903 } 904 905 @Override 906 public final PRIMITIVE quotient( final byte aValue ) 907 throws UnsupportedOperationException, 908 IllegalArgumentException, 909 ArithmeticException 910 { 911 return this.quotient(BigInteger.valueOf(aValue)); 912 } 913 914 @Override 915 public final PRIMITIVE quotient( final char aValue ) 916 throws UnsupportedOperationException, 917 IllegalArgumentException, 918 ArithmeticException 919 { 920 return this.quotient(BigInteger.valueOf(aValue)); 921 } 922 923 @Override 924 public final PRIMITIVE quotient( final double aValue ) 925 throws UnsupportedOperationException, 926 IllegalArgumentException, 927 ArithmeticException 928 { 929 return this.quotient(Constant.toUnlimitedDecimal(aValue)); 930 } 931 932 @Override 933 public final PRIMITIVE quotient( final float aValue ) 934 throws UnsupportedOperationException, 935 IllegalArgumentException, 936 ArithmeticException 937 { 938 return this.quotient(Constant.toUnlimitedDecimal(aValue)); 939 } 940 941 @Override 942 public final PRIMITIVE quotient( final int aValue ) 943 throws UnsupportedOperationException, 944 IllegalArgumentException, 945 ArithmeticException 946 { 947 return this.quotient(BigInteger.valueOf(aValue)); 948 } 949 950 @Override 951 public final PRIMITIVE quotient( final long aValue ) 952 throws UnsupportedOperationException, 953 IllegalArgumentException, 954 ArithmeticException 955 { 956 return this.quotient(BigInteger.valueOf(aValue)); 957 } 958 959 @Override 960 public final PRIMITIVE quotient( final short aValue ) 961 throws UnsupportedOperationException, 962 IllegalArgumentException, 963 ArithmeticException 964 { 965 return this.quotient(BigInteger.valueOf(aValue)); 966 } 967 968 @Override 969 @SuppressWarnings( "unchecked" ) 970 public final PRIMITIVE round( final RoundingStrategy aRoundingStrategy ) 971 throws UnsupportedOperationException, 972 IllegalArgumentException, 973 ArithmeticException, 974 NullPointerException 975 { 976 return (PRIMITIVE)this; 977 } 978 979 @Override 980 public final PRIMITIVE setMaximum() 981 throws UnsupportedOperationException, 982 ArithmeticException, 983 IllegalArgumentException 984 { 985 return this.setScalar(Long.MAX_VALUE); 986 } 987 988 @Override 989 public final PRIMITIVE setMinimum() 990 throws UnsupportedOperationException, 991 ArithmeticException, 992 IllegalArgumentException 993 { 994 return this.setScalar(Long.MIN_VALUE); 995 } 996 997 @Override 998 public final PRIMITIVE setPrimitive( final SealedPrimitive<?> aValue ) 999 throws UnsupportedOperationException, 1000 IllegalArgumentException, 1001 ArithmeticException, 1002 NullPointerException 1003 { 1004 return this.setReal(aValue.toUnlimitedInteger()); 1005 } 1006 1007 @Override 1008 public final PRIMITIVE setReal( final BigDecimal aValue ) 1009 throws UnsupportedOperationException, 1010 IllegalArgumentException, 1011 ArithmeticException, 1012 NullPointerException 1013 { 1014 return this.setReal(aValue.toBigInteger()); 1015 } 1016 1017 @Override 1018 public final PRIMITIVE setReal( final SealedReal<?> aValue ) 1019 throws UnsupportedOperationException, 1020 IllegalArgumentException, 1021 ArithmeticException, 1022 NullPointerException 1023 { 1024 return this.setReal(aValue.toUnlimitedInteger()); 1025 } 1026 1027 @Override 1028 public final PRIMITIVE setScalar( final boolean aValue ) 1029 throws UnsupportedOperationException, 1030 IllegalArgumentException, 1031 ArithmeticException 1032 { 1033 return this.setReal(Constant.toUnlimitedInteger(aValue)); 1034 } 1035 1036 @Override 1037 public final PRIMITIVE setScalar( final byte aValue ) 1038 throws UnsupportedOperationException, 1039 IllegalArgumentException, 1040 ArithmeticException 1041 { 1042 return this.setReal(BigInteger.valueOf(aValue)); 1043 } 1044 1045 @Override 1046 public final PRIMITIVE setScalar( final char aValue ) 1047 throws UnsupportedOperationException, 1048 IllegalArgumentException, 1049 ArithmeticException 1050 { 1051 return this.setReal(BigInteger.valueOf(aValue)); 1052 } 1053 1054 @Override 1055 public final PRIMITIVE setScalar( final double aValue ) 1056 throws UnsupportedOperationException, 1057 IllegalArgumentException, 1058 ArithmeticException 1059 { 1060 return this.setReal(Constant.toUnlimitedDecimal(aValue)); 1061 } 1062 1063 @Override 1064 public final PRIMITIVE setScalar( final float aValue ) 1065 throws UnsupportedOperationException, 1066 IllegalArgumentException, 1067 ArithmeticException 1068 { 1069 return this.setReal(Constant.toUnlimitedDecimal(aValue)); 1070 } 1071 1072 @Override 1073 public final PRIMITIVE setScalar( final int aValue ) 1074 throws UnsupportedOperationException, 1075 IllegalArgumentException, 1076 ArithmeticException 1077 { 1078 return this.setReal(BigInteger.valueOf(aValue)); 1079 } 1080 1081 @Override 1082 public final PRIMITIVE setScalar( final long aValue ) 1083 throws UnsupportedOperationException, 1084 IllegalArgumentException, 1085 ArithmeticException 1086 { 1087 return this.setReal(BigInteger.valueOf(aValue)); 1088 } 1089 1090 @Override 1091 public final PRIMITIVE setScalar( final SealedScalar<?> aValue ) 1092 throws UnsupportedOperationException, 1093 IllegalArgumentException, 1094 ArithmeticException, 1095 NullPointerException 1096 { 1097 return this.setScalar(aValue.doubleValue()); 1098 } 1099 1100 @Override 1101 public final PRIMITIVE setScalar( final short aValue ) 1102 throws UnsupportedOperationException, 1103 IllegalArgumentException, 1104 ArithmeticException 1105 { 1106 return this.setReal(BigInteger.valueOf(aValue)); 1107 } 1108 1109 @Override 1110 public final PRIMITIVE setUnity() 1111 throws UnsupportedOperationException, 1112 IllegalArgumentException, 1113 ArithmeticException 1114 { 1115 return this.setReal(BigInteger.ONE); 1116 } 1117 1118 @Override 1119 public final PRIMITIVE setZero() 1120 throws UnsupportedOperationException, 1121 IllegalArgumentException, 1122 ArithmeticException 1123 { 1124 return this.setReal(BigInteger.ZERO); 1125 } 1126 1127 @Override 1128 public final PRIMITIVE shiftLeft( final int count ) 1129 throws UnsupportedOperationException, 1130 IllegalArgumentException, 1131 ArithmeticException 1132 { 1133 final BigInteger myValue = this.toUnlimitedInteger(); 1134 return this.setReal(myValue.shiftLeft(count)); 1135 } 1136 1137 @Override 1138 public final PRIMITIVE shiftRight( final int count ) 1139 throws UnsupportedOperationException, 1140 IllegalArgumentException, 1141 ArithmeticException 1142 { 1143 final BigInteger myValue = this.toUnlimitedInteger(); 1144 return this.setReal(myValue.shiftRight(count)); 1145 } 1146 1147 @Override 1148 public final short shortPostDecrement() 1149 throws UnsupportedOperationException, 1150 ArithmeticException, 1151 IllegalArgumentException 1152 { 1153 return this.unlimitedIntegerPostDecrement().shortValue(); 1154 } 1155 1156 @Override 1157 public final short shortPostIncrement() 1158 throws UnsupportedOperationException, 1159 ArithmeticException, 1160 IllegalArgumentException 1161 { 1162 return this.unlimitedIntegerPostIncrement().shortValue(); 1163 } 1164 1165 @Override 1166 public final short shortValue() 1167 { 1168 return this.toUnlimitedInteger().shortValue(); 1169 } 1170 1171 @Override 1172 public final int signum() 1173 { 1174 return this.toUnlimitedInteger().signum(); 1175 } 1176 1177 @Override 1178 public final int size() 1179 { 1180 return this.toUnlimitedInteger().bitCount(); 1181 } 1182 1183 @Override 1184 public final PRIMITIVE square() 1185 throws UnsupportedOperationException, 1186 IllegalArgumentException, 1187 ArithmeticException 1188 { 1189 final BigInteger myValue = this.toUnlimitedInteger(); 1190 return this.setReal(myValue.multiply(myValue)); 1191 } 1192 1193 @Override 1194 public final PRIMITIVE sum( final boolean aValue ) 1195 throws UnsupportedOperationException, 1196 IllegalArgumentException, 1197 ArithmeticException 1198 { 1199 return this.sum(Constant.toUnlimitedInteger(aValue)); 1200 } 1201 1202 @Override 1203 public final PRIMITIVE sum( final byte aValue ) 1204 throws UnsupportedOperationException, 1205 IllegalArgumentException, 1206 ArithmeticException 1207 { 1208 return this.sum(BigInteger.valueOf(aValue)); 1209 } 1210 1211 @Override 1212 public final PRIMITIVE sum( final char aValue ) 1213 throws UnsupportedOperationException, 1214 IllegalArgumentException, 1215 ArithmeticException 1216 { 1217 return this.sum(BigInteger.valueOf(aValue)); 1218 } 1219 1220 @Override 1221 public final PRIMITIVE sum( final double aValue ) 1222 throws UnsupportedOperationException, 1223 IllegalArgumentException, 1224 ArithmeticException 1225 { 1226 return this.sum(Constant.toUnlimitedDecimal(aValue)); 1227 } 1228 1229 @Override 1230 public final PRIMITIVE sum( final float aValue ) 1231 throws UnsupportedOperationException, 1232 IllegalArgumentException, 1233 ArithmeticException 1234 { 1235 return this.sum(Constant.toUnlimitedDecimal(aValue)); 1236 } 1237 1238 @Override 1239 public final PRIMITIVE sum( final int aValue ) 1240 throws UnsupportedOperationException, 1241 IllegalArgumentException, 1242 ArithmeticException 1243 { 1244 return this.sum(BigInteger.valueOf(aValue)); 1245 } 1246 1247 @Override 1248 public final PRIMITIVE sum( final long aValue ) 1249 throws UnsupportedOperationException, 1250 IllegalArgumentException, 1251 ArithmeticException 1252 { 1253 return this.sum(BigInteger.valueOf(aValue)); 1254 } 1255 1256 @Override 1257 public final PRIMITIVE sum( final short aValue ) 1258 throws UnsupportedOperationException, 1259 IllegalArgumentException, 1260 ArithmeticException 1261 { 1262 return this.sum(BigInteger.valueOf(aValue)); 1263 } 1264 1265 @Override 1266 public final PRIMITIVE swapPrimitives( final Primitive<?> aPrimitive ) 1267 { 1268 final BigInteger myValue = this.toUnlimitedInteger(); 1269 final BigInteger aValue = aPrimitive.toUnlimitedInteger(); 1270 aPrimitive.setReal(myValue); 1271 return this.setReal(aValue); 1272 } 1273 1274 @Override 1275 public final Number toNumber() 1276 { 1277 return this.toUnlimitedInteger(); 1278 } 1279 1280 @Override 1281 public final Scalar<?> toScalar() 1282 { 1283 return new DoublePrimitive(this); 1284 } 1285 1286 @Override 1287 public final String toString() 1288 { 1289 return this.toUnlimitedInteger().toString(); 1290 } 1291 1292 @Override 1293 public final BigDecimal toUnlimitedDecimal() 1294 { 1295 return Constant.toUnlimitedDecimal(this.toUnlimitedInteger()); 1296 } 1297 1298 @Override 1299 public final BigDecimal unlimitedDecimalPostDecrement() 1300 throws UnsupportedOperationException, 1301 ArithmeticException, 1302 IllegalArgumentException 1303 { 1304 final BigDecimal myValue = this.toUnlimitedDecimal(); 1305 this.decrement(); 1306 return myValue; 1307 } 1308 1309 @Override 1310 public final BigDecimal unlimitedDecimalPostIncrement() 1311 throws UnsupportedOperationException, 1312 ArithmeticException, 1313 IllegalArgumentException 1314 { 1315 final BigDecimal myValue = this.toUnlimitedDecimal(); 1316 this.increment(); 1317 return myValue; 1318 } 1319 1320 @Override 1321 public final BigInteger unlimitedIntegerPostDecrement() 1322 throws UnsupportedOperationException, 1323 ArithmeticException, 1324 IllegalArgumentException 1325 { 1326 final BigInteger myValue = this.toUnlimitedInteger(); 1327 this.decrement(); 1328 return myValue; 1329 } 1330 1331 @Override 1332 public final BigInteger unlimitedIntegerPostIncrement() 1333 throws UnsupportedOperationException, 1334 ArithmeticException, 1335 IllegalArgumentException 1336 { 1337 final BigInteger myValue = this.toUnlimitedInteger(); 1338 this.increment(); 1339 return myValue; 1340 } 1341 1342 @Override 1343 public final PRIMITIVE xor( final BigInteger aValue ) 1344 throws UnsupportedOperationException, 1345 IllegalArgumentException, 1346 ArithmeticException 1347 { 1348 return this.setReal(this.toUnlimitedInteger().xor(aValue)); 1349 } 1350 1351 @Override 1352 public final PRIMITIVE xor( final boolean aValue ) 1353 throws UnsupportedOperationException, 1354 IllegalArgumentException, 1355 ArithmeticException 1356 { 1357 return this.xor(Constant.toUnlimitedInteger(aValue)); 1358 } 1359 1360 @Override 1361 public final PRIMITIVE xor( final byte aValue ) 1362 throws UnsupportedOperationException, 1363 IllegalArgumentException, 1364 ArithmeticException 1365 { 1366 return this.xor(BigInteger.valueOf(aValue)); 1367 } 1368 1369 @Override 1370 public final PRIMITIVE xor( final char aValue ) 1371 throws UnsupportedOperationException, 1372 IllegalArgumentException, 1373 ArithmeticException 1374 { 1375 return this.xor(BigInteger.valueOf(aValue)); 1376 } 1377 1378 @Override 1379 public final PRIMITIVE xor( final int aValue ) 1380 throws UnsupportedOperationException, 1381 IllegalArgumentException, 1382 ArithmeticException 1383 { 1384 return this.xor(BigInteger.valueOf(aValue)); 1385 } 1386 1387 @Override 1388 public final PRIMITIVE xor( final long aValue ) 1389 throws UnsupportedOperationException, 1390 IllegalArgumentException, 1391 ArithmeticException 1392 { 1393 return this.xor(BigInteger.valueOf(aValue)); 1394 } 1395 1396 @Override 1397 public final PRIMITIVE xor( final short aValue ) 1398 throws UnsupportedOperationException, 1399 IllegalArgumentException, 1400 ArithmeticException 1401 { 1402 return this.xor(BigInteger.valueOf(aValue)); 1403 } 1404}