Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4500635
pi.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
624 B
Referenced Files
None
Subscribers
None
pi.js
View Options
const
iterations
=
1
_000_000
;
function
calculatePiLeibniz
()
{
let
pi
=
0
;
let
denom
=
1
;
const
limit
=
iterations
-
(
iterations
%
4
);
for
(
let
i
=
0
;
i
<
limit
;
i
+=
4
)
{
pi
+=
1
/
denom
-
1
/
(
denom
+
2
)
+
1
/
(
denom
+
4
)
-
1
/
(
denom
+
6
);
denom
+=
8
;
}
let
sign
=
1
;
for
(
let
i
=
limit
;
i
<
iterations
;
i
++
)
{
pi
+=
sign
/
denom
;
sign
=
-
sign
;
denom
+=
2
;
}
return
pi
*
4
;
}
const
start
=
performance
.
now
();
const
result
=
calculatePiLeibniz
();
const
end
=
performance
.
now
();
console
.
log
(
`Pi (
${
iterations
}
) ≈
${
result
}
`
);
console
.
log
(
`Time:
${
(
end
-
start
).
toFixed
(
2
)
}
ms`
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, May 3, 8:27 AM (1 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
517928
Default Alt Text
pi.js (624 B)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment