文档库 最新最全的文档下载
当前位置:文档库 › jdk源码的java.math包学习

jdk源码的java.math包学习

jdk源码的java.math包学习
jdk源码的java.math包学习

jdk源码学习java.math包

阅读JDK源代码java.math中的

java.math.BigDecimal

java.math.BigInteger

java.math.BitSieve

java.math.MathContext

java.math.MutableBigInteger

java.math.RoundingMode

java.math.SignedMutableBigInteger

1、java.math.BigDecimal

不可变的、任意精度的有符号十进制数。BigDecimal 由任意精度的整数非标度值和 32 位的整数标度 (scale) 组成。

如果为零或正数,则标度是小数点后的位数。如果为负数,则将该数的非标度值乘以 10 的负 scale 次幂。因此,BigDecimal 表示的数值是unscaledValue × 10^(-scale)。

提供以下操作:算术、标度操作、舍入、比较、哈希算法和格式转换。

可以通过两种类型的操作来处理 BigDecimal 的标度:标度/舍入操作和小数点移动操作。标度/舍入操作(setScale 和 round)返回 BigDecimal,其值近似地(或精确地)等于操作数的值,但是其标度或精度是指定的值;即:它们会增加或减少对其值具有最小影响的存储数的精度。小数点移动操作(movePointLeft 和 movePointRight)返回从操作数创建的 BigDecimal,创建的方法是按指定方向将小数点移动一个指定距离。

BigDecimal 的自然排序与 equals 方法不一致。

public class BigDecimal extends Number implements Comparable 属性:

private volatile BigInteger intVal //BigDecimal的非标度值

private int scale = 0 //BigDecimal的标度值

private volatile transient int precision = 0 //BigDecimal的精度.This field is mutable until set nonzero.

private volatile transient String stringCache = null //规范的字符表示private static final long INFLATED = Long.MIN_VALUE //

private transient long intCompact = INFLATED

private static final int MAX_COMPACT_DIGITS = 18

private static final int MAX_BIGINT_BITS = 62

private static final long serialVersionUID = 6108874887143696463L

private static final BigDecimal zeroThroughTen[] 缓存0~10的数据

public static final BigDecimal ZERO = zeroThroughTen[0] 值为0,标度为0。

public static final BigDecimal ONE = zeroThroughTen[1] 值为1,标度为 0。public static final BigDecimal TEN = zeroThroughTen[10] 值为10,标度

为 0。

public BigDecimal(char[] in, int offset, int len) //翻译字符数组为BigDecimal

public BigDecimal(char[] in, int offset, int len, MathContext mc) //

调用this(in, offset, len);指定精度,if (mc.precision > 0) roundThis(mc) public BigDecimal(char[] in) //调用this(in, 0, in.length)

public BigDecimal(char[] in, MathContext mc) //调用this(in, 0, in.length, mc)

public BigDecimal(String val) //调用this(val.toCharArray(), 0,

val.length())

public BigDecimal(String val, MathContext mc) //this(val.toCharArray(), 0, val.length()); if (mc.precision > 0)roundThis(mc)

public BigDecimal(double val) //此构造方法的结果有一定的不可预知性,优先选用String参数

public BigDecimal(double val, MathContext mc) //调用this(val);if (mc.precision > 0) roundThis(mc)

public BigDecimal(BigInteger val) //将 BigInteger 转换为 BigDecimal。BigDecimal 的标度是零。

public BigDecimal(BigInteger val, MathContext mc) //将 BigInteger 转换为 BigDecimal(根据上下文设置进行舍入)。BigDecimal 的标度为零。

public BigDecimal(BigInteger unscaledVal, int scale) //将 BigInteger 非标度值和 int 标度转换为 BigDecimal。BigDecimal 的值为(unscaledVal × 10-scale)。

public BigDecimal(BigInteger unscaledVal, int scale, MathContext mc) //

public BigDecimal(int val) //将int转型成BigDecimal

public BigDecimal(int val, MathContext mc) //设置精度

public BigDecimal(long val) //将long转型成BigDecimal

public BigDecimal(long val, MathContext mc) //设置精度

private BigDecimal(long val, int scale) //Trusted internal constructor private BigDecimal(BigInteger intVal, long val, int scale) //Trusted internal constructor

public static BigDecimal valueOf(long unscaledVal, int scale) //将 long 非标度值和 int 标度转换为 BigDecimal。

public static BigDecimal valueOf(long val) //将 long 非标度值转换为BigDecimal。

public static BigDecimal valueOf(double val) //将 double 非标度值转换为 BigDecimal。

public BigDecimal add(BigDecimal augend) //加法

public BigDecimal add(BigDecimal augend, MathContext mc) //加法,带精度

private BigDecimal[] preAlign(BigDecimal lhs, BigDecimal augend,long padding, MathContext mc)

public BigDecimal subtract(BigDecimal subtrahend) //减法

public BigDecimal subtract(BigDecimal subtrahend, MathContext mc) //

减法,带精度

public BigDecimal multiply(BigDecimal multiplicand) //乘法

public BigDecimal multiply(BigDecimal multiplicand, MathContext mc) //乘法,带精度

public BigDecimal divide(BigDecimal divisor, int scale, int roundingMode) //除法

public BigDecimal divide(BigDecimal divisor, int scale, RoundingMode roundingMode) //除法

public BigDecimal divide(BigDecimal divisor, int roundingMode) //舍入模式

public BigDecimal divide(BigDecimal divisor, RoundingMode roundingMode) //舍入模式

public BigDecimal divide(BigDecimal divisor) //返回一个 BigDecimal,其值为 (this / divisor),其首选标度为 (this.scale() – divisor.scale() public BigDecimal divide(BigDecimal divisor, MathContext mc) //除法,带精度

public BigDecimal divideToIntegralValue(BigDecimal divisor) //返回整数型的除法值//返回 BigDecimal,其值为向下舍入所得商值 (this / divisor) 的整数部分。

public BigDecimal divideToIntegralValue(BigDecimal divisor, MathContext mc) //带精度

public BigDecimal remainder(BigDecimal divisor) //返回剩余部分数据//

数据的值为

this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)) public BigDecimal remainder(BigDecimal divisor, MathContext mc) //带精度

public BigDecimal[] divideAndRemainder(BigDecimal divisor)//除并且返回剩余值

public BigDecimal[] divideAndRemainder(BigDecimal divisor, MathContext mc) //带精度

public BigDecimal pow(int n) //N次方

public BigDecimal pow(int n, MathContext mc) //带精度

public BigDecimal abs() //绝对值

public BigDecimal abs(MathContext mc) //带精度

public BigDecimal negate() //取负

public BigDecimal negate(MathContext mc)

public BigDecimal plus() //与negate()对称

public BigDecimal plus(MathContext mc) //带精度

public int signum() //正负号函数

public int scale() //返回数的标度

public int precision() //返回数的精度

public BigInteger unscaledValue() //返回其值为此 BigDecimal 的非标度值的 BigInteger。(计算 (this * 10this.scale())。)

数值的舍入方式

public final static int ROUND_UP = 0

public final static int ROUND_DOWN = 1

public final static int ROUND_CEILING = 2

public final static int ROUND_FLOOR = 3

public final static int ROUND_HALF_UP = 4

public final static int ROUND_HALF_DOWN = 5

public final static int ROUND_HALF_EVEN = 6

public final static int ROUND_UNNECESSARY = 7

public BigDecimal round(MathContext mc) //对数值进行舍入

public BigDecimal setScale(int newScale, RoundingMode roundingMode) //设置新的标度

public BigDecimal setScale(int newScale, int roundingMode) //设置新的标度

public BigDecimal setScale(int newScale) //调用setScale(newScale, ROUND_UNNECESSARY)

public BigDecimal movePointLeft(int n) //小数点左移

public BigDecimal movePointRight(int n) //小数点右移

public BigDecimal scaleByPowerOfTen(int n) //返回其数值等于 (this * 10n) 的 BigDecimal。该结果的标度为 (this.scale() – n)。

public BigDecimal stripTrailingZeros() //去除尾部多余的零

public int compareTo(BigDecimal val) //比较数值的大小

public boolean equals(Object x) //判断是否相等

public BigDecimal min(BigDecimal val) //返回较小值

public BigDecimal max(BigDecimal val) //返回较大值

public int hashCode() //hashCode

public String toString() //返回字符串表示形式

public String toEngineeringString() //科学计数法

public String toPlainString() //不带指数的表示

private String getValueString(int signum, String intString, int scale) //返回digit.digit字符串的形式

public BigInteger toBigInteger()

public BigInteger toBigIntegerExact()

public long longValue()

public long longValueExact()

// These constants are only initialized if needed

/** BigInteger equal to Long.MIN_VALUE. */

private static BigInteger LONGMIN = null;

/** BigInteger equal to Long.MAX_VALUE. */

private static BigInteger LONGMAX = null;

public int intValue()

public int intValueExact()

public short shortValueExact()

public byte byteValueExact()

public float floatValue()

public double doubleValue()

public BigDecimal ulp()

private String layoutChars(boolean sci)

private static BigInteger tenToThe(int n)

private static BigInteger TENPOWERS[]

private static long longTenToThe(long val, int n)

private static long thresholds[][]

private static boolean compactLong(long val) //返回(val !=

Long.MIN_VALUE)

private BigDecimal inflate()

private static void matchScale(BigDecimal[] val)

private synchronized void readObject(java.io.ObjectInputStream s) private void writeObject(java.io.ObjectOutputStream s)

private int digitLength()

private static int[] ilogTable

private int intLength(int x)

private BigDecimal stripZerosToMatchScale(long preferredScale)

private int checkScale(long val)

private BigDecimal roundOp(MathContext mc)

private void roundThis(MathContext mc)

private BigDecimal doRound(MathContext mc)

private BigDecimal dropDigits(MathContext mc, int drop)

private static int longCompareTo(long x, long y)

private static void print(String name, BigDecimal bd) //内部打印格式private BigDecimal audit() //审计

2、java.math.MathContext

该对象是封装上下文设置的不可变对象,它描述数字运算符的某些规则precision:某个操作使用的数字个数;结果舍入到此精度

roundingMode:一个 RoundingMode 对象,该对象指定舍入使用的算法。

public final class MathContext implements Serializable

private static final int DEFAULT_DIGITS = 9;

private static final RoundingMode DEFAULT_ROUNDINGMODE = RoundingMode.HALF_UP;

private static final int MIN_DIGITS = 0 //用来表示的最少字符Maximum is Integer.MAX_VALUE

private static final long serialVersionUID = 5579720004786848255L //

序列化版本号

public static final MathContext UNLIMITED =new MathContext(0, RoundingMode.HALF_UP) //具有无限精度算法所需值的 MathContext 对象。public static final MathContext DECIMAL32 =new MathContext(7, RoundingMode.HALF_EVEN) //精度设置与 IEEE 754R Decimal32 格式(即 7 个数字)匹配

public static final MathContext DECIMAL64 =new MathContext(16, RoundingMode.HALF_EVEN) //精度设置与 IEEE 754R Decimal64 格式(即 16 个数字)匹配

public static final MathContext DECIMAL128 =new MathContext(34, RoundingMode.HALF_EVEN) //精度设置与 IEEE 754R Decimal128 格式(即 34 个数字)匹配

final int precision //精度

final RoundingMode roundingMode //舍入模式

transient BigInteger roundingMax = null; //

transient BigInteger roundingMin = null; //

private static final int MAX_LOOKASIDE = 1000; //

public MathContext(int setPrecision) //设置精度,非负 int 精度设置public MathContext(int setPrecision,RoundingMode setRoundingMode) //

具有指定的精度和舍入模式。

public MathContext(String val) //与 toString() 方法生成的字符串的格式相同的输入参数

public int getPrecision() //返回精度,非负数

public RoundingMode getRoundingMode() //返回舍入模式

public boolean equals(Object x) //

public int hashCode()

public https://www.wendangku.net/doc/0511478448.html,ng.String toString() //”precision=” + precision + ” ” + “roundingMode=” + roundingMode.toString()

private synchronized void readObject(java.io.ObjectInputStream s)

3、java.math.RoundingMode

舍入模式

public enum RoundingMode

UP(BigDecimal.ROUND_UP)

DOWN(BigDecimal.ROUND_DOWN)

CEILING(BigDecimal.ROUND_CEILING)

FLOOR(BigDecimal.ROUND_FLOOR)

HALF_UP(BigDecimal.ROUND_HALF_UP)

HALF_DOWN(BigDecimal.ROUND_HALF_DOWN)

HALF_EVEN(BigDecimal.ROUND_HALF_EVEN)

UNNECESSARY(BigDecimal.ROUND_UNNECESSARY)

final int oldMode //舍入模式对应的代码

private RoundingMode(int oldMode) //返回与 BigDecimal 中遗留整数舍入模式常量对应的 RoundingMode 对象。

public static RoundingMode valueOf(int rm) //

public static RoundingMode valueOf(String name)

public static final RoundingMode[] values()

4、java.math.BigInteger

不可变的任意精度的整数。所有操作中,都以二进制补码形式表示 BigInteger (如 Java 的基本整数类型)。

提供Math下的方法、模算术、GCD 计算、质数测试、素数生成、位操作等public class BigInteger extends Number implements Comparable

int signum //符号位

int[] mag //The magnitude of this BigInteger, in big-endian order private int bitCount = -1 //The bitCount of this BigInteger

private int bitLength = -1 //The bitLength of this BigInteger

private int lowestSetBit = -2 //The lowest set bit of this BigInteger private int firstNonzeroByteNum = -2 //The index of the lowest-order byte in the magnitude of this BigInteger

private int firstNonzeroIntNum = -2 //The index of the lowest-order int in the magnitude of this BigInteger

private final static long LONG_MASK = 0xffffffffL //无符号数的掩码

public BigInteger(byte[] val) //将包含 BigInteger 的二进制补码表示形式的 byte 数组转换为 BigInteger。

private BigInteger(int[] val)

public BigInteger(int signum, byte[] magnitude) //将 BigInteger 的符号-数量表示形式转换为 BigInteger。

private BigInteger(int signum, int[] magnitude)

public BigInteger(String val, int radix) //将指定基数的 BigInteger 的字符串表示形式转换为 BigInteger。

private static long bitsPerDigit[] = { 0, 0,

1024, 1624, 2048, 2378, 2648, 2875, 3072, 3247, 3402, 3543, 3672, 3790, 3899, 4001, 4096, 4186, 4271, 4350, 4426, 4498, 4567, 4633, 4696, 4756, 4814, 4870, 4923, 4975, 5025, 5074, 5120, 5166, 5210, 5253, 5295}

private static void destructiveMulAdd(int[] x, int y, int z)

public BigInteger(String val) //将 BigInteger 的十进制字符串表示形式转换为 BigInteger。

public BigInteger(int numBits, Random rnd) //构造一个随机生成的BigInteger,它是在 0 到 (2numBits – 1)(包括)范围内均匀分布的值。private static byte[] randomBits(int numBits, Random rnd)

public BigInteger(int bitLength, int certainty, Random rnd) //构造一个随机生成的正 BigInteger,它可能是一个具有指定 bitLength 的素数。

private static final int SMALL_PRIME_THRESHOLD = 95

private static final int DEFAULT_PRIME_CERTAINTY = 100

public static BigInteger probablePrime(int bitLength, Random rnd) //

返回有可能是素数的、具有指定长度的正 BigInteger。

private static BigInteger smallPrime(int bitLength, int certainty, Random rnd)

private static final BigInteger SMALL_PRIME_PRODUCT =

valueOf(3L*5*7*11*13*17*19*23*29*31*37*41)

private static BigInteger largePrime(int bitLength, int certainty, Random rnd)

public BigInteger nextProbablePrime()//返回大于此 BigInteger 的可能为

素数的第一个整数。

boolean primeToCertainty(int certainty, Random random)

private boolean passesLucasLehmer()

private static int jacobiSymbol(int p, BigInteger n)

private static BigInteger lucasLehmerSequence(int z, BigInteger k, BigInteger n)

private static volatile Random staticRandom

private static Random getSecureRandom()

private boolean passesMillerRabin(int iterations, Random rnd)

private BigInteger(int[] magnitude, int signum)

private BigInteger(byte[] magnitude, int signum)

public static BigInteger valueOf(long val) //返回其值等于指定 long 的值的 BigInteger。

private BigInteger(long val)

private static BigInteger valueOf(int val[])

private final static int MAX_CONSTANT = 16;

private static BigInteger posConst[] = new BigInteger[MAX_CONSTANT+1]; private static BigInteger negConst[] = new BigInteger[MAX_CONSTANT+1]; static {//Initialize static constant array when class is loaded.

for (int i = 1; i <= MAX_CONSTANT; i++) {

int[] magnitude = new int[1];

magnitude[0] = (int) i;

posConst[i] = new BigInteger(magnitude, 1);

negConst[i] = new BigInteger(magnitude, -1);

}

}

public static final BigInteger ZERO = new BigInteger(new int[0], 0) //0 public static final BigInteger ONE = valueOf(1) //1

private static final BigInteger TWO = valueOf(2) //2

public static final BigInteger TEN = valueOf(10) //10

public BigInteger add(BigInteger val) //加

