Frequently used functions for large numbers in Java

Source: Internet
Author: User
Tags abs gcd greatest common divisor pow

The field in Java.math declared as BigInteger is static BigInteger BigInteger. The one BigInteger constant 1. Static BigInteger BigInteger. TEN BigInteger's constant 10. Static BigInteger BigInteger. The constant of ZERO BigInteger 0.

Returns the method BigInteger BigInteger in the Java.math of BigInteger. ABS () returns the BigInteger whose values are the absolute value of this BigInteger. BigInteger BigInteger. Add (BigInteger val) returns the BigInteger whose value is (this + val). BigInteger BigInteger. and (BigInteger Val) returns the BigInteger whose value is (This & Val). BigInteger BigInteger. AndNot (BigInteger val) returns the BigInteger whose value is (This & ~val).

BigInteger BigInteger. Clearbit (int n) returns the value of this BigInteger equivalent to the BigInteger that was cleared for positioning.

BigInteger BigInteger. Divide (BigInteger val) returns the BigInteger whose value is (This/val).

BigInteger [] BigInteger. Divideandremainder (BigInteger val) returns an array of two BigInteger including (This/val) followed by (this% Val). BigInteger BigInteger. Flipbit (int n) returns the BigInteger whose value is equivalent to the value after the specified bit is flipped for this BigInteger.

BigInteger BigInteger. GCD (BigInteger val) returns a BigInteger. The value is ABS (this) and ABS (Val) of the greatest common divisor. BigInteger BigInteger. Max (BigInteger val) returns the maximum value for this BigInteger and Val. BigInteger BigInteger. Min (BigInteger val) returns the minimum value for this BigInteger and Val. BigInteger BigInteger. MoD (BigInteger m) returns the BigInteger whose value is (this mod m). BigInteger BigInteger. Modinverse (BigInteger m) returns the BigInteger whose value is (this-1 mod m). BigInteger BigInteger. Modpow (BigInteger exponent, BigInteger m) returns the thisexponent whose value is (BigInteger mod m).

BigInteger BigInteger. Multiply (BigInteger val) returns the BigInteger whose value is (this * val). BigInteger BigInteger. Negate () returns the BigInteger whose value is (-this).

BigInteger BigInteger. Nextprobableprime () returns the first integer that is larger than the possible prime number of this BigInteger. BigInteger BigInteger. Not () returns the BigInteger whose value is (~this).

BigInteger BigInteger. or (BigInteger val) returns the BigInteger whose value is (This | val). BigInteger BigInteger. POW (int exponent) returns a BigInteger whose value is (thisexponent). Static BigInteger BigInteger. Probableprime (int bitlength, Random rnd) returns a positive BigInteger with a specified length that is likely to be a prime number. BigInteger BigInteger. Remainder (BigInteger val) returns the BigInteger whose value is (this% val). BigInteger BigInteger. Setbit (int n) returns its value with the BigInteger equivalent of the BigInteger that is set to refer to the position.

BigInteger BigInteger. Shiftleft (int n) returns the BigInteger whose value is (this << n). BigInteger BigInteger. Shiftright (int n) returns the BigInteger whose value is (this >> n). BigInteger BigInteger. Subtract (BigInteger val) returns the BigInteger whose value is (This-val). BigInteger BigDecimal. Tobiginteger () converts this BigDecimal to BigInteger. BigInteger BigDecimal. Tobigintegerexact () converts this BigDecimal to BigInteger to check for lost information. BigInteger BigDecimal. Unscaledvalue () returns a BigInteger whose value is the non-scale value of this BigDecimal. Static BigInteger BigInteger. ValueOf (long Val) returns the BigInteger whose value equals the value of the specified long. BigInteger BigInteger. XOR (BigInteger val) returns the BigInteger whose value is (this ^ val). The method BigInteger BigInteger in Java.math with the parameter type BigInteger. Add (BigInteger val) returns the BigInteger whose value is (this + val). BigInteger BigInteger. and (BigInteger Val) returns the BigInteger whose value is (This & Val). BigInteger BigInteger. AndNot (BigInteger val) returns the value of (This & ~vAL) of the BigInteger. int BigInteger. CompareTo (BigInteger val) Compare this BigInteger with the specified BigInteger. BigInteger BigInteger. Divide (BigInteger val) returns the BigInteger whose value is (This/val).

