Sha256: 552433fabe3598e3797576d569cea5bbac6fd2c0736949259b9d38de467725b1

Contents?: true

Size: 1.51 KB

Versions: 8

Compression:

Stored size: 1.51 KB

Contents

#include <mpfr.h>
#include <mpfi.h>
#include <mpfi_io.h>
#include "ruby_mpfi.h"
#include "func_mpfi_extention.h"

void mpfi_mid_interval(mpfi_t ret, mpfi_t x){
  mpfr_t left, right;
  mpfr_init2(left, mpfi_get_prec(x));
  mpfr_init2(right, mpfi_get_prec(x));

  mpfr_add(left, r_mpfi_left_ptr(x), r_mpfi_right_ptr(x), GMP_RNDD);
  mpfr_add(right, r_mpfi_left_ptr(x), r_mpfi_right_ptr(x), GMP_RNDU);

  mpfr_div_ui(r_mpfi_left_ptr(ret), left, 2, GMP_RNDD);
  mpfr_div_ui(r_mpfi_right_ptr(ret), right, 2, GMP_RNDU);

  mpfr_clear(left);
  mpfr_clear(right);
}

/* Retrun 0 if this function puts subdivision to *ret. */
/* Otherwise, return -1. */
int mpfi_subdivision(int num, mpfi_t *ret, mpfi_t x){
  int i, ret_val = -1;
  mpfr_t l;
  mpfr_init(l);
  mpfr_sub(l, r_mpfi_right_ptr(x), r_mpfi_left_ptr(x), GMP_RNDD);
  mpfr_div_si(l, l, num, GMP_RNDD);
  
  mpfr_t x_diam;
  mpfr_init(x_diam);
  mpfi_diam_abs(x_diam, x);
  if(mpfr_cmp(x_diam, l) > 0){
    mpfr_set(r_mpfi_left_ptr(*ret), r_mpfi_left_ptr(x), GMP_RNDN);
    mpfr_add(r_mpfi_right_ptr(*ret), r_mpfi_left_ptr(*ret), l, GMP_RNDU);

    for(i = 1; i < num - 1; i ++){
      mpfr_set(r_mpfi_left_ptr(*ret + i), r_mpfi_right_ptr(*ret + i - 1), GMP_RNDN);
      mpfr_add(r_mpfi_right_ptr(*ret + i), r_mpfi_left_ptr(*ret + i), l, GMP_RNDU);
    }

    mpfr_set(r_mpfi_left_ptr(*ret + i), r_mpfi_right_ptr(*ret + i - 1), GMP_RNDN);
    mpfr_set(r_mpfi_right_ptr(*ret + i), r_mpfi_right_ptr(x), GMP_RNDN);
    ret_val = 0;
  }
  
  mpfr_clear(x_diam);
  mpfr_clear(l);
  return ret_val;
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ruby-mpfi-0.0.9 ext/mpfi/func_mpfi_extention.c
ruby-mpfi-0.0.8 ext/mpfi/func_mpfi_extention.c
ruby-mpfi-0.0.7 ext/mpfi/func_mpfi_extention.c
ruby-mpfi-0.0.6 ext/mpfi/func_mpfi_extention.c
ruby-mpfi-0.0.5 ext/mpfi/func_mpfi_extention.c
ruby-mpfi-0.0.4 ext/mpfi/func_mpfi_extention.c
ruby-mpfi-0.0.3 ext/mpfi/func_mpfi_extention.c
ruby-mpfi-0.0.2 ext/mpfi/func_mpfi_extention.c