Created
November 20, 2009 11:15
-
-
Save yuroyoro/239431 to your computer and use it in GitHub Desktop.
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
//ガウス=ルジャンドルのアルゴリズム | |
// あとでBigDecimalになおす | |
def calcPI( ac:Int ):Double = { | |
def stop_?( d:Double ) = d.toString.length > ac + 2 | |
def calc( a:Double , b:Double, t:Double, p:Double ):Double = { | |
println("%f, %f, %f, %f".format( a, b, t, p ) ) | |
if( stop_?( a ) && stop_?( b ) ) Math.pow( a + b , 2) / (4 * t) | |
else{ | |
val x = ( a + b ) / 2 | |
val y = Math.sqrt( a * b ) | |
val t2 = t - p * Math.pow( a - x, 2 ) | |
calc( x, y, t2, p * 2 ) | |
} | |
} | |
calc( 1, Math.sqrt( 0.5 ), 0.25, 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment