Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef unsigned int u32;
- double canonical_div(u32 interations) {
- double rv = 0;
- for (u32 x=1; x<interations; x++) {
- rv += 1.0/x;
- }
- return rv;
- }
- #define M (2U * 1024*1024*1024)
- double fast_div(u32 interations) {
- double rv = 0;
- double *prev = malloc(M);
- for (u32 x=1; x<interations; x++) {
- prev[x] = 1.0/x;
- rv += prev[x];
- x++;
- prev[x] = 0.5 * prev[x>>1];
- rv += prev[x];
- }
- return rv;
- }
- int main() {
- printf("%.12f\n", canonical_div(M/8));
- //~ printf("%.12f\n", fast_div(M/8));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment