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
456 stars 137 forks source link

Rounding mode in arb_set_round() #357

Closed hannorein closed 3 years ago

hannorein commented 3 years ago

First of all thank you for developing this library. It's fantastic.

I have a (probably naive) question about the rounding mode of arb_set_round(). I can see that it is set to ARB_RND which is set to ARF_RND_DOWN.

What is the reason for it rounding down by default? Wouldn't it make sense to have the function take an additional argument the same way the arf_set_round() function does? For my application, I need to round to the nearest number. Right now I'm just calling the underlying arf_set_round() myself. But I wonder if I'm missing something since there is apparently no built-in function to round an arbt_t to an arb_t with a specific rounding mode.

fredrik-johansson commented 3 years ago

ARF_RND_DOWN is slightly faster than the other rounding modes in terms of low-level operations. I have considered changing the ARB_RND to ARF_RND_NEAR since it buys a little bit of accuracy, but it would need testing and profiling.

There is no real reason for not having another function like arb_set_round but which takes a rounding mode as input; it has just not been implemented. arb_set_round does not take a rounding parameter because it is used all over the place to change the precision of balls, and specifying the rounding mode would add clutter.

hannorein commented 3 years ago

Thanks for the quick reply! That makes perfect sense.

Maybe adding a short note in the documentation would help others (see pull request)