Ejemplo n.º 1
0
unsigned int GetIdentifierValueAsNativeInteger(char *Id)
{
	symbol_value_t *s;
	
	s = (symbol_value_t *)symtab->get(symtab, (void *)Id);
	if (s) {
		return mpf_get_ui(s->value);
	}
	
	return 0;
}
Ejemplo n.º 2
0
void my_out_str_raw(FILE *fp, unsigned long digits, mpf_t f, unsigned long offset)
{
    unsigned long d;

    if (digits <= LINE_SIZE*NUM_BLOCKS) {
        unsigned long cursor = offset % LINE_SIZE;
        for (d = 0; d < digits; ) {
            mpf_set_prec_raw(f, (int)((digits-d)*BITS_PER_DIGIT+1));
            mpf_mul_ui(f, f, UNIT_MOD);
            unsigned long i = mpf_get_ui(f);
            mpf_sub_ui(f, f, i);

            utoa(i, UNIT_SIZE);
            *out_ptr++ = ' ';
            d += UNIT_SIZE;
            cursor += UNIT_SIZE;
            if (cursor == LINE_SIZE) {
                cursor = 0;
                *out_ptr++ = ':';
                *out_ptr++ = ' ';
                utoa(offset + d, 0);
                *out_ptr++ = '\n';
                if ((offset + d) % (LINE_SIZE*10) == 0)
                    flush_out(fp);
            }
        }
    } else {
        mpf_t block, mod;
        unsigned long num_units = (digits + UNIT_SIZE-1)/UNIT_SIZE;
        unsigned long block_size =  (num_units + NUM_BLOCKS-1)/NUM_BLOCKS*UNIT_SIZE;
        mpf_set_default_prec((int)(block_size*BITS_PER_DIGIT+1));
        mpf_init(block);
        mpf_init_set_ui(mod, 10);
        mpf_pow_ui(mod, mod, block_size);

        for (d = 0; d < digits; d += block_size) {
            unsigned long size = block_size < digits - d ? block_size : digits - d;
            mpf_set_prec_raw(block, (int)(size*BITS_PER_DIGIT+1));
            mpf_set(block, f);
            my_out_str_raw(fp, size, block, offset+d);
            if (block_size < digits - d) {
                mpf_set_prec_raw(f, (int)((digits-d)*BITS_PER_DIGIT+1));
                mpf_mul(f, f, mod);
                mpf_floor(trunk, f);
                mpf_sub(f, f, trunk);
            }
        }
        mpf_clear(block);
        mpf_clear(mod);
    }
}
Ejemplo n.º 3
0
void my_out_str(FILE *fp, unsigned long base, unsigned long digits, mpf_t f)
{
    unsigned long num_units = (digits + UNIT_SIZE-1)/UNIT_SIZE;
    unsigned long block_size =  (num_units + NUM_BLOCKS-1)/NUM_BLOCKS*UNIT_SIZE;
    mpf_init2(trunk, (int)(block_size*BITS_PER_DIGIT+1));

    unsigned long i = mpf_get_ui(f);
    fprintf(fp, "%lu.\n", i);
    mpf_sub_ui(f, f, i);
    my_out_str_raw(fp, digits, f, 0);
    if (out_ptr != out_buf)
        flush_out(fp);

    mpf_clear(trunk);
}
Ejemplo n.º 4
0
Archivo: hilbert.c Proyecto: blynn/pbc
// Computes q = exp(2 pi i tau).
static void compute_q(mpc_t q, mpc_t tau) {
  mpc_t z0;
  mpf_t f0, f1;
  mpf_ptr fp0;
  pbc_mpui pwr;

  mpc_init(z0);
  mpf_init(f0);
  mpf_init(f1);

  //compute z0 = 2 pi i tau
  mpc_set(z0, tau);
  //first remove integral part of Re(tau)
  //since exp(2 pi i)  = 1
  //it seems |Re(tau)| < 1 anyway?
  fp0 = mpc_re(z0);
  mpf_trunc(f1, fp0);
  mpf_sub(fp0, fp0, f1);

  mpc_mul_mpf(z0, z0, pi);
  mpc_mul_ui(z0, z0, 2);
  mpc_muli(z0, z0);

  //compute q = exp(z0);
  //first write z0 = A + a + b i
  //where A is a (negative) integer
  //and a, b are in [-1, 1]
  //compute e^A separately
  fp0 = mpc_re(z0);
  pwr = mpf_get_ui(fp0);
  mpf_pow_ui(f0, recipeulere, pwr);
  mpf_add_ui(fp0, fp0, pwr);

  mpf_exp(f1, mpc_re(z0));
  mpf_mul(f0, f1, f0);
  mpc_cis(q, mpc_im(z0));

  /*
  old_mpc_exp(q, z0);
  */
  mpc_mul_mpf(q, q, f0);

  mpc_clear(z0);
  mpf_clear(f0);
  mpf_clear(f1);
}
Ejemplo n.º 5
0
void set_gmp_precision(int precision) {

	mpf_t value;
	mpf_t log_2;
	unsigned int bits_precision_size;

    /* Inicializações */
	mpf_init(value);
	mpf_init(log_2);

    /* Calculo do valor da precisao e faço a transformação para numero de bits */
	mpf_set_ui(value, (unsigned int) precision);
	/* log de 10 na base 2 */ 
	mpf_set_str(log_2,"3.3219280949",10); 
	mpf_mul(value,value,log_2);
	bits_precision_size = mpf_get_ui(value) + 1;
	mpf_set_default_prec(bits_precision_size);
	/* Debug gmp_printf("###-Precision: %F.f\n", precision_gmp);	*/

	/* Limpeza (frees) */
	mpf_clear(log_2);
	mpf_clear(value);
}
Ejemplo n.º 6
0
void
check_limbdata (void)
{
#define M  GMP_NUMB_MAX

  static const struct {
    mp_exp_t       exp;
    mp_size_t      size;
    mp_limb_t      d[10];
    unsigned long  want;

  } data[] = {

    /* in the comments here, a "_" indicates a digit (ie. limb) position not
       included in the d data, and therefore zero */

    { 0, 0, { 0 }, 0L },    /* 0 */

    { 1,  1, { 1 }, 1L },   /* 1 */
    { 1, -1, { 1 }, 1L },   /* -1 */

    { 0,  1, { 1 }, 0L },   /* .1 */
    { 0, -1, { 1 }, 0L },   /* -.1 */

    { -1,  1, { 1 }, 0L },  /* ._1 */
    { -1, -1, { 1 }, 0L },  /* -._1 */

    { -999,          1, { 1 }, 0L },   /* .___1 small */
    { MP_EXP_T_MIN,  1, { 1 }, 0L },   /* .____1 very small */

    { 999,          1, { 1 }, 0L },    /* 1____. big */
    { MP_EXP_T_MAX, 1, { 1 }, 0L },    /* 1_____. very big */

    { 1, 2, { 999, 2 }, 2L },                  /* 2.9 */
    { 5, 8, { 7, 8, 9, 3, 0, 0, 0, 1 }, 3L },  /* 10003.987 */

    { 2, 2, { M, M },    ULONG_MAX }, /* FF. */
    { 2, 2, { M, M, M }, ULONG_MAX }, /* FF.F */
    { 3, 3, { M, M, M }, ULONG_MAX }, /* FFF. */

#if GMP_NUMB_BITS >= BITS_PER_ULONG
    /* normal case, numb bigger than long */
    { 2,  1, { 1 },    0L },      /* 1_. */
    { 2,  2, { 0, 1 }, 0L },      /* 10. */
    { 2,  2, { 999, 1 }, 999L },  /* 19. */
    { 3,  2, { 999, 1 }, 0L },    /* 19_. */

#else
    /* nails case, numb smaller than long */
    { 2,  1, { 1 }, 1L << GMP_NUMB_BITS },  /* 1_. */
    { 3,  1, { 1 }, 0L },                   /* 1__. */

    { 2,  2, { 99, 1 },    99L + (1L << GMP_NUMB_BITS) },  /* 19. */
    { 3,  2, { 1, 99 },    1L << GMP_NUMB_BITS },          /* 91_. */
    { 3,  3, { 0, 1, 99 }, 1L << GMP_NUMB_BITS },          /* 910. */

#endif
  };

  mpf_t          f;
  unsigned long  got;
  int            i;
  mp_limb_t      buf[20 + numberof(data[i].d)];

  for (i = 0; i < numberof (data); i++)
    {
      refmpn_fill (buf, 10, CNST_LIMB(0xDEADBEEF));
      refmpn_copy (buf+10, data[i].d, ABS(data[i].size));
      refmpn_fill (buf+10+ABS(data[i].size), 10, CNST_LIMB(0xDEADBEEF));

      PTR(f) = buf+10;
      EXP(f) = data[i].exp;
      SIZ(f) = data[i].size;
      PREC(f) = numberof (data[i].d);
      MPF_CHECK_FORMAT (f);

      got = mpf_get_ui (f);
      if (got != data[i].want)
        {
          printf    ("mpf_get_ui wrong at limb data[%d]\n", i);
          mpf_trace ("  f", f);
          mpn_trace ("  d", data[i].d, data[i].size);
          printf    ("  size %ld\n", (long) data[i].size);
          printf    ("  exp %ld\n", (long) data[i].exp);
          printf    ("  got   %lu (0x%lX)\n", got, got);
          printf    ("  want  %lu (0x%lX)\n", data[i].want, data[i].want);
          abort();
        }
    }
}
Ejemplo n.º 7
0
Archivo: util.c Proyecto: tyru/dentaku
unsigned long
digit2ulong(Digit *src)
{
    return mpf_get_ui(*src);
}