Exemplo n.º 1
0
static VALUE r_gmpf_to_fr(int argc, VALUE *argv, VALUE self)
{
  VALUE ptr_return;
  MP_FLOAT *ptr_self;
  MPFR *ptr_mpfr;
  mp_rnd_t rnd;
  mp_prec_t prec;
  mpf_get_struct(self, ptr_self);
  switch(argc) {
  case 2:
    switch(TYPE(argv[0])){
    case T_SYMBOL:
      rnd = r_mpfr_rnd_from_value(argv[0]);
      if (FIXNUM_P(argv[1])) {
	prec = NUM2INT(argv[1]);
      } else {
	rb_raise(rb_eArgError, "Invalid arguments for GMP::F#to_fr; argc=%d\n", argc);
      }
      break;
    case T_FIXNUM:
      prec = NUM2INT(argv[0]);
      if (SYMBOL_P(argv[1])) {
	rnd = r_mpfr_rnd_from_value(argv[1]);
      } else {
	rb_raise(rb_eArgError, "Invalid arguments for GMP::F#to_fr; argc=%d\n", argc);
      }
      break;
    default:
      rb_raise(rb_eArgError, "Invalid arguments for GMP::F#to_fr; argc=%d\n", argc);
    }
    break;
  case 1:
    switch(TYPE(argv[0])){
    case T_SYMBOL:
      prec = R_MPF_GET_PREC(ptr_self);
      rnd = r_mpfr_rnd_from_value(argv[0]);
      break;
    case T_FIXNUM:
      prec = NUM2INT(argv[0]);
      rnd = mpfr_get_default_rounding_mode();
      break;
    default:
      rb_raise(rb_eArgError, "Invalid arguments for GMP::F#to_fr; argc=%d\n", argc);
    }
    break;
  case 0:
    prec = R_MPF_GET_PREC(ptr_self);
    rnd = mpfr_get_default_rounding_mode();
    break;
  default:
    rb_raise(rb_eArgError, "Invalid number of arguments for GMP::F#to_fr; argc=%d\n", argc);
  }
  r_mpfr_make_struct_init2(ptr_return, ptr_mpfr, prec);
  mpfr_set(ptr_mpfr, ptr_self, rnd);
  return ptr_return;
}
Exemplo n.º 2
0
static void
rasqal_xsd_decimal_init(rasqal_xsd_decimal* dec)
{
  /* XSD wants min of 18 decimal (base 10) digits 
   * http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#decimal
   */
#ifdef RASQAL_DECIMAL_NONE
  /* double has a restricted range */
  dec->precision_digits = DBL_DIG;
#else
  dec->precision_digits = 18;
#endif

  /* over-estimate bits since log(10)/log(2) = 3.32192809488736234789 < 4 */
  dec->precision_bits = dec->precision_digits*4;
  
#ifdef RASQAL_DECIMAL_C99
  dec->raw = 0DD;
#endif
#ifdef RASQAL_DECIMAL_MPFR
  mpfr_init2(dec->raw, dec->precision_bits);

  /* GMP_RNDD, GMP_RNDU, GMP_RNDN, GMP_RNDZ */
  dec->rounding = mpfr_get_default_rounding_mode();
#endif
#ifdef RASQAL_DECIMAL_GMP
  mpf_init2(dec->raw, dec->precision_bits);
#endif
#ifdef RASQAL_DECIMAL_NONE
  dec->raw = 0e0;
#endif

  dec->string = NULL;
  dec->string_len = 0;
}
Exemplo n.º 3
0
/* Test default rounding mode */
static void
check_default_rnd (void)
{
  int r;
  mp_rnd_t t;
  for(r = 0 ; r < GMP_RND_MAX ; r++)
    {
      mpfr_set_default_rounding_mode ((mp_rnd_t) r);
      t = mpfr_get_default_rounding_mode();
      if ((mp_rnd_t) r != t)
	ERROR("ERROR in setting / getting default rounding mode (1)\n");
    }
  mpfr_set_default_rounding_mode ((mp_rnd_t) 4);
  if (mpfr_get_default_rounding_mode() != GMP_RNDD)
    ERROR("ERROR in setting / getting default rounding mode (2)\n");
  mpfr_set_default_rounding_mode ((mp_rnd_t) -1);
  if (mpfr_get_default_rounding_mode() != GMP_RNDD)
    ERROR("ERROR in setting / getting default rounding mode (3)\n");
}
Exemplo n.º 4
0
/* Test default rounding mode */
static void
check_default_rnd (void)
{
    int r;
    mpfr_rnd_t t;
    for(r = 0 ; r < MPFR_RND_MAX ; r++)
    {
        mpfr_set_default_rounding_mode ((mpfr_rnd_t) r);
        t = (mpfr_get_default_rounding_mode) ();
        if ((mpfr_rnd_t) r != t)
        {
            printf ("%s %s\n", mpfr_print_rnd_mode ((mpfr_rnd_t) r),
                    mpfr_print_rnd_mode (t));
            ERROR("ERROR in setting / getting default rounding mode (1)");
        }
    }
    mpfr_set_default_rounding_mode ((mpfr_rnd_t) MPFR_RND_MAX);
    if (mpfr_get_default_rounding_mode() != MPFR_RNDA)
        ERROR("ERROR in setting / getting default rounding mode (2)");
    mpfr_set_default_rounding_mode((mpfr_rnd_t) -1);
    if (mpfr_get_default_rounding_mode() != MPFR_RNDA)
        ERROR("ERROR in setting / getting default rounding mode (3)");
}
void boost_cyl_bessel_k(boost_mp_result y, boost_mp_input x0, boost_mp_input y0)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_spherical_harmonic_i(boost_mp_result y, boost_mp_input n_, boost_mp_input m_, boost_mp_input theta, boost_mp_input phi)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_sinhc_pi(boost_mp_result y, boost_mp_input z)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
//
//
//
//// Exponential Integral
//
void boost_expint_n(boost_mp_result y, boost_mp_input n_, boost_mp_input z)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_ellint_3_K(boost_mp_result y, boost_mp_input k, boost_mp_input n)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_ellint_rc(boost_mp_result y, boost_mp_input x0, boost_mp_input y0)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_ibetac_non_normalized(boost_mp_result y, boost_mp_input a, boost_mp_input b, boost_mp_input x)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
//
//
//
//// Beta function
//
void boost_beta(boost_mp_result y, boost_mp_input x0, boost_mp_input x1)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_binomial_coefficient(boost_mp_result y, boost_mp_input i_, boost_mp_input j_)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_falling_factorial(boost_mp_result y, boost_mp_input x, boost_mp_input i_)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
Exemplo n.º 15
0
int main( int argc, char* argv[] )
{
    int ret = 0; 
    int use_turn_by_turn_buffer = 0;
    
    static st_block_size_t const REAL_SIZE = sizeof( SIXTRL_REAL_T );
    static st_block_size_t const I64_SIZE  = sizeof( SIXTRL_INT64_T );
    
    st_block_num_elements_t ii = 0;
    st_block_num_elements_t NUM_PARTICLES = 1000;
    st_block_num_elements_t NUM_ELEMENTS  = 100;
    
    mpfr_prec_t prec = ( mpfr_prec_t )128u;
    uint64_t prng_seed = ( uint64_t )20180501u;
    
    st_block_size_t jj = 0;
    st_block_size_t BLOCK_CAPACITY = 1;
    st_block_size_t DATA_CAPACITY  = 0;
    st_block_size_t NUM_TURNS      = 1;
        
    mpfr_rnd_t  const rnd  = mpfr_get_default_rounding_mode();
    
    st_Particles particles;    
    st_ParticlesContainer particle_buffer;
    st_ParticlesContainer elem_by_elem_buffer;
    st_ParticlesContainer turn_by_turn_buffer;
    
    st_BeamElements beam_elements;
    
    printf( "\r\n\r\nUsage: %s [NUM_PARTICLES=1000] [NUM_ELEMENTS=100] "
            "[NUM_TURNS=1] [precision=128] [seed=20180501] \r\n", argv[ 0 ] );
    
    if( argc >= 6 )
    {
        uint64_t const temp_seed = ( uint64_t )atoi( argv[ 5 ] );
        if( temp_seed > ( uint64_t )0u ) prng_seed = temp_seed;
    }
    
    if( argc >= 5 )
    {
        uint64_t const  temp_prec = ( uint64_t )atoi( argv[ 4 ] );
        if( temp_prec > ( uint64_t )0u ) prec = ( mpfr_prec_t )temp_prec;
    }

    if( argc >= 4 )
    {
        st_block_size_t const temp_num_turns = atoi( argv[ 3 ] );
        if( temp_num_turns > 0 ) NUM_TURNS = temp_num_turns;        
    }
    
    if( argc >= 3 )
    {
        st_block_num_elements_t const temp_num_elements = atoi( argv[ 2 ] );        
        if( temp_num_elements > 0 ) NUM_ELEMENTS = temp_num_elements;
    }
    
    if( argc > 1 )
    {
        st_block_num_elements_t const temp_num_particles = atoi( argv[ 1 ] );
        if( temp_num_particles > 0 ) NUM_PARTICLES = temp_num_particles;
        
        printf( " --> Use values: \r\n" 
                "   - NUM_PARTICLES: %12ld\r\n"
                "   - NUM_ELEMENTS : %12ld\r\n"
                "   - NUM_TURNS    : %12lu\r\n"
                "   - seed         : %12lu\r\n\r\n",
                NUM_PARTICLES, NUM_ELEMENTS, NUM_TURNS, prng_seed );
    }    
    else
    {
        printf( " --> Use default values\r\n" );        
    }
    
    /* -------------------------------------------------------------------- */
    
    st_Random_init_genrand64( prng_seed );
    
    /* -------------------------------------------------------------------- */
    
    st_BeamElements_preset( &beam_elements );
    
    st_BeamElements_set_data_begin_alignment( &beam_elements, REAL_SIZE );
    st_BeamElements_set_data_alignment( &beam_elements, REAL_SIZE );
    
    BLOCK_CAPACITY = NUM_ELEMENTS;
    DATA_CAPACITY  = BLOCK_CAPACITY * ( REAL_SIZE + I64_SIZE );
    
    st_BeamElements_reserve_num_blocks( &beam_elements, BLOCK_CAPACITY );
    st_BeamElements_reserve_for_data( &beam_elements, DATA_CAPACITY );
    
    for( ii = 0 ; ii < NUM_ELEMENTS ; ++ii )
    {
        st_Drift drift;
        st_Drift_preset( &drift );
        
        ret |= st_BeamElements_create_beam_element_mpfr4(
            &drift, &beam_elements, st_BLOCK_TYPE_DRIFT, prec );
        
        if( ret == 0 )
        {
            ret = st_Drifts_init_random_mpfr4( &drift, rnd );
        }
        
        if( ret != 0 )
        {
            break;
        }
    }
    
    /* -------------------------------------------------------------------- */
    
    st_Particles_preset( &particles );
    st_ParticlesContainer_preset( &particle_buffer );
    
    if( ret == 0 )
    {
        ret  = st_ParticlesContainer_init_num_of_blocks_mpfr4( 
            &particle_buffer, 1, NUM_PARTICLES, prec );
    
        ret |= st_ParticlesContainer_get_particles( 
            &particles, &particle_buffer, 0 );
    }
    
    if( ret == 0 )
    {
        st_Particles_init_random_mpfr4( &particles, rnd );
    }
    
    /* --------------------------------------------------------------------- */
    
    st_ParticlesContainer_preset( &elem_by_elem_buffer );
    
    if( ret == 0 )
    {
        ret = st_ParticlesContainer_init_num_of_blocks_mpfr4( 
            &elem_by_elem_buffer, NUM_TURNS * NUM_ELEMENTS, 
                NUM_PARTICLES, prec );
    }
    
    /* --------------------------------------------------------------------- */
    
    st_ParticlesContainer_preset( &turn_by_turn_buffer );
    
    if( ret == 0 )
    {
        ret = st_ParticlesContainer_init_num_of_blocks_mpfr4( 
            &turn_by_turn_buffer, NUM_TURNS, NUM_PARTICLES, prec );
    }
    
    /* --------------------------------------------------------------------- */
    
    if( ret == 0 )
    {
        st_block_num_elements_t kk = 0;
        
        for( jj = 0 ; jj < NUM_TURNS ; ++jj, kk += NUM_ELEMENTS )
        {
            /* ============================================================= */
            
            ret |= st_Track_beam_elements_mpfr4( &particles, 
                    &beam_elements, prec, rnd, kk, &elem_by_elem_buffer );
            
            /* ============================================================= */
            
            if( use_turn_by_turn_buffer )
            {
                st_Particles particles_after_turn;
                
                ret |= st_ParticlesContainer_get_particles( 
                    &particles_after_turn, &turn_by_turn_buffer, jj );
                
                st_Particles_copy_all_unchecked_mpfr4(
                    &particles_after_turn, &particles, rnd );
            }
            
            if( ret != 0 )
            {
                break;
            }
        }
    }
    
    /* -------------------------------------------------------------------- */
    
    st_BeamElements_free_mpfr4( &beam_elements );
    st_ParticlesContainer_free_mpfr4( &particle_buffer );
    st_ParticlesContainer_free_mpfr4( &turn_by_turn_buffer );
    st_ParticlesContainer_free_mpfr4( &elem_by_elem_buffer );
    
    /* -------------------------------------------------------------------- */
    
    mpfr_free_cache();
    
    return 0;
}
void boost_sph_neumann(boost_mp_result y, boost_mp_input v_, boost_mp_input y0)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_airy_bi_prime(boost_mp_result y, boost_mp_input x)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_ibeta_derivative(boost_mp_result y, boost_mp_input a, boost_mp_input b, boost_mp_input x)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_digamma(boost_mp_result y, boost_mp_input x)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_legendre_next_m(boost_mp_result y, boost_mp_input n_, boost_mp_input m_, boost_mp_input x, boost_mp_input Pl, boost_mp_input Plm1)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_jacobi_sn(boost_mp_result y, boost_mp_input k, boost_mp_input u)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_laguerre(boost_mp_result y, boost_mp_input n_, boost_mp_input x)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_tgamma_delta_ratio(boost_mp_result y, boost_mp_input x0, boost_mp_input y0)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_laguerre_next_m(boost_mp_result y, boost_mp_input n_, boost_mp_input m_, boost_mp_input x, boost_mp_input Ln, boost_mp_input Lnm1)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_gamma_p_inva(boost_mp_result y, boost_mp_input x0, boost_mp_input y0)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }
void boost_hermite_next(boost_mp_result y, boost_mp_input n_, boost_mp_input x, boost_mp_input Hn, boost_mp_input Hnm1)
 {
    mpfr_set_si(y, 2, mpfr_get_default_rounding_mode());
 }