KISS MY ASCII GOOD PI!
#18
Your endless string formulas are too complicated and cumbersome. There I get headdache.  Angry

If one implement the formulas it is short and concise.  Wink  I have now implemented a guide for C++ (running) in C. It's Chudnovsky's formula for pi, but it won't work in QB64. Does anyone see where the error is? - I suspect it has to do with "pi += ..." - maybe.

Chudnovskys Pi formula in C
Code: (Select All)
//PI nach Cudnowsky - https://stackoverflow.com/questions/12028313/c-chudnovsky-formula-for-pi
//24. Aug. 2022, in C 25. Aug. 2022

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

long double fac(double num);

int main(void)
{
  long double pi = 0.0;
 
    for (double k = 0.0; k < 10.0; k++)
    {
    pi += (pow(-1.0, k) * fac(6.0 * k) * (13591409.0 + (545140134.0 * k)))
       / (fac(3.0 * k) * pow(fac(k), 3.0) * pow(640320.0, 3.0 * k + 3.0/2.0));        
  }
  pi *= 12.0;
    __mingw_printf("%.12Lf\n\n", 1.0 / pi);
 
  return 0;
}

long double fac(double num)
{
    double result = 1.0;
  for (double i = 2.0; i < num; i++)
        { result *= i; }
  return result;
}

That has to be! Unfortunately there is no explanation why.
Code: (Select All)
__mingw_printf("%.12Lf\n\n", 1.0 / pi);

Chudnovskys Pi formula in QB64
Code: (Select All)
'Pi nach Chudnovsky berechnen - 25. Aug. 2022

Option _Explicit

Declare Function fac (num as Double) as Double

Dim As Double pi, k

pi = 0.0: k = 0.0
While k < 10.0
  k = k + 1.0
  pi = pi + (-1.0 ^ k) * fac(6.0 * k) * (13591409.0 + (545140134.0 * k)) / fac(3.0 * k) * fac(k) ^ 3.0 * 640320.0 ^ 3.0 * k + (3.0 / 2.0)
  'pi = pi + pi
Wend
pi = pi * 12.0

Print
Print 1.0 / pi

End

Function fac (num As Double)

  Dim As Double resultat, i
  resultat = 1.0: i = 2.0

  While i < num
    i = i + i
    resultat = resultat * i
  Wend
  fac = resultat

End Function
Reply


Messages In This Thread
KISS MY ASCII GOOD PI! - by Pete - 08-22-2022, 09:43 AM
RE: KISS MY ASCII GOOD PI! - by Kernelpanic - 08-22-2022, 12:23 PM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-22-2022, 02:25 PM
RE: KISS MY ASCII GOOD PI! - by Kernelpanic - 08-22-2022, 03:37 PM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-22-2022, 03:49 PM
RE: KISS MY ASCII GOOD PI! - by Kernelpanic - 08-22-2022, 03:57 PM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-22-2022, 06:37 PM
RE: KISS MY ASCII GOOD PI! - by Kernelpanic - 08-22-2022, 09:17 PM
RE: KISS MY ASCII GOOD PI! - by Kernelpanic - 08-22-2022, 10:42 PM
RE: KISS MY ASCII GOOD PI! - by SMcNeill - 08-22-2022, 10:56 PM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-24-2022, 12:28 AM
RE: KISS MY ASCII GOOD PI! - by Jack - 08-22-2022, 11:44 PM
RE: KISS MY ASCII GOOD PI! - by SMcNeill - 08-22-2022, 11:51 PM
RE: KISS MY ASCII GOOD PI! - by Jack - 08-24-2022, 01:27 AM
RE: KISS MY ASCII GOOD PI! - by Jack - 08-24-2022, 02:20 AM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-25-2022, 02:06 AM
RE: KISS MY ASCII GOOD PI! - by Jack - 08-25-2022, 11:43 AM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-25-2022, 08:50 PM
RE: KISS MY ASCII GOOD PI! - by Kernelpanic - 08-25-2022, 04:41 PM
RE: KISS MY ASCII GOOD PI! - by mnrvovrfc - 08-25-2022, 08:12 PM
RE: KISS MY ASCII GOOD PI! - by Kernelpanic - 08-25-2022, 09:37 PM
RE: KISS MY ASCII GOOD PI! - by Jack - 08-26-2022, 12:50 AM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-26-2022, 03:16 AM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-26-2022, 03:39 PM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-26-2022, 04:14 PM
RE: KISS MY ASCII GOOD PI! - by Jack - 08-26-2022, 04:24 PM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-26-2022, 04:46 PM
RE: KISS MY ASCII GOOD PI! - by Jack - 08-26-2022, 05:31 PM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-26-2022, 07:50 PM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-26-2022, 08:36 PM
RE: KISS MY ASCII GOOD PI! - by Jack - 08-26-2022, 08:48 PM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-26-2022, 09:36 PM
RE: KISS MY ASCII GOOD PI! - by Pete - 08-27-2022, 05:24 AM



Users browsing this thread: 8 Guest(s)