flintlib / arb

Arb has been merged into FLINT -- use https://github.com/flintlib/flint/ instead
http://arblib.org/
GNU Lesser General Public License v2.1
455 stars 137 forks source link

arb_get_str() & arb_set_str() does not preserve value #412

Open saraedum opened 2 years ago

saraedum commented 2 years ago

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?

albinahlback commented 2 years ago

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.

saraedum commented 2 years ago

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

albinahlback commented 2 years ago

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

saraedum commented 2 years ago

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

saraedum commented 2 years ago

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.