fix bounds + update libs
This commit is contained in:
parent
828ebb23c0
commit
bc58da6d49
5 changed files with 59 additions and 50 deletions
|
|
@ -7,19 +7,19 @@
|
|||
terms := 1000000
|
||||
|
||||
# The running sum of terms
|
||||
tot := 0
|
||||
tot := 0.0
|
||||
|
||||
n := 1
|
||||
while n <= terms {
|
||||
tot = tot + 1 / (n*n)
|
||||
tot = tot + 1.0/float(n*n)
|
||||
n = n + 1
|
||||
}
|
||||
|
||||
tot = tot * 6
|
||||
tot = tot * 6.0
|
||||
|
||||
# get the absolute value of a number
|
||||
func abs(x: number) number {
|
||||
if x < 0 {
|
||||
fn abs(x: float) -> float {
|
||||
if x < 0.0 {
|
||||
return -x
|
||||
}
|
||||
return x
|
||||
|
|
@ -30,19 +30,19 @@ func abs(x: number) number {
|
|||
# see: https://en.wikipedia.org/wiki/Newton's_method
|
||||
# The required accuracy
|
||||
SQRT_ACC := 0.00000001
|
||||
func sqrt(x: number) number {
|
||||
pg := 0 # previous guess
|
||||
g := 1 # current guess
|
||||
fn sqrt(x: float) -> float {
|
||||
pg := 0.0 # previous guess
|
||||
g := 1.0 # current guess
|
||||
|
||||
while abs(pg - g) >= SQRT_ACC {
|
||||
pg = g
|
||||
g = (pg + tot/pg)/2
|
||||
g = (pg + x/pg)/2.0
|
||||
}
|
||||
|
||||
return g
|
||||
}
|
||||
|
||||
tot = sqrt(tot)
|
||||
pi := sqrt(tot)
|
||||
|
||||
# output the result
|
||||
write(str(tot))
|
||||
println(pi)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue