feat: add wallis product
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
# math
|
# math
|
||||||
|
|
||||||
| Class | Comments | MuBoard Link |
|
| Class | Comments | MuBoard Link |
|
||||||
|--------------------------|--------------------|-----------------------------------------------------------------------------------------------------------------------------|
|
|-------------------------|--------------------|-----------------------------------------------------------------------------------------------------------------------------|
|
||||||
| ChineseRemainderTheorem | 中国剩余定理 | [chinese-remainder-theorem](https://hatter.ink/static/resource/muboard/?id=chinese-remainder-theorem&version=latest&full=1) |
|
| ChineseRemainderTheorem | 中国剩余定理 | [chinese-remainder-theorem](https://hatter.ink/static/resource/muboard/?id=chinese-remainder-theorem&version=latest&full=1) |
|
||||||
| EulerTheorem | 欧拉定理 | [euler-theorem](https://hatter.ink/static/resource/muboard/?id=euler-theorem&version=latest&full=1) |
|
| EulerTheorem | 欧拉定理 | [euler-theorem](https://hatter.ink/static/resource/muboard/?id=euler-theorem&version=latest&full=1) |
|
||||||
| ModularInv | 求乘法逆元【扩展欧几里得法】 | - |
|
| ModularInv | 求乘法逆元【扩展欧几里得法】 | - |
|
||||||
| Sqrt10 | 求 $\sqrt{10}$【连分数】 | [resolve-sqrt-10](https://hatter.ink/static/resource/muboard/?id=resolve-sqrt-10&version=latest&full=1) |
|
| Sqrt10 | 求 $\sqrt{10}$【连分数】 | [resolve-sqrt-10](https://hatter.ink/static/resource/muboard/?id=resolve-sqrt-10&version=latest&full=1) |
|
||||||
|
| WallisProduct | 沃里斯乘积 | [wallis-product](https://hatter.ink/static/resource/muboard/?id=wallis-product&version=latest&full=1) |
|
||||||
|
|
||||||
|
|||||||
26
src/main/java/me/hatter/math/WallisProduct.java
Normal file
26
src/main/java/me/hatter/math/WallisProduct.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package me.hatter.math;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
|
public class WallisProduct {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 3.1415925750499739534746260502048989270653181072075621931977986489848855062212872415726332946132240849
|
||||||
|
System.out.println(pi());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BigDecimal pi() {
|
||||||
|
BigDecimal p = BigDecimal.valueOf(2);
|
||||||
|
for (long i = 1; i < 10000000; i++) {
|
||||||
|
BigDecimal doubleI = BigDecimal.valueOf(i * 2);
|
||||||
|
p = p.multiply(
|
||||||
|
doubleI.divide(doubleI.subtract(BigDecimal.ONE), 100, RoundingMode.FLOOR)
|
||||||
|
).multiply(
|
||||||
|
doubleI.divide(doubleI.add(BigDecimal.ONE), 100, RoundingMode.FLOOR)
|
||||||
|
);
|
||||||
|
p = p.divide(BigDecimal.ONE, 100, RoundingMode.FLOOR);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user