File: sophomore.c

package info (click to toggle)
sleef 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,564 kB
  • sloc: ansic: 49,154; cpp: 6,095; makefile: 38
file content (25 lines) | stat: -rw-r--r-- 611 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>

#define SLEEF_ENABLE_OMP_SIMD
#include "sleef.h"

#define N 65536
#define M (N + 3)

static double func(double x) { return Sleef_pow_u10(x, -x); }

double int_simpson(double a, double b) {
   double h = (b - a) / M;
   double sum_odd = 0.0, sum_even = 0.0;
   for(int i = 1;i <= M-3;i += 2) {
     sum_odd  += func(a + h * i);
     sum_even += func(a + h * (i + 1));
   }
   return h / 3 * (func(a) + 4 * sum_odd + 2 * sum_even + 4 * func(b - h) + func(b));
}

int main() {
  double sum = 0;
  for(int i=1;i<N;i++) sum += Sleef_pow_u10(i, -i);
  printf("%g %g\n", int_simpson(0, 1), sum);
}