Can I use a `mpfr_t` as both input and output argument?
Asked Answered
C

1

6

The question is very simple and direct, but I could not find an answer on the documentation. If I have

mpfr_t a, b;

Can I do something like

mpfr_add(a, a, b, rnd);

This would compute the sum of a and b and store the result on a. I don't know if this results in an aliasing problem, potentially invalidating the result, or if this is fine.

Cordy answered 24/2, 2017 at 10:35 Comment(2)
what is wrong with a = mpfr_add(a,b)?Birthday
@jonas_toth: everything? The interface of this function is int mpfr_add (mpfr_t rop, mpfr_t op1, mpfr_t op2, mpfr_rnd_t rnd)Cordy
C
3

Never mind, it's in section 4.3 of the linked document.

MPFR allows you to use the same variable for both input and output in the same expression. For example, the main function for floating-point multiplication, mpfr_mul, can be used like this: mpfr_mul (x, x, x, rnd). This computes the square of x with rounding mode rnd and puts the result back in x.

Cordy answered 24/2, 2017 at 10:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.