예제 #1
0
static void
bug20090520 (void)
{
  mpfr_t x;
  long double d, e;
  int i;

  mpfr_init (x);
  mpfr_set_ui (x, 1, MPFR_RNDN);
  d = 1.0;
  mpfr_div_2exp (x, x, 16383, MPFR_RNDN);
  for (i = 0; i < 16383; i++)
    d *= 0.5;
  e = mpfr_get_ld (x, MPFR_RNDN);
  if (e != d)
    {
      printf ("mpfr_get_ld(1e-16383) failed\n");
      printf ("expected %.20Le\n", d);
      printf ("got      %.20Le\n", e);
      exit (1);
    }
  mpfr_clear (x);
}
예제 #2
0
void regressMinRelError_fr(int n, int m, mpfr_t **x, mpfr_t *result) {
  int m0 = n * 3, n0 = m + 2 * n, i, j;
  mpfr_t **a0, *c0, *result0;
  int in0[m0];

  a0 = malloc(sizeof(mpfr_t *) * m0);
  for(i=0;i<m0;i++) {
    a0[i] = calloc(n0+1, sizeof(mpfr_t));
    for(j=0;j<n0+1;j++) mpfr_zinit(a0[i][j]);
  }

  c0 = calloc(n0+1, sizeof(mpfr_t));
  result0 = calloc(n0+1, sizeof(mpfr_t));

  for(j=0;j<n0+1;j++) {
    mpfr_zinit(c0[j]);
    mpfr_zinit(result0[j]);
  }
  
  for(i=0;i<n;i++) {
    long double ld = mpfr_get_ld(x[m][i], GMP_RNDN);
    if (ld < DBL_MIN) ld = 1;

#if 1
    mpfr_set_ld(c0[m+i  +1], 1.0/fabsl(ld), GMP_RNDN);
    mpfr_set_ld(c0[m+n+i+1], 1.0/fabsl(ld), GMP_RNDN);
#else
    int e;
    frexpl(ld, &e);
    ld = 1.0 / ldexpl(1.0, e);
    mpfr_set_ld(c0[m+i  +1], ld, GMP_RNDN);
    mpfr_set_ld(c0[m+n+i+1], ld, GMP_RNDN);
#endif
    
    mpfr_set_d(a0[i*3+0][m+i+1], 1, GMP_RNDN);
    in0[i*3+0] = GEQ;

    mpfr_set_d(a0[i*3+1][m+n+i+1], 1, GMP_RNDN);
    in0[i*3+1] = GEQ;

    for(j=0;j<m;j++) {
      mpfr_set(a0[i*3+2][j+1], x[j][i], GMP_RNDN);
    }

    mpfr_set_d(a0[i*3+2][m+i+1], 1, GMP_RNDN);
    mpfr_set_d(a0[i*3+2][m+n+i+1], -1, GMP_RNDN);
    in0[i*3+2] = EQU;
    mpfr_set(a0[i*3+2][0], x[m][i], GMP_RNDN);
    mpfr_neg(a0[i*3+2][0], a0[i*3+2][0], GMP_RNDN);
  }

  int status = solve_fr(result0, n0, m0, a0, in0, c0);

  if (status == NOT_FEASIBLE) {
    printf("not feasible\n");
  } else {
    if (status == MAXIMIZABLE_TO_INFINITY) printf("maximizable to inf\n");
  }

  for(i=0;i<m;i++) {
    mpfr_set(result[i], result0[i+1], GMP_RNDN);
  }

  free(result0);
  free(c0);
}
예제 #3
0
파일: mpfrplus.hpp 프로젝트: dlevin256/kfr
 /// Explicit conversion to long double
 inline explicit operator long double() const noexcept
 {
     return mpfr_get_ld(val, internal::rounding_mode());
 }
예제 #4
0
파일: fractal.c 프로젝트: jwm-art-net/MDZ
int fractal_calculate_line(image_info* img, int line)
{
    int ix = 0;
    int mx = 0;
    int chk_px = ((rthdata*)img->rth_ptr)->check_stop_px;

    int img_width = img->real_width;
    int* raw_data = &img->raw_data[line * img_width];

    long double x,y;
    long double x2, y2;
    long double c_re = 0, c_im = 0;

    /* Working */
    long double wre,  wim;
    long double wre2, wim2;
    depth_t depth = img->depth;

    long double xmin, xmax, ymax, width;
    long double j_c_re = 0, j_c_im = 0;

    xmin = mpfr_get_ld(img->xmin,   GMP_RNDN);
    xmax = mpfr_get_ld(img->xmax,   GMP_RNDN);
    ymax = mpfr_get_ld(img->ymax,   GMP_RNDN);
    width = xmax - xmin;

    if (img->family == FAMILY_JULIA)
    {
        j_c_re = mpfr_get_ld(img->u.julia.c_re, GMP_RNDN);
        j_c_im = mpfr_get_ld(img->u.julia.c_im, GMP_RNDN);
    }

    y = ymax - (width / (long double)img_width)
                * (long double)line;
    y2 = y * y;

    while (ix < img_width)
    {
        mx += chk_px;
        if (mx > img_width)
            mx = img_width;
        for (; ix < mx; ++ix, ++raw_data)
        {
            x = (ix / (long double)img_width) * width + xmin;
            x2 = x * x;
            wre = x;
            wim = y;
            wre2 = x2;
            wim2 = y2;
            switch (img->family)
            {
            case FAMILY_MANDEL:
                c_re = x;
                c_im = y;
                break;
            case FAMILY_JULIA:
                c_re = j_c_re;
                c_im = j_c_im;
                break;
            }
            switch(img->fractal)
            {
            case BURNING_SHIP:
                *raw_data = frac_burning_ship(depth,  wim, wre,
                                                c_im, c_re,
                                                wim2, wre2);
                break;
            case GENERALIZED_CELTIC:
                *raw_data = frac_generalized_celtic(depth,  wim, wre,
                                                c_im, c_re,
                                                wim2, wre2);
                break;
            case VARIANT:
                *raw_data = frac_variant(depth,  wim, wre,
                                                c_im, c_re,
                                                wim2, wre2);
                break;
            case MANDELBROT:
            default:
                *raw_data = frac_mandel(depth,  wim, wre,
                                                c_im, c_re,
                                                wim2, wre2);
            }
        }
        if (rth_render_should_stop((rthdata*)img->rth_ptr))
            return 0;
    }
    return 1;
}