Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- (unknown)
Instance Method Summary collapse
-
#to_mpfr ⇒ MPFR
Return a MPFR object with a just enough bits of precision to accomodate the value of self.
- #to_sollya ⇒ Object
Instance Method Details
#to_mpfr ⇒ MPFR
Return a MPFR object with a just enough bits of precision to accomodate the value of self.
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'ext/mpfr_rb.c', line 486
static VALUE mpfrrb_Integer_to_mpfr(VALUE self)
{
if (RB_FIXNUM_P(self)) {
long int v = NUM2LL(self);
mpfr_prec_t p;
if (v > 0) {
p = (mpfr_prec_t)ceil(log2((double)(v + 1)));
} else if (v < 0) {
p = (mpfr_prec_t)ceil(log2((double)(1 - v)));
} else {
p = 1;
}
VALUE obj = mpfrrb_alloc(c_MPFR);
mpfr_ptr mp = mpfrrb_rb2ref(obj);
mpfr_init2(mp, p);
mpfr_set_si(mp, v, MPFR_RNDN);
return obj;
} else {
mpz_t mpz;
mpz_init(mpz);
mpfrrb_bignum_to_mpz(self, mpz);
int nlz_bits_ret;
size_t nb_bytes = rb_absint_size(self, &nlz_bits_ret);
mpfr_prec_t p = nb_bytes*8 - nlz_bits_ret;
VALUE obj = mpfrrb_alloc(c_MPFR);
mpfr_ptr mp = mpfrrb_rb2ref(obj);
mpfr_init2(mp, p);
mpfr_set_z(mp, mpz, MPFR_RNDN);
mpz_clear(mpz);
return obj;
}
}
|
#to_sollya ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'ext/sollya_rb.c', line 257
static VALUE sollyarb_integer_to_sollya(VALUE self)
{
if (RB_FIXNUM_P(self)) {
return sollyarb_ref2rb(sollya_lib_constant_from_int64(NUM2LL(self)), c_SolFunction);
}
mpz_t mpz;
mpz_init(mpz);
mpfrrb_bignum_to_mpz(self, mpz);
VALUE r = sollyarb_ref2rb(sollya_lib_constant_from_mpz(mpz), c_SolFunction);
mpz_clear(mpz);
return r;
}
|