2016-04-26 17:20:05 +02:00
|
|
|
/*
|
2013-02-18 07:59:48 +01:00
|
|
|
Copyright (C) 2013 Fredrik Johansson
|
|
|
|
|
2016-04-26 17:20:05 +02:00
|
|
|
This file is part of Arb.
|
|
|
|
|
|
|
|
Arb is free software: you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2013-02-18 07:59:48 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "bernoulli.h"
|
|
|
|
|
|
|
|
double log2bern_approx(double n)
|
|
|
|
{
|
|
|
|
return 1 + ((n+0.5)*log(n) - n - (n-0.5)*log(2*3.14159265358979323)) * (1. / log(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2015-11-05 18:01:09 +00:00
|
|
|
slong i, bound;
|
2013-02-18 07:59:48 +01:00
|
|
|
double a, b;
|
|
|
|
fmpq_t q;
|
|
|
|
fmpr_t t;
|
|
|
|
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("bound_2exp_si....");
|
2013-02-18 07:59:48 +01:00
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
fmpq_init(q);
|
|
|
|
fmpr_init(t);
|
|
|
|
|
|
|
|
for (i = 0; i < 1000; i++)
|
|
|
|
{
|
|
|
|
arith_bernoulli_number(q, i);
|
|
|
|
bound = bernoulli_bound_2exp_si(i);
|
|
|
|
|
|
|
|
fmpr_set_round_fmpz(t, fmpq_numref(q), 32, FMPR_RND_UP);
|
|
|
|
fmpr_div_fmpz(t, t, fmpq_denref(q), 32, FMPR_RND_UP);
|
|
|
|
|
|
|
|
if (fmpr_cmpabs_2exp_si(t, bound) > 0)
|
|
|
|
{
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("FAIL: %wd\n", i);
|
|
|
|
fmpr_print(t); flint_printf("\n\n");
|
|
|
|
flint_printf("%wd\n", bound); flint_printf("\n\n");
|
2013-02-18 07:59:48 +01:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmpq_clear(q);
|
|
|
|
fmpr_clear(t);
|
|
|
|
|
|
|
|
for (i = 100; i < 4000000; i += 1)
|
|
|
|
{
|
|
|
|
i += (i & 1);
|
|
|
|
a = bernoulli_bound_2exp_si(i);
|
|
|
|
b = log2bern_approx(i);
|
|
|
|
|
|
|
|
if (a < b || a > 1.01 * b)
|
|
|
|
{
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("FAIL: %wd\n", i);
|
|
|
|
flint_printf("%wd: %f %f %f\n", i, a, b, (float) a / b);
|
2013-02-18 07:59:48 +01:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:06:08 +02:00
|
|
|
flint_cleanup();
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("PASS\n");
|
2013-02-18 07:59:48 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|