pi

Calculating PI with BigDecimal

∥☆過路亽.° 提交于 2021-02-10 20:20:44
问题 This is my first time using a BigDecimal and I am having some troubles with it. Here is my code: import java.math.BigDecimal; public class Test { public static void main(String[] args) { BigDecimal pi = new BigDecimal(4); boolean plus = false; for (int i = 3; i < 1000000; i += 2) { if (plus) { pi.add(new BigDecimal(4).divide(new BigDecimal(i), 2, BigDecimal.ROUND_HALF_UP)); } else { pi.subtract(new BigDecimal(4).divide(new BigDecimal(i), 2, BigDecimal.ROUND_HALF_UP)); } plus = !plus; } System

Borwein’s algorithm for the calculation of Pi in Fortran is converging too fast

半城伤御伤魂 提交于 2021-01-29 18:39:25
问题 The following implementation of Borwein’s algorithm with quartic convergence in Fortran admittedly calculates Pi, but converges simply too fast. In theory, a converges quartically to 1/π. On each iteration, the number of correct digits is therefore quadrupled. ! pi.f90 program main use, intrinsic :: iso_fortran_env, only: real128 implicit none real(kind=real128), parameter :: CONST_PI = acos(-1._real128) real(kind=real128) :: pi integer :: i do i = 1, 10 pi = borwein(i) print '("Pi (n = ", i3

Building multi-architecture docker images with Skaffold

家住魔仙堡 提交于 2021-01-29 17:12:11
问题 I've been able to get two awesome technologies to work independently. Skaffold BuildX Unfortunatly I don't know how to use them both at the same time. I'm currently building and testing on my laptop (amd), then deploying to a Raspberri Pi 4 (arm64) running Kubernetes. To get this working I use something like: docker buildx build --platform linux/amd64,linux/arm64 --tag my-registry/my-image:latest --push . Before attempting to target an arm I was using skaffold. Is there any way to continue to

Why is incorrect value of pi output?

点点圈 提交于 2021-01-28 07:50:29
问题 I'm trying to calculate pi using following code that uses Chudnovsky algorithm. When $n is increased, then number of digits after the decimal point. However when $n is small, it can calculate correct value of pi (3.141592...) is output, but when $n is increased, it calculate incorrect value of pi. Why? #!/usr/bin/perl use strict; use warnings; use GMP qw(:all); use GMP::Mpf qw(:all); use GMP::Mpz qw(:all); use GMP::Mpq qw(:all); my $n = shift; $n = $n<7?7:$n; $n *= 8; my $l = int($n/7) + 1;

Are there number limitations in python?

筅森魡賤 提交于 2021-01-27 01:41:07
问题 I have made a Python 3 program to calculate pi for a school project, but it always stops at 16 decimal places. Is there a limit to the length of numbers in python? If so is there a language that I could use that will let me continue? accuracy = int(input("accuracy: ")) current = 2 opperation = "+" number = 3 count = 1 for i in range (accuracy): if opperation == "-": number = number - (4/(current*(current+1)*(current+2))) opperation = "+" elif opperation == "+": number = number + (4/(current*

The Chudnovsky Formula in Python

谁说我不能喝 提交于 2021-01-24 09:30:42
问题 I'm trying to implement the Chudnovsky algorithm for calculating pi. I am using formulas from this description https://www.craig-wood.com/nick/articles/pi-chudnovsky/ Now it's working, but maximum number of digits it can show is 3.141592653589793238462643385 - only 27 digits. Why does Python limits the number of digits in this script? May be i am using Decimal in wrong way? Here is my code (updated): from decimal import Decimal, getcontext from math import factorial import sys def calculate