private static int[] add(int[] x, int[] y) //Adds the contents of the int arrays x and y.

public BigInteger subtract(BigInteger val) //减

private static int[] subtract(int[] big, int[] little)

public BigInteger multiply(BigInteger val)

private int[] multiplyToLen(int[] x, int xlen, int[] y, int ylen, int[] z) //Multiplies int arrays x and y to the specified lengths places the result into z.

private BigInteger square()

private static final int[] squareToLen(int[] x, int len, int[] z) public BigInteger divide(BigInteger val) //商

public BigInteger[] divideAndRemainder(BigInteger val) //商、余数public BigInteger remainder(BigInteger val) //余数

public BigInteger pow(int exponent) //次方

public BigInteger gcd(BigInteger val) //最大公约数

private static int[] leftShift(int[] a, int len, int n) //左移<< static void primitiveRightShift(int[] a, int len, int n) //右移>>> static void primitiveLeftShift(int[] a, int len, int n)

private static int bitLength(int[] val, int len)

public BigInteger abs() //绝对值

public BigInteger negate() //相反数

public int signum() //符号

public BigInteger mod(BigInteger m) //取余数

public BigInteger modPow(BigInteger exponent, BigInteger m) //指数模m

static int[] bnExpModThreshTable = {7, 25, 81, 241, 673,

1793,Integer.MAX_VALUE}

private BigInteger oddModPow(BigInteger y, BigInteger z) //whose value is x to the power of y mod z

private static int[] montReduce(int[] n, int[] mod, int mlen, int inv) //Montgomery reduce n, modulo mod.

private static int intArrayCmpToLen(int[] arg1, int[] arg2, int len) //Returns -1, 0 or +1

private static int subN(int[] a, int[] b, int len) //Subtracts two numbers of same length

static int mulAdd(int[] out, int[] in, int offset, int len, int k)

//Multiply an array by one word k and add to result

static int addOne(int[] a, int offset, int mlen, int carry) //Add one word to the number a mlen words into a.

private BigInteger modPow2(BigInteger exponent, int p) //(this ** exponent) mod (2**p)

private BigInteger mod2(int p) //this mod(2**p)

public BigInteger modInverse(BigInteger m) //(this-1 mod m)

public BigInteger shiftLeft(int n) //左移

public BigInteger shiftRight(int n) //右移

public BigInteger and(BigInteger val) //与this & val

public BigInteger or(BigInteger val) //或this | val

public BigInteger xor(BigInteger val) //异或this ^ val

public BigInteger not() //非 ~this

public BigInteger andNot(BigInteger val) //与非 this &~ val

public boolean testBit(int n) //当且仅当设置了指定的位时,返回 true。public BigInteger setBit(int n) //返回其值与设置了指定位的此 BigInteger 等效的 BigInteger。

public BigInteger clearBit(int n) //返回其值与清除了指定位的此BigInteger 等效的 BigInteger。

public BigInteger flipBit(int n) //this ^ (1<

public int getLowestSetBit() //此 BigInteger 最右端(最低位)1 比特的索引

public int bitLength() //此 BigInteger 的最小的二进制补码表示形式的位数

static int bitLen(int w)

final static byte trailingZeroTable[]

public int bitCount() //二进制补码表示形式中与符号不同的位的数量。static int bitCnt(int val)

static int trailingZeroCnt(int val)

public boolean isProbablePrime(int certainty) // BigInteger 可能为素数public int compareTo(BigInteger val) //比较

private static int intArrayCmp(int[] arg1, int[] arg2)

public boolean equals(Object x) //相等

public BigInteger min(BigInteger val) //取小

public BigInteger max(BigInteger val) //取大

public int hashCode() //hash值

public String toString(int radix) //转换成进制

public String toString() //转换成10进制

public byte[] toByteArray() //字节数组

public int intValue()

public long longValue()

public float floatValue()

public double doubleValue()

private static int[] stripLeadingZeroInts(int val[])

private static int[] trustedStripLeadingZeroInts(int val[])

private static int[] stripLeadingZeroBytes(byte a[])

private static int[] makePositive(byte a[])

private static int[] makePositive(int a[])

private static int digitsPerLong[]

private static BigInteger longRadix[]

private static int digitsPerInt[]

private static int intRadix[]

private int intLength()

private int signBit()

private int signInt()

private int getInt(int n)

private int firstNonzeroIntNum()

private static final long serialVersionUID = -8287574255936472291L

