Skip to content

Instantly share code, notes, and snippets.

@tadd
Created August 2, 2010 14:08
Show Gist options
  • Select an option

  • Save tadd/504690 to your computer and use it in GitHub Desktop.

Select an option

Save tadd/504690 to your computer and use it in GitHub Desktop.
patch for ISBN4-87408-414-1 p.324
--- bernoull.c~ 1991-01-20 18:43:42.000000000 +0900
+++ bernoull.c 2010-08-02 23:06:40.000000000 +0900
@@ -21,6 +21,7 @@ int main()
int i, n;
double q, b1, b2, d;
static double t[N + 1];
+ int s = -1;
q = 1;
t[1] = 1;
@@ -29,13 +30,14 @@ int main()
t[n - 1] = 0;
for (i = n; i >= 2; i--) t[i] += t[i - 2];
if (n % 2 == 0) {
+ s = -s;
q *= 4;
b1 = n * t[0]; b2 = q * (q - 1);
if (b1 < 1 / DBL_EPSILON && b2 < 1 / DBL_EPSILON) {
d = gcd(b1, b2); b1 /= d; b2 /= d;
- printf("|B(%2d)| = %.0f/%.0f\n", n, b1, b2);
+ printf("|B(%2d)| = %.0f/%.0f\n", n, s * b1, b2);
} else
- printf("|B(%2d)| = %g\n", n, b1 / b2);
+ printf("|B(%2d)| = %g\n", n, s * b1 / b2);
}
}
return EXIT_SUCCESS;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment