Find Jobs
Hire Freelancers

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](); } }
项目 ID: 30814192

关于此项目

2提案
远程项目
活跃3 年前

想赚点钱吗?

在Freelancer上竞价的好处

设定您的预算和时间范围
为您的工作获得报酬
简要概述您的提案
免费注册和竞标工作
2威客以平均价$23 USD来参与此工作竞价
用户头像
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.
$20 USD 在7天之内
5.0 (7条评论)
3.2
3.2

关于客户

UNITED STATES的国旗
Milwaukee, United States
5.0
9
付款方式已验证
会员自3月 17, 2016起

客户认证

谢谢!我们已通过电子邮件向您发送了索取免费积分的链接。
发送电子邮件时出现问题。请再试一次。
已注册用户 发布工作总数
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
加载预览
授予地理位置权限。
您的登录会话已过期而且您已经登出,请再次登录。