acb functions - how to get more than double precision?

13 views
Skip to first unread message

Joachim Wuttke

unread,
Dec 12, 2024, 8:09:53 AM (10 days ago) Dec 12
to flint-devel
If you permit a beginner's question here (I found no other mailing list):

With the program below, I am stuck at a precision of some 10^-17. How to enforce given prec, to get the advantages of arbitrary-precision computation?

Thanks, Joachim

---

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <flint/arb.h>
#include <flint/acb.h>

int main(int argc, char *argv[])
{
    if (argc != 3) {
        fprintf(stderr, "Usage: %s <x> <y>\n", argv[0]);
        return 1;
    }
    char *endptr;
    double x = strtod(argv[1], &endptr);
    assert(*endptr == '\0');
    double y = strtod(argv[2], &endptr);
    assert(*endptr == '\0');

    printf("Called with args %g %g\n", x, y);
    acb_t Z;
    acb_init(Z);
    arb_set_d(acb_realref(Z), x);
    arb_set_d(acb_realref(Z), y);
    acb_t W;
    acb_init(W);
    for (short prec = 1<<2; prec < 1<<10; prec *= 2) {
acb_sqrt(W, Z, prec);
printf("Using %5ld bits, erfc(z) = ", prec);
acb_printn(W, 16, 0); printf("\n");
    }

    acb_clear(Z); acb_clear(W);
    return 0;
}

Output:

Called with args 2 0.37
Using     4 bits, erfc(z) = [+/- 0.626]
Using     8 bits, erfc(z) = [0.61 +/- 8.44e-3]
Using    16 bits, erfc(z) = [0.6083 +/- 5.42e-5]
Using    32 bits, erfc(z) = [0.608276253 +/- 3.66e-10]
Using    64 bits, erfc(z) = [0.6082762530298220 +/- 3.49e-17]
Using   128 bits, erfc(z) = [0.6082762530298220 +/- 3.48e-17]
Using   256 bits, erfc(z) = [0.6082762530298220 +/- 3.48e-17]
Using   512 bits, erfc(z) = [0.6082762530298220 +/- 3.48e-17]

Fredrik Johansson

unread,
Dec 12, 2024, 8:14:27 AM (10 days ago) Dec 12
to flint...@googlegroups.com
Hello Joachim,

Two things: first, don't use strtod and arb_set_d unless you specifically want e.g. 0.37 rounded to a double rather than the exact decimal 0.37. Instead use arb_set_str. Second, the problem in your program is that acb_printn(W, 16, 0) caps the output to 16 digits. Use something like acb_printn(W, prec / (log(10)/log(2)) + 1, 0) instead to match the precision.

Fredrik

--

---
You received this message because you are subscribed to the Google Groups "flint-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flint-devel...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/flint-devel/1db3a8b9-8236-4513-ac61-82dc68b1705fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages