src/bignum-gem.c
static mrb_value
new_bignum(mrb_state *mrb, mpz_t num, mrb_bool fixnum_conv)
{
  struct Bignum *b;

  /* Can we return a Fixnum? */
  if (fixnum_conv) {
    mrb_value fix = bignum_to_fixnum(num);
    if (mrb_fixnum_p(fix)) {
      /* Return a Fixnum */
      return fix;
    }
  }

  /* Return a Bignum */
  b = mrb_malloc(mrb, sizeof(*b));
  mpz_init_set(b->num, num);
  return mrb_obj_value(mrb_data_object_alloc(mrb,
        mrb_class_get(mrb, "Bignum"), b, &bignum_type));
}
/* Create a new Bignum or Fixnum as a Ruby object */
Create a new Bignum or Fixnum as a Ruby object
Create a new Bignum or Fixnum as a Ruby object
static mrb_value
new_bignum(mrb_state *mrb, mpz_t num, mrb_bool fixnum_conv)
{
  struct Bignum *b;
  if (fixnum_conv) {
    mrb_value fix = bignum_to_fixnum(num);
    if (mrb_fixnum_p(fix)) {
      return fix;
    }
  }
  b = mrb_malloc(mrb, sizeof(*b));
  mpz_init_set(b->num, num);
  return mrb_obj_value(mrb_data_object_alloc(mrb,
        mrb_class_get(mrb, "Bignum"), b, &bignum_type));
}
static mrb_value new_bignum ( mrb_state * mrb , mpz_t num , mrb_bool fixnum_conv ) { struct Bignum * b ; if ( fixnum_conv ) { mrb_value fix = bignum_to_fixnum ( num ) ; if ( mrb_fixnum_p ( fix ) ) { return fix ; } } b = mrb_malloc ( mrb , sizeof ( * b ) ) ; mpz_init_set ( b -> num , num ) ; return mrb_obj_value ( mrb_data_object_alloc ( mrb , mrb_class_get ( mrb , " " ) , b , & bignum_type ) ) ; }
Create a new Bignum or Fixnum as a Ruby object
Create a new Bignum or Fixnum as a Ruby object
/* Can we return a Fixnum? */ /* Return a Fixnum */ /* Return a Bignum */