mailing list of musl libc
 help / color / mirror / code / Atom feed
d28ec8e52df3604019f6d9a1c873ed9bc2dc2e7e blob 1447 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
#include "complex_impl.h"
#include <fenv.h>

/* cssqsl() and csqrtl() taken from
 * Kahan, W. (1987). Branch cuts for complex elementary functions.
 */
static inline long double complex _cssqsl(long double complex z) {
#pragma STDC FENV_ACCESS ON
  fenv_t env;
  unsigned k = 0;
  long double x, y, r;
  int set_excepts;

  feholdexcept(&env);
  x = creal(z);
  y = cimag(z);
  r = x * x + y * y;
  if ((isinf(x) || isinf(y)) && (isnan(r) || isinf(r))) {
    r = INFINITY;
  } else {
    set_excepts = fetestexcept(FE_OVERFLOW | FE_UNDERFLOW);
    if ((set_excepts & FE_OVERFLOW) ||
        ((set_excepts & FE_UNDERFLOW) && isless(r, LDBL_MIN / LDBL_EPSILON))) {
      k = logbl(fmaxl(fabsl(x), fabsl(y)));
      x = scalbnl(x, -k);
      y = scalbnl(y, -k);
      r = x * x + y * y;
    }
  }
  feupdateenv(&env);
  return CMPLXL(r, k);
}

long double complex csqrtl(long double complex z) {
  long double x, y, r, xi, eta;
  unsigned k;

  x = creal(z);
  y = cimag(z);
  z = _cssqsl(z);
  r = creal(z);
  k = cimag(z);
  if (!isnan(x)) {
    r = scalbnl(fabsl(x), -k) + sqrtl(r);
  }
  if (k & 1) {
    k = (k - 1) / 2;
  } else {
    k = k / 2 - 1;
    r *= 2;
  }
  r = scalbnl(sqrtl(r), k);
  xi = r;
  eta = y;
  if (r != 0) {
    if (!isinf(eta)) {
      // TODO if eta underflowed, signal it
      eta = (eta / r) / 2;
    }
    if (isless(x, 0)) {
      xi = fabsl(eta);
      eta = copysignl(r, y);
    }
  }
  return CMPLX(xi, eta);
}
debug log:

solving d28ec8e5 ...
found d28ec8e5 in https://inbox.vuxu.org/musl/CAAQmekc76iSjRots+cQuWMMsBPnPEV5emiCH8wAsmVxRH+OpEA@mail.gmail.com/
found 22539379 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 225393790420d67b9b5740d9f73e756912b59bfb	src/complex/csqrtl.c

applying [1/1] https://inbox.vuxu.org/musl/CAAQmekc76iSjRots+cQuWMMsBPnPEV5emiCH8wAsmVxRH+OpEA@mail.gmail.com/
diff --git a/src/complex/csqrtl.c b/src/complex/csqrtl.c
index 22539379..d28ec8e5 100644

Checking patch src/complex/csqrtl.c...
Applied patch src/complex/csqrtl.c cleanly.

index at:
100644 d28ec8e52df3604019f6d9a1c873ed9bc2dc2e7e	src/complex/csqrtl.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).