Module: Kernel
- Defined in:
- (unknown)
Instance Method Summary collapse
-
#MPFR(*args) ⇒ Object
Return new MPFR instance.
Instance Method Details
#MPFR(*args) ⇒ Object
Return new MPFR instance. The same arguments as MPFR.new is acceptable.
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'ext/mpfr/ruby_mpfr.c', line 445
static VALUE r_mpfr_global_new(int argc, VALUE *argv, VALUE self)
{
MPFR *ptr;
VALUE val;
mp_prec_t prec;
mp_rnd_t rnd;
switch(argc){
case 0:
r_mpfr_make_struct_init(val, ptr);
mpfr_set_nan(ptr);
return val;
case 1:
prec = mpfr_get_default_prec();
rnd = mpfr_get_default_rounding_mode();
break;
case 2:
if (SYMBOL_P(argv[1])) {
rnd = r_mpfr_rnd_from_value(argv[1]);
prec = mpfr_get_default_prec();
} else if (FIXNUM_P(argv[1])) {
prec = NUM2INT(argv[1]);
rnd = mpfr_get_default_rounding_mode();
} else {
rb_raise(rb_eArgError, "Invalid argument.");
}
break;
case 3:
r_mpfr_get_rnd_prec_from_optional_arguments(&rnd, &prec, 1, 3, argc, argv);
break;
default:
rb_raise(rb_eArgError, "Invalid number of arguments.");
break;
}
if(MPFR_P(argv[0])){
MPFR *ptr_obj;
r_mpfr_get_struct(ptr_obj, argv[0]);
r_mpfr_make_struct_init2(val, ptr, prec);
mpfr_set(ptr, ptr_obj, rnd);
}else{
switch(TYPE(argv[0])){
case T_STRING:
r_mpfr_make_struct_init2(val, ptr, prec);
mpfr_set_str(ptr, StringValuePtr(argv[0]), 10, rnd);
break;
case T_FLOAT:
r_mpfr_make_struct_init2(val, ptr, prec);
mpfr_set_d(ptr, NUM2DBL(argv[0]), rnd);
break;
case T_FIXNUM:
r_mpfr_make_struct_init2(val, ptr, prec);
mpfr_set_si(ptr, FIX2LONG(argv[0]), rnd);
break;
case T_BIGNUM:
r_mpfr_make_struct_init2(val, ptr, prec);
r_mpfr_convert_to_str_set(ptr, argv[0], rnd);
break;
default:
val = r_mpfr_robj_to_mpfr(argv[0], argc - 1, argv + 1);
break;
}
}
return val;
}
|