private static final ObjectStreamField[] serialPersistentFields private void readObject(java.io.ObjectInputStream s)

private void writeObject(ObjectOutputStream s)

private byte[] magSerializedForm()

5、java.math.BitSieve

字节过滤类,

class BitSieve

private long bits[] //存储bit过滤Stores the bits in this bitSieve. private int length //Length is how many bits this sieve holds.

private static BitSieve smallSieve = new BitSieve() //A small sieve used to filter out multiples of small primes in a search sieve.

private BitSieve()

BitSieve(BigInteger base, int searchLen) //Construct a bit sieve of searchLen bits used for finding prime number candidates.

private static int unitIndex(int bitIndex) //Given a bit index return unit index containing it.

private static long bit(int bitIndex) //Return a unit that masks the specified bit in its unit.

private boolean get(int bitIndex) //Get the value of the bit at the specified index.

private void set(int bitIndex) //Set the bit at the specified index. private int sieveSearch(int limit, int start) //returns the index of the first clear bit in the search array

private void sieveSingle(int limit, int start, int step) //Sieve a single set of multiples out of the sieve.

BigInteger retrieve(BigInteger initValue, int certainty,

java.util.Random random) //Test probable primes in the sieve and return successful candidates.

6、java.math.MutableBigInteger

可变的BigInteger

class MutableBigInteger

int[] value

int intLen

int offset = 0

private final static long LONG_MASK = 0xffffffffL

MutableBigInteger()

MutableBigInteger(int val)

MutableBigInteger(int[] val, int len)

MutableBigInteger(int[] val)

MutableBigInteger(BigInteger b)

MutableBigInteger(MutableBigInteger val)

void clear()

void reset()

final int compare(MutableBigInteger b) //比较

private final int getLowestSetBit()

private final int getInt(int index)

private final long getLong(int index)

final void normalize()

private final void ensureCapacity(int len)

int[] toIntArray()

void setInt(int index, int val)

void setValue(int[] val, int length)

void copyValue(MutableBigInteger val)

void copyValue(int[] val)

boolean isOne()

boolean isZero()

boolean isEven()

boolean isOdd()

boolean isNormal()

public String toString()

void rightShift(int n)

void leftShift(int n)

private int divadd(int[] a, int[] result, int offset)

private int mulsub(int[] q, int[] a, int x, int len, int offset)

private final void primitiveRightShift(int n)

private final void primitiveLeftShift(int n)

void add(MutableBigInteger addend)

int subtract(MutableBigInteger b)

private int difference(MutableBigInteger b)

void multiply(MutableBigInteger y, MutableBigInteger z)

void mul(int y, MutableBigInteger z)

void divideOneWord(int divisor, MutableBigInteger quotient)

void divide(MutableBigInteger b,MutableBigInteger quotient, MutableBigInteger rem)

private boolean unsignedLongCompare(long one, long two)

private void divWord(int[] result, long n, int d)

MutableBigInteger hybridGCD(MutableBigInteger b) //Calculate GCD of this and b.

private MutableBigInteger binaryGCD(MutableBigInteger v) //Calculate GCD of this and v.

static int binaryGcd(int a, int b) //Calculate GCD of a and b interpreted as unsigned integers.

MutableBigInteger mutableModInverse(MutableBigInteger p) //the modInverse of this mod p.

MutableBigInteger modInverseMP2(int k) // inverse of this mod 2^k static int inverseMod32(int val) //inverse of val mod 2^32

static MutableBigInteger modInverseBP2(MutableBigInteger mod, int k) //inverse of 2^k mod mod

private MutableBigInteger modInverse(MutableBigInteger mod)

static MutableBigInteger fixup(MutableBigInteger c, MutableBigInteger p,int k) //X = C * 2^(-k) (mod P)

MutableBigInteger euclidModInverse(int k) //mod a modulus that is a power of 2

7、java.math.SignedMutableBigInteger

有符号的可变的BigInteger

class SignedMutableBigInteger extends MutableBigInteger

int sign = 1

SignedMutableBigInteger()

SignedMutableBigInteger(int val)

SignedMutableBigInteger(MutableBigInteger val)

方法:

void signedAdd(SignedMutableBigInteger addend) //加

void signedAdd(MutableBigInteger addend) //加

void signedSubtract(SignedMutableBigInteger addend) //减void signedSubtract(MutableBigInteger addend) //减

public String toString()

相关文档