BigInteger [] BigInteger. Divideandremainder (BigInteger val) returns an array of two BigInteger including (This/val) followed by (this% Val). BigInteger BigInteger. GCD (BigInteger val) returns a BigInteger. The value is ABS (this) and ABS (Val) of the greatest common divisor.

BigInteger BigInteger. Max (BigInteger val) returns the maximum value for this BigInteger and Val. BigInteger BigInteger. Min (BigInteger val) returns the minimum value for this BigInteger and Val. BigInteger BigInteger. MoD (BigInteger m) returns the BigInteger whose value is (this mod m).

BigInteger BigInteger. Modinverse (BigInteger m) returns the BigInteger whose value is (this-1 mod m). BigInteger BigInteger. Modpow (BigInteger exponent, BigInteger m) returns the thisexponent whose value is (BigInteger mod m). BigInteger BigInteger. Multiply (BigInteger val) returns the BigInteger whose value is (this * val).

BigInteger BigInteger. or (BigInteger val) returns the BigInteger whose value is (This | val). BigInteger BigInteger. Remainder (BigInteger val) returns the BigInteger whose value is (this% val). BigInteger BigInteger. Subtract (BigInteger val) returns the BigInteger whose value is (This-val). BigInteger BigInteger. XOR (BigInteger val) returns the BigInteger whose value is (this ^ val).

Constructor Method BigDecimal (BigInteger val) in Java.math with the parameter type BigInteger will convert BigInteger to BigDecimal. BigDecimal (BigInteger unscaledval, int scale) converts BigInteger non-scale values and int scales to BigDecimal.

BigDecimal (BigInteger unscaledval, int scale, Mathcontext MC) converts BigInteger non-scaling values and int scales to BigDecimal (based on context settings into Row rounding). BigDecimal (BigInteger val, Mathcontext MC) converts BigInteger to BigDecimal (rounded based on context settings). The use of BigInteger in Java.util returns the method BigInteger Scanner in BigInteger java.util. Nextbiginteger () scans the next tag of the input information as a BigInteger.

BigInteger Scanner. Nextbiginteger (int radix) scans the next tag of the input information as a BigInteger.

The use of BigDecimal in Java.math is declared as a field in the Java.math of BigDecimal static BigDecimal BigDecimal. The one value is 1 and the scale is 0.

Static BigDecimal BigDecimal. The TEN value is 10 and the scale is 0. Static BigDecimal BigDecimal. The ZERO value is 0 and the scale is 0.

Returns the method BigDecimal BigDecimal in the Java.math of BigDecimal. ABS () returns BIGDECIMAL, whose value is absolute for this BigDecimal, with a scale of This.scale ().

BigDecimal BigDecimal. ABS (Mathcontext MC) returns the BigDecimal (rounded by context setting) whose values are the absolute value of this BigDecimal. BigDecimal BigDecimal. Add (BigDecimal augend) returns a BigDecimal with a value of (this + augend) with a scale of Max (This.scale (), Augend.scale ()).

BigDecimal BigDecimal. Add (BigDecimal augend, Mathcontext MC) returns the Augend whose value is (this + BigDecimal) (based on the context setting Rounding). BigDecimal BigDecimal. Divide (BigDecimal divisor) returns a BigDecimal with a value of (this/divisor) with a preferred scale of (This.scale ()-Divisor.scale ()); Represents the exact quotient value (because it has an infinite decimal extension), the ArithmeticException is thrown. BigDecimal BigDecimal. Divide (BigDecimal divisor, int roundingmode) returns a BigDecimal with a value of (this/divisor) with a scale of This.scale (). BigDecimal BigDecimal. Divide (BigDecimal divisor, int scale, int roundingmode) returns a BigDecimal. Its value is (this/divisor) and its scale is the specified scale.

BigDecimal BigDecimal. Divide (BigDecimal divisor, int scale, Roundingmode roundingmode) returns a BigDecimal with a value of (this/divisor) whose scale is the specified Degree. BigDecimal BigDecimal. Divide (BigDecimal divisor, Mathcontext MC) returns a this/divisor whose value is (BigDecimal) (rounded by context setting). BigDecimal BigDecimal. Divide (BigDecimal divisor, Roundingmode roundingmode) returns a BigDecimal with a value of (this/divisor). Its scale is This.scale (). BigDecimal [] BigDecimal. Divideandremainder (BigDecimal divisor) returns a BigDecimal array of two elements, which includes the results of Dividetointegralvalue, followed by the calculation of two operands. Remainder.

