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