Created
August 19, 2019 02:07
-
-
Save miya0001/15e1ba9d1f51b91c42893aaccd68c08e to your computer and use it in GitHub Desktop.
Node + ピタゴラスの定理を使って円周率を計算する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const max = 1000000000; | |
let n = 6 | |
let side1 = 0 | |
let side2 = 1 | |
let side3 = 1 | |
for ( let i = n; i <= max; i = i * 2 ) { | |
side1 = 1 - Math.sqrt( 1 - ( side3 / 2 ) ** 2 ) | |
side2 = side3 / 2 | |
side3 = Math.sqrt( side1 ** 2 + side2 ** 2 ) | |
console.log( `${i * 2}: ${side3 * i}` ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
6角系から順番に倍々にしていって約16億角形まで計算して、円周率を求めるサンプル。
この例では小数点以下16位までしか計算できない。
動作例: