Java jdk源代码的Math包(2)

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 //用来表示的最少字符Maximumis Integer.MAX_VALUE
 private static final long serialVersionUID = 5579720004786848255L //序列化版本号
 
public static final MathContext UNLIMITED =newMathContext(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 java.lang.String toString() //”precision=” + precision + ” ” +“roundingMode=” +    roundingMode.toString()
 
private synchronized void readObject(java.io.ObjectInputStreams)
 
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<BigInteger>
 
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 inthe magnitude of this BigInteger
 private int firstNonzeroIntNum = -2 //The index of the lowest-order int in themagnitude 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, intz)
 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, intcertainty, 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, BigIntegern)
 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(newint[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 intarrays 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 intoz.
 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, intn)  //左移<<
 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 tothe 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 ofsame length
 static int mulAdd(int[] out, int[] in, int offset, int len, int k) //Multiplyan array by one word k and add to result
 static int addOne(int[] a, int offset, int mlen, int carry) //Add one word tothe 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<<n)
 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()

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/3ee35690b3a0cc949d38cc9fd22db142.html