arb icon indicating copy to clipboard operation
arb copied to clipboard

arb_get_str() & arb_set_str() does not preserve value

Open saraedum opened this issue 2 years ago • 5 comments

Consider the following C program.

$ cat roundtrip.c
#include <arb.h>

int main() {
  arb_t a;
  arb_init(a);

  arb_load_str(a, "2bb573849d73 -2c 800031b 365d");

  arb_printn(a, 1024, ARB_STR_MORE);

  arb_set_str(a, arb_get_str(a, 1024, ARB_STR_MORE), 1024);

  arb_printn(a, 1024, ARB_STR_MORE);
}

When run (with Arb 2.22.1 from conda-forge) it prints:

[+/- 3.65e+4197][+/- 3.66e+4197]

I understand that arb_get_str() can introduce imprecision and I also understand that I should probably use arb_dump_str to serialize an arb_t; but shouldn't arb_set_str() preserve the radius?

saraedum avatar Mar 31 '22 16:03 saraedum

Neither arb_get_str nor arb_set_str says in their documentation that they preserve the radius. It only states that the old interval is contained in the new interval.

albinahlback avatar Mar 31 '22 16:03 albinahlback

@albinahlback Thanks, I am aware of that. I am not saying that the implementation breaks the documentation.

saraedum avatar Mar 31 '22 16:03 saraedum

Then what is your issue? You asked if arb_set_str preserves the radius, for which I gave an answer.

albinahlback avatar Mar 31 '22 16:03 albinahlback

My question was: Shouldn't arb_set_str() try to preserve the radius here?

saraedum avatar Mar 31 '22 16:03 saraedum

Note that this is somewhat related to #391. In #391 arb_get_str introduces an error, here arb_set_str introduces an error.

I wonder if both methods could be more careful when it's possible not to introduce any error.

saraedum avatar Mar 31 '22 16:03 saraedum