Exemple #1
0
struct xpr
cxabs (struct cxpr z)
{
  struct xpr x;
  int ea, eb;

  if (xprcmp (&z.re, &xZero) == 0 && xprcmp (&z.im, &xZero) == 0)
    return xZero;
  else
    {
      ea = (z.re.nmm[0] &= xM_exp) - xBias;
      eb = (z.im.nmm[0] &= xM_exp) - xBias;
      if (ea > eb + XBOUND)
	return z.re;
      else if (eb > ea + XBOUND)
	return z.im;
      else
	{
	  z.re.nmm[0] -= eb;
	  z.im.nmm[0] = xBias;
	  x = xsqrt (xadd (xmul (z.re, z.re), xmul (z.im, z.im), 0));
	  x.nmm[0] += eb;
	  return x;
	}
    }
}
Exemple #2
0
int
cxrec (struct cxpr z, struct cxpr *w)
{
  struct xpr x;
  int sa, sb, ea, eb;

  if (xprcmp (&z.re, &xZero) == 0 && xprcmp (&z.im, &xZero) == 0)
    return 0;
  else
    {
      sa = z.re.nmm[0] & xM_sgn;
      sb = z.im.nmm[0] & xM_sgn;
      ea = (z.re.nmm[0] &= xM_exp) - xBias;
      eb = (z.im.nmm[0] &= xM_exp) - xBias;
      if (ea > eb + XBOUND)
	x = z.re;
      else if (eb > ea + XBOUND)
	x = z.im;
      else
	{
	  z.re.nmm[0] -= eb;
	  z.im.nmm[0] = xBias;
	  x = xsqrt (xadd (xmul (z.re, z.re), xmul (z.im, z.im), 0));
	  x.nmm[0] += eb;
	  z.re.nmm[0] += eb;
	  z.im.nmm[0] += eb;
	}
      w->re = xdiv (xdiv (z.re, x), x);
      w->im = xdiv (xdiv (z.im, x), x);
      w->re.nmm[0] |= sa;
      w->im.nmm[0] |= xM_sgn ^ sb;
      return 1;
    }
}
Exemple #3
0
main ()
{
  global_x = 100.0;
  printf ("", &global_x, &global_y);	/* Frighten the optimizer.  */
  global_y = xsqrt (global_x / 2.0);	/* Compensate for the "x += x;" in xsqrt().  */
  if (global_y != 10.0)
    abort ();
  exit (0);
}
Exemple #4
0
Angle
dist(Angle ra1, Angle dec1, Angle ra2, Angle dec2)
{
	double a;

	a = sin(dec1) * sin(dec2) +
		cos(dec1) * cos(dec2) *
		cos(ra1 - ra2);
	a = atan2(xsqrt(1 - a*a), a);
	if(a < 0)
		a = -a;
	return a;
}
Exemple #5
0
int
main (void)
{
    struct xpr z, w, f, u;

    printf ("     Test of Sqrt Function\n");
    z = xZero;
    w = atox ("0.2");
    u = atox ("4.01");
    for (; xprcmp (&z, &u) < 0; z = xadd (z, w, 0))
    {
        /* compute extended precision square root */
        f = xsqrt (z);
        printf (" %8.4f  ", xtodbl (z));
        xprxpr (f, decd);
        putchar ('\n');
    }
    return 0;
}