Calculate PI Digits with P5.JS / JavaScript - Looking for maximum efficiency
$20-30 USD
已关闭
已发布将近 3 年前
$20-30 USD
货到付款
Hi,
I am working on a project in [login to view URL] /JavaScript and I need the ability to calculate PI digits starting at the beginning and going for as long as possible.
Currently, I am using the Spigot Algorithm that can be found here:
[login to view URL]
This code works but after a day of it running non-stop it begins to slow down because it takes more and more CPU calculations to generate the next digit of PI(I believe), and this in turn slows the [login to view URL] program that is using the digits of PI. I believe BigInt is part of the reason it gets slower as time goes on.
So, I'm looking for a more efficient way to generator each digit of PI and I've heard there are two major ways to do this: one is CPU intensive and the second is more memory intensive? If this is true, I would like a method that is more memory intensive because the [login to view URL] program needs CPU power to run well; and memory is more abundant on PC these days, but of course if the PI generator uses all the PC's RAM in a day, that's not a better solution than I currently have.
Is there a memory intensive way to generate PI? Is it as good as or better than the Spigot Algorithm
If not, is there a better way to generate PI other than the Spigot Algorithm?
If so will this method run longer, before there is noticeable speed loss?
I want to be able to generate PI for as long as possible with as little CPU loss a possible.
Here is the [login to view URL] code I have that uses the Spigot Algorithm:
let piBuffer;
function setup() {
createCanvas(400, 400);
piBuffer = new PiBuffer();
[login to view URL](0);
frameRate(30);
}
function draw() {
print('NextPiDigit = ' + [login to view URL]());
}
class PiBuffer {
constructor() {
this.q = BigInt(1);
this.r = BigInt(180);
this.t = BigInt(60);
this.i = BigInt(2);
// y is the previous digit
this.y
this.u
[login to view URL] = [];
}
// Caluculate the next numDigits of Pi
async calculatePi(loopDelay) {
while(true){
await new Promise(resolve => {
setTimeout(() => {
resolve(true);
[login to view URL]([login to view URL]());
}, loopDelay);
});
}
}
calculateNextPiDigit() {
// Spigot Method of calculating Pi
this.y = (this.q*(BigInt(27)*this.i-BigInt(12))+BigInt(5)*this.r)/(BigInt(5)*this.t);
this.u = BigInt(3)*(BigInt(3)*this.i+BigInt(1))*(BigInt(3)*this.i+BigInt(2));
this.r = BigInt(10)*this.u*(this.q*(BigInt(5)*this.i-BigInt(2))+this.r-this.y*this.t);
this.q = BigInt(10)*this.q*this.i*(BigInt(2)*this.i-BigInt(1));
this.t = this.t*this.u;
this.i = this.i+BigInt(1);
if (this.i % BigInt(1000) === BigInt(0)){
print("Current Digit=" + this.i);
}
return this.y
}
getNextPiDigit() {
return [login to view URL]();
}
}
Hi, Dear.
I am a c/c++ expert and have a lot experience.
And I have an excellent team.
Your project is right for me.
If you select me for your project, you will necessarily success.
High quality, fast delivery and friendly service is promised for you.
Best regard.