BigDecimal [] BigDecimal. Divideandremainder (BigDecimal divisor, Mathcontext MC) returns a BigDecimal array of two elements that includes the results of Dividetointegralvalue , followed by the remainder result of rounding the two operands based on the context setting.

BigDecimal BigDecimal. Dividetointegralvalue (BigDecimal divisor) returns BigDecimal. The value is rounded down to the integer portion of the resulting quotient value (this/divisor). BigDecimal BigDecimal. Dividetointegralvalue (BigDecimal divisor, Mathcontext MC) returns BIGDECIMAL. An integer part whose value is (this/divisor).

BigDecimal BigDecimal. Max (BigDecimal val) returns the maximum value for this BigDecimal and Val. BigDecimal BigDecimal. Min (BigDecimal val) returns the minimum value for this BigDecimal and Val.

BigDecimal BigDecimal. Movepointleft (int n) returns a BigDecimal, which is equivalent to moving the decimal point of the value to the left n bits. BigDecimal BigDecimal. Movepointright (int n) returns a BigDecimal. It is equivalent to moving the decimal point of the value to the right n bits.

BigDecimal BigDecimal. Multiply (BigDecimal multiplicand) returns a BigDecimal with a value of (Thisxmultiplicand) with a scale of (This.scale () + Multiplicand . scale ()). BigDecimal BigDecimal. Multiply (BigDecimal multiplicand, Mathcontext MC) returns a thisxmultiplicand whose value is (BigDecimal) (rounded by context setting).

BigDecimal BigDecimal. Negate () returns BIGDECIMAL. Its value is (-this) and its scale is this.scale (). BigDecimal BigDecimal. Negate (Mathcontext MC) returns BigDecimal (rounded by context setting) whose value is (-this).

BigDecimal BigDecimal. Plus () returns BigDecimal with a value of (+this) with a scale of This.scale (). BigDecimal BigDecimal. Plus (Mathcontext MC) returns the BigDecimal (rounded by context setting) whose value is (+this). BigDecimal BigDecimal. Pow (int n) returns the BigDecimal whose value is (THISN). The power is calculated accurately, so that it has infinite precision.

BigDecimal BigDecimal. The POW (int n, Mathcontext MC) returns the BigDecimal whose value is (THISN).

BigDecimal BigDecimal. Remainder (BigDecimal divisor) returns the BigDecimal whose value is (this% divisor). BigDecimal BigDecimal. Remainder (BigDecimal divisor, Mathcontext MC) returns the divisor whose value is (this% BigDecimal) (rounded by context setting). BigDecimal BigDecimal. Round (Mathcontext MC) returns BigDecimal after rounding based on mathcontext settings. BigDecimal BigDecimal. Scalebypoweroften (int n) returns the BigDecimal whose value is equal to (this * 10n). BigDecimal BigDecimal. Setscale (int newscale) returns a BigDecimal whose scale is the specified value. Its value is higher than the value of this BigDecimal. BigDecimal BigDecimal. Setscale (int newscale, int roundingmode) returns a BigDecimal whose scale is the specified value, and its non-scale value is determined by multiplying the non-scale value of this BigDecimal by the appropriate power of 10. To maintain their total value. BigDecimal BigDecimal. Setscale (int newscale, Roundingmode roundingmode) returns BigDecimal, whose scale is the specified value, the non-scale value of which is multiplied by or divided by 10 by the non-scale value of this BigDecimal to correct Availability To maintain their total value. BigDecimal BigDecimal. Striptrailingzeros () returns a value higher than this decimal. But remove all trailing zeros from this representation BigDecimal. BigDecimal BigDecimal. Subtract (BigDecimal subtrahend) returns aThe value of BigDecimal, which is (this-subtrahend). Its scale is Max (This.scale (), Subtrahend.scale ()). BigDecimal BigDecimal. Subtract (BigDecimal subtrahend, Mathcontext MC) returns a this-subtrahend whose value is (BigDecimal) (rounded by context setting). BigDecimal BigDecimal. ULP () returns the size of the ULP (last unit) of this BigDecimal.

Static BigDecimal BigDecimal. ValueOf (double val) converts a double to BigDecimal using the string representation of the double specification provided by the double.tostring (double) method.

Static BigDecimal BigDecimal. ValueOf (long Val) converts a long value to a BigDecimal with a scale of 0. Static BigDecimal BigDecimal. ValueOf (long unscaledval, int scale) converts long non-scaling values and int scales to BigDecimal. The method BigDecimal BigDecimal in Java.math with the parameter type BigDecimal. Add (BigDecimal augend) returns a BigDecimal with a value of (this + augend) with a scale of Max (This.scale (), Augend.scale ()). BigDecimal BigDecimal. Add (BigDecimal augend, Mathcontext MC) returns the BigDecimal whose value is (this + augend) (rounded based on context setting).

int BigDecimal. CompareTo (BigDecimal val) Compare this BigDecimal with the specified BigDecimal.

BigDecimal BigDecimal. Divide (BigDecimal divisor) returns a BigDecimal with a value of (this/divisor). Its preferred scale is (This.scale ()-Divisor.scale ()); It is assumed that the exact quotient value cannot be represented (because it has an infinite decimal extension). The ArithmeticException is thrown. BigDecimal BigDecimal. Divide (BigDecimal divisor, int roundingmode) returns a BigDecimal with a value of (this/divisor) with a scale of This.scale (). BigDecimal BigDecimal. Divide (BigDecimal divisor, int scale, int roundingmode) returns a BigDecimal with a value of (this/divisor) with a specified scale.

BigDecimal BigDecimal. Divide (BigDecimal divisor, int scale, Roundingmode roundingmode) returns a BigDecimal. Its value is (this/divisor). Its scale is the specified scale. BigDecimal BigDecimal. Divide (BigDecimal divisor, Mathcontext MC) returns a this/divisor whose value is (BigDecimal) (rounded by context setting). BigDecimal BigDecimal. Divide (BigDecimal divisor, Roundingmode roundingmode) returns a BigDecimal with a value of (this/divisor) with a scale of This.scale () 。

BigDecimal [] BigDecimal. Divideandremainder (BigDecimal divisor) returns a BigDecimal array of two elements, which includes the results of Dividetointegralvalue, followed by the calculation of two operands. Remainder. BigDecimal [] BigDecimal. Divideandremainder (BigDecimal divisor, Mathcontext MC) returns a BigDecimal array of two elements that includes the results of Dividetointegralvalue , followed by the remainder result of rounding the two operands based on the context setting.

BigDecimal BigDecimal. Dividetointegralvalue (BigDecimal divisor) returns BigDecimal, whose value is rounded down the integer portion of the resulting quotient value (this/divisor). BigDecimal BigDecimal. Dividetointegralvalue (BigDecimal divisor, Mathcontext MC) returns the BigDecimal, whose value is the integer portion of (this/divisor).

BigDecimal BigDecimal. Max (BigDecimal val) returns the maximum value for this BigDecimal and Val. BigDecimal BigDecimal. Min (BigDecimal val) returns the minimum value for this BigDecimal and Val.

BigDecimal BigDecimal. Multiply (BigDecimal multiplicand) returns a BigDecimal. Its value is (Thisxmultiplicand). Its scale is (This.scale () + Multiplicand.scale ()). BigDecimal BigDecimal. Multiply (BigDecimal multiplicand, Mathcontext MC) returns a thisxmultiplicand whose value is (BigDecimal) (rounded by context setting).

BigDecimal BigDecimal. Remainder (BigDecimal divisor) returns the BigDecimal whose value is (this% divisor). BigDecimal BigDecimal. Remainder (BigDecimal divisor, Mathcontext MC) returns the divisor whose value is (this% BigDecimal) (rounded by context setting).

BigDecimal BigDecimal. Subtract (BigDecimal subtrahend) returns a BigDecimal with a value of (this-subtrahend) with a scale of Max (This.scale (), Subtrahend.sca Le ()). BigDecimal BigDecimal. Subtract (BigDecimal subtrahend, Mathcontext MC) returns a this-subtrahend whose value is (BigDecimal) (rounded by context setting).

The use of BigDecimal in Java.util returns the method BigDecimal Scanner in BigDecimal java.util. Nextbigdecimal () scans the next tag of the input information as a BigDecimal.

Frequently used functions for large numbers in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.