Macaulay2 Engine
Loading...
Searching...
No Matches

◆ mpfc_abs()

void mpfc_abs ( gmp_RRmutable result,
gmp_CCmutable c )

Definition at line 225 of file complex.c.

226{
227 mpfr_t a, b;
228
229 mpfr_init2(a, mpfr_get_prec(c->re));
230 mpfr_init2(b, mpfr_get_prec(c->re));
231 mpfr_abs(a, c->re, MPFR_RNDN);
232 mpfr_abs(b, c->im, MPFR_RNDN);
233 if (mpfr_zero_p(a))
234 mpfr_set(result, b, MPFR_RNDN);
235 else if (mpfr_zero_p(b))
236 mpfr_set(result, a, MPFR_RNDN);
237 else if (mpfr_greater_p(a, b))
238 {
239 // double d = b/a;
240 // But use b for d, as it is not needed later.
241 // result = a * ::sqrt(1.0 + d*d);
242 mpfr_div(b, b, a, MPFR_RNDN);
243 mpfr_sqr(b, b, MPFR_RNDN);
244 mpfr_add_si(b, b, 1, MPFR_RNDN);
245 mpfr_sqrt(b, b, MPFR_RNDN);
246 mpfr_mul(result, a, b, MPFR_RNDN);
247 }
248 else
249 {
250 // double d = a/b;
251 // But use a for d, as it is not needed later.
252 // result = b * ::sqrt(1.0 + d*d);
253 mpfr_div(a, a, b, MPFR_RNDN);
254 mpfr_sqr(a, a, MPFR_RNDN);
255 mpfr_add_si(a, a, 1, MPFR_RNDN);
256 mpfr_sqrt(a, a, MPFR_RNDN);
257 mpfr_mul(result, b, a, MPFR_RNDN);
258 }
259 mpfr_clear(a);
260 mpfr_clear(b);
261
262#if 0
263 static void abs(double &result, elem c)
264 {
265 double a = fabs(c.re);
266 double b = fabs(c.im);
267 if (a == 0.0) result = b;
268 else if (b == 0.0) result = a;
269 else if (a > b)
270 {
271 double d = b/a;
272 result = a * ::sqrt(1.0 + d*d);
273 }
274 else
275 {
276 double d = a/b;
277 result = b * ::sqrt(1.0 + d*d);
278 }
279 }
280#endif
281}
VALGRIND_MAKE_MEM_DEFINED & result(result)
const mpreal fabs(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition mpreal.h:2293
#define abs(x)
Definition polyroots.cpp:51

References abs, and result().