从底层重学 Java 之 BigInteger 大整数 Gitchat连接
生活随笔
收集整理的這篇文章主要介紹了
从底层重学 Java 之 BigInteger 大整数 Gitchat连接
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Gitchat連接
https://gitbook.cn/gitchat/activity/5f395a80aced402379f6a0ca
簡介
從底層,從原理,我們來重學一次 Java。BigInteger 是大整數計算類,是BigDecimal用于存儲大數屬性的類型,BigDecimal中很多計算就是基于BigInteger的函數進行計算的,采用了多種優化的算法實現,他的源碼及實現是怎樣的呢?
本系列秉承所有結論盡量從源碼中來,沒有源碼的盡量標明出處。相關源碼會附著在文章中,讀本文即可,不用再自行查找源碼及資料學習,方便大家充分利用路上的碎片時間。
本篇 Chat 對BigInteger的屬性、構造函數、四則運算、位移等進行逐一源碼分析,幫助大家深入理解和學習 JDK 源碼的牛掰優化。
本文包含以下內容:
- 類信息
- 類的定義
- 類的繼承結構
- 靜態代碼塊
- 靜態代碼塊1及相關的常量
- MAX_CONSTANT
- posConst
- negConst
- 靜態代碼塊2及相關的常量
- zeros
- 靜態代碼塊1及相關的常量
- 常量
- 屬性
- signum
- mag
- 構造函數
- BigInteger(int[] magnitude, int signum)
- BigInteger.ZERO
- 三個靜態數組
- bitsPerDigit
- digitsPerInt
- intRadix
- BigInteger(String val)
- private BigInteger(long val)
- 四則運算
- 加
- add(BigInteger val)
- int compareMagnitude(BigInteger val)
- int[] add(int[] x, int[] y)
- int[] subtract(int[] big, int[] little)
- 減
- 乘
- BigInteger multiply(BigInteger val)
- BigInteger multiply(BigInteger val, boolean isRecursion)
- BigInteger multiplyByInt(int[] x, int y, int sign)
- int[] multiplyToLen(int[] x, int xlen, int[] y, int ylen, int[] z)
- Karatsuba算法
- 實現原理
- BigInteger multiplyKaratsuba(BigInteger x, BigInteger y)
- BigInteger getLower(int n)
- BigInteger getUpper(int n)
- BigInteger abs()
- Integer.numberOfLeadingZeros()
- Toom-Cook 3路算法
- BigInteger multiplyToomCook3(BigInteger a, BigInteger b)
- BigInteger getToomSlice(int lowerSize, int upperSize, int slice,int fullsize)
- exactDivideBy3
- 平方計算
- implSquareToLen
- squareKaratsuba
- squareToomCook3
- 除
- BigInteger divide(BigInteger val)
- Knuth算法
- MutableBigInteger
- MutableBigInteger.divideKnuth
- divideOneWord
- divideMagnitude
- Integer.numberOfTrailingZeros
- copyAndShift
- Burnikel-Ziegler算法
- 算法文章
- 第一步計算
- divide2n1n
- divide3n2n
- divideAndRemainderBurnikelZiegler主算法
- Arrays.fill
- 加
- 位運算
- 左移
- 右移
- valueOf
- 其他計算及比較
- BigInteger abs()
適用人群:有一些 Java 基礎的人群。
總結
以上是生活随笔為你收集整理的从底层重学 Java 之 BigInteger 大整数 Gitchat连接的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android NFC标签读写 配置 过
- 下一篇: 练习2-1 Programming in