pi.ino 563 Bytes
Newer Older
Neil Gershenfeld's avatar
Neil Gershenfeld committed
1
2
3
4
5
6
7
8
9
10
/*
* pi.ino
* Neil Gershenfeld 12/20/20
* pi calculation benchmark
* pi = 3.14159265358979323846
*/

#define NPTS 1000000

int i;
Neil Gershenfeld's avatar
wip    
Neil Gershenfeld committed
11
float a,b,c,pi,dt,mflops;
Neil Gershenfeld's avatar
Neil Gershenfeld committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
unsigned long tstart,tend;

void setup() {
   Serial.begin(115200);
   }

void loop() {
   tstart = millis();
   a = 0.5;
   b = 0.75;
   c = 0.25;
   pi = 0;
   for (i = 1; i <= NPTS; ++i)
      pi += a/((i-b)*(i-c));
   tend = millis();
   dt = (tend-tstart)/1000.0;
   mflops = NPTS*5.0/(dt*1e6);
   printf("NPTS = %d, pi = %f\n",NPTS,pi);
   printf("time = %f, estimated MFlops = %f\n",dt,mflops);
   }