Module: Bug::Rational

Defined in:
ext/-test-/rational/rat.c

Constant Summary collapse

INTEGER_PACK_MSWORD_FIRST =
INT2NUM(INTEGER_PACK_MSWORD_FIRST)
INTEGER_PACK_LSWORD_FIRST =
INT2NUM(INTEGER_PACK_LSWORD_FIRST)
INTEGER_PACK_MSBYTE_FIRST =
INT2NUM(INTEGER_PACK_MSBYTE_FIRST)
INTEGER_PACK_LSBYTE_FIRST =
INT2NUM(INTEGER_PACK_LSBYTE_FIRST)
INTEGER_PACK_NATIVE_BYTE_ORDER =
INT2NUM(INTEGER_PACK_NATIVE_BYTE_ORDER)
INTEGER_PACK_2COMP =
INT2NUM(INTEGER_PACK_2COMP)
INTEGER_PACK_LITTLE_ENDIAN =
INT2NUM(INTEGER_PACK_LITTLE_ENDIAN)
INTEGER_PACK_BIG_ENDIAN =
INT2NUM(INTEGER_PACK_BIG_ENDIAN)
INTEGER_PACK_FORCE_BIGNUM =
INT2NUM(INTEGER_PACK_FORCE_BIGNUM)
INTEGER_PACK_NEGATIVE =
INT2NUM(INTEGER_PACK_NEGATIVE)
INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION =
INT2NUM(INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.big2str_generic(x, vbase) ⇒ Object



14
15
16
17
18
19
20
21
# File 'ext/-test-/bignum/big2str.c', line 14

static VALUE
big2str_generic(VALUE klass, VALUE x, VALUE vbase)
{
    int base = NUM2INT(vbase);
    if (base < 2 || 36 < base)
        rb_raise(rb_eArgError, "invalid radix %d", base);
    return rb_big2str_generic(big(x), base);
}

.big2str_gmp(x, vbase) ⇒ Object



35
36
37
38
39
40
41
42
# File 'ext/-test-/bignum/big2str.c', line 35

static VALUE
big2str_gmp(VALUE klass, VALUE x, VALUE vbase)
{
    int base = NUM2INT(vbase);
    if (base < 2 || 36 < base)
        rb_raise(rb_eArgError, "invalid radix %d", base);
    return rb_big2str_gmp(big(x), base);
}

.big2str_poweroftwo(x, vbase) ⇒ Object



25
26
27
28
29
30
31
32
# File 'ext/-test-/bignum/big2str.c', line 25

static VALUE
big2str_poweroftwo(VALUE klass, VALUE x, VALUE vbase)
{
    int base = NUM2INT(vbase);
    if (base < 2 || 36 < base || !POW2_P(base))
        rb_raise(rb_eArgError, "invalid radix %d", base);
    return rb_big2str_poweroftwo(big(x), base);
}

.gcd_gmp(x, y) ⇒ Object



23
24
25
26
27
# File 'ext/-test-/rational/rat.c', line 23

static VALUE
gcd_gmp(VALUE klass, VALUE x, VALUE y)
{
    return rb_big_norm(rb_gcd_gmp(big(x), big(y)));
}

.gcd_normal(x, y) ⇒ Object



16
17
18
19
20
# File 'ext/-test-/rational/rat.c', line 16

static VALUE
gcd_normal(VALUE klass, VALUE x, VALUE y)
{
    return rb_big_norm(rb_gcd_normal(rb_to_int(x), rb_to_int(y)));
}

.make_call_receiver(procarg) ⇒ Object



11
12
13
14
15
# File 'ext/-test-/proc/receiver.c', line 11

static VALUE
bug_proc_make_call_receiver(VALUE self, VALUE procarg)
{
    return rb_proc_new(bug_proc_call_receiver, procarg);
}

.negzero(length) ⇒ Object



12
13
14
15
16
17
18
19
# File 'ext/-test-/bignum/bigzero.c', line 12

static VALUE
bug_big_negzero(VALUE self, VALUE length)
{
    long len = NUM2ULONG(length);
    VALUE z = rb_big_new(len, 0);
    MEMZERO(BIGNUM_DIGITS(z), BDIGIT, len);
    return z;
}

.nofreeObject



3
4
5
6
7
# File 'ext/-test-/string/nofree.c', line 3

VALUE
bug_str_nofree(VALUE self)
{
    return rb_str_new_cstr("abcdef");
}

.raw(x, y) ⇒ Object



32
33
34
35
36
# File 'ext/-test-/rational/rat.c', line 32

static VALUE
s_rational_raw(VALUE klass, VALUE x, VALUE y)
{
    return rb_rational_raw(x, y);
}

.str2big_gmp(str, vbase, badcheck) ⇒ Object



22
23
24
25
26
# File 'ext/-test-/bignum/str2big.c', line 22

static VALUE
str2big_gmp(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
{
    return rb_str2big_gmp(str, NUM2INT(vbase), RTEST(badcheck));
}

.str2big_karatsuba(str, vbase, badcheck) ⇒ Object



15
16
17
18
19
# File 'ext/-test-/bignum/str2big.c', line 15

static VALUE
str2big_karatsuba(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
{
    return rb_str2big_karatsuba(str, NUM2INT(vbase), RTEST(badcheck));
}

.str2big_normal(str, vbase, badcheck) ⇒ Object



9
10
11
12
13
# File 'ext/-test-/bignum/str2big.c', line 9

static VALUE
str2big_normal(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
{
    return rb_str2big_normal(str, NUM2INT(vbase), RTEST(badcheck));
}

.str2big_poweroftwo(str, vbase, badcheck) ⇒ Object



3
4
5
6
7
# File 'ext/-test-/bignum/str2big.c', line 3

static VALUE
str2big_poweroftwo(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
{
    return rb_str2big_poweroftwo(str, NUM2INT(vbase), RTEST(badcheck));
}

.test_numbits_2comp_without_sign(val) ⇒ Object



47
48
49
50
51
52
53
54
# File 'ext/-test-/bignum/intpack.c', line 47

static VALUE
rb_integer_test_numbits_2comp_without_sign(VALUE klass, VALUE val)
{
  size_t size;
  int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val);
  size = rb_absint_numwords(val, 1, NULL) - (neg && rb_absint_singlebit_p(val));
  return SIZET2NUM(size);
}

.test_numbytes_2comp_with_sign(val) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'ext/-test-/bignum/intpack.c', line 56

static VALUE
rb_integer_test_numbytes_2comp_with_sign(VALUE klass, VALUE val)
{
  int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val);
  int nlz_bits;
  size_t size = rb_absint_size(val, &nlz_bits);
  if (nlz_bits == 0 && !(neg && rb_absint_singlebit_p(val)))
    size++;
  return SIZET2NUM(size);
}

.test_pack(val, numwords_arg, wordsize_arg, nails, flags) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'ext/-test-/bignum/intpack.c', line 19

static VALUE
rb_integer_pack_m(VALUE klass, VALUE val, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags)
{
  int sign;
  size_t numwords = NUM2SIZET(numwords_arg);
  size_t wordsize = NUM2SIZET(wordsize_arg);
  VALUE buf;

  if (numwords != 0 && wordsize != 0 && LONG_MAX / wordsize < numwords)
      rb_raise(rb_eArgError, "too big numwords * wordsize");
  buf = rb_str_new(NULL, numwords * wordsize);
  sign = rb_integer_pack(val,
      RSTRING_PTR(buf), numwords,
      wordsize, NUM2SIZET(nails), NUM2INT(flags));

  return rb_assoc_new(INT2NUM(sign), buf);
}

.test_pack_raw(val, buf, numwords_arg, wordsize_arg, nails, flags) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'ext/-test-/bignum/intpack.c', line 3

static VALUE
rb_integer_pack_raw_m(VALUE klass, VALUE val, VALUE buf, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags)
{
  int sign;
  size_t numwords = 0;
  size_t wordsize = NUM2SIZET(wordsize_arg);

  StringValue(buf);
  rb_str_modify(buf);
  sign = rb_integer_pack(val,
      RSTRING_PTR(buf), NUM2SIZET(numwords_arg),
      NUM2SIZET(wordsize_arg), NUM2SIZET(nails), NUM2INT(flags));

  return rb_ary_new_from_args(2, INT2NUM(sign), rb_str_new(RSTRING_PTR(buf), wordsize * numwords));
}

.test_unpack(buf, numwords, wordsize, nails, flags) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'ext/-test-/bignum/intpack.c', line 37

static VALUE
rb_integer_unpack_m(VALUE klass, VALUE buf, VALUE numwords, VALUE wordsize, VALUE nails, VALUE flags)
{
    StringValue(buf);

    return rb_integer_unpack(RSTRING_PTR(buf),
            NUM2SIZET(numwords), NUM2SIZET(wordsize),
            NUM2SIZET(nails), NUM2INT(flags));
}

.zero(length) ⇒ Object



3
4
5
6
7
8
9
10
# File 'ext/-test-/bignum/bigzero.c', line 3

static VALUE
bug_big_zero(VALUE self, VALUE length)
{
    long len = NUM2ULONG(length);
    VALUE z = rb_big_new(len, 1);
    MEMZERO(BIGNUM_DIGITS(z), BDIGIT, len);
    return z;
}

Instance Method Details

#get(name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'ext/-test-/struct/member.c', line 3

static VALUE
bug_struct_get(VALUE obj, VALUE name)
{
    ID id = rb_check_id(&name);

    if (!id) {
        rb_name_error_str(name, "`%"PRIsVALUE"' is not a struct member", name);
    }
    return rb_struct_getmember(obj, id);
}

#modify!Object



3
4
5
6
7
8
# File 'ext/-test-/string/modify.c', line 3

VALUE
bug_str_modify(VALUE str)
{
    rb_str_modify(str);
    return str;
}

#modify_expand!(expand) ⇒ Object



10
11
12
13
14
15
# File 'ext/-test-/string/modify.c', line 10

VALUE
bug_str_modify_expand(VALUE str, VALUE expand)
{
    rb_str_modify_expand(str, NUM2LONG(expand));
    return str;
}

#qsort!(*args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'ext/-test-/string/qsort.c', line 28

static VALUE
bug_str_qsort_bang(int argc, VALUE *argv, VALUE str)
{
    VALUE beg, len, size;
    long l, b = 0, n, s = 1;
    struct sort_data d;

    rb_scan_args(argc, argv, "03", &beg, &len, &size);
    l = RSTRING_LEN(str);
    if (!NIL_P(beg) && (b = NUM2INT(beg)) < 0 && (b += l) < 0) {
        rb_raise(rb_eArgError, "out of bounds");
    }
    if (!NIL_P(size) && (s = NUM2INT(size)) < 0) {
        rb_raise(rb_eArgError, "negative size");
    }
    if (NIL_P(len) ||
        (((n = NUM2INT(len)) < 0) ?
         (rb_raise(rb_eArgError, "negative length"), 0) :
         (b + n * s > l))) {
        n = (l - b) / s;
    }
    rb_str_modify(str);
    d.enc = rb_enc_get(str);
    d.elsize = s;
    ruby_qsort(RSTRING_PTR(str) + b, n, s,
               rb_block_given_p() ? cmp_1 : cmp_2, &d);
    return str;
}