From 8ed8664aa7ca657f536d507ac6de84d71e02e31b Mon Sep 17 00:00:00 2001 From: dave Date: Fri, 19 Dec 2003 03:58:57 +0000 Subject: Add boot_classes to rdoc parsing, fix a couple of bugs git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) (limited to 'bignum.c') diff --git a/bignum.c b/bignum.c index 9fe9a33fa5..255b5d141f 100644 --- a/bignum.c +++ b/bignum.c @@ -872,6 +872,15 @@ rb_big2dbl(x) return d; } +/* + * call-seq: + * big.to_f -> float + * + * Converts big to a Float. If big doesn't + * fit in a Float, the result is infinity. + * + */ + static VALUE rb_big_to_f(x) VALUE x; @@ -879,6 +888,16 @@ rb_big_to_f(x) return rb_float_new(rb_big2dbl(x)); } +/* + * call-seq: + * big <=> numeric => -1, 0, +1 + * + * Comparison---Returns -1, 0, or +1 depending on whether big is + * less than, equal to, or greater than numeric. This is the + * basis for the tests in Comparable. + * + */ + static VALUE rb_big_cmp(x, y) VALUE x, y; @@ -914,6 +933,17 @@ rb_big_cmp(x, y) (RBIGNUM(x)->sign ? INT2FIX(-1) : INT2FIX(1)); } +/* + * call-seq: + * big == obj => true or false + * + * Returns true only if obj has the same value + * as big. Contrast this with Bignum#eql?, which + * requires obj to be a Bignum. + * + * 68719476736 == 68719476736.0 #=> true + */ + static VALUE rb_big_eq(x, y) VALUE x, y; @@ -938,6 +968,17 @@ rb_big_eq(x, y) return Qtrue; } +/* + * call-seq: + * big.eql?(obj) => true or false + * + * Returns true only if obj is a + * Bignum with the same value as big. Contrast this + * with Bignum#==, which performs type conversions. + * + * 68719476736.eql?(68719476736.0) #=> false + */ + static VALUE rb_big_eql(x, y) VALUE x, y; @@ -967,6 +1008,18 @@ rb_big_uminus(x) return bignorm(z); } +/* + * call-seq: + * ~big => integer + * + * Inverts the bits in big. As Bignums are conceptually infinite + * length, the result acts as if it had an infinite number of one + * bits to the left. In hex representations, this is displayed + * as two periods to the left of the digits. + * + * sprintf("%X", ~0x1122334455) #=> "..FEEDDCCBBAA" + */ + static VALUE rb_big_neg(x) VALUE x; @@ -1602,6 +1655,13 @@ rb_big_and(x, y) return bignorm(z); } +/* + * call-seq: + * big | numeric => integer + * + * Performs bitwise +or+ between _big_ and _numeric_. + */ + VALUE rb_big_or(x, y) VALUE x, y; @@ -1652,6 +1712,13 @@ rb_big_or(x, y) return bignorm(z); } +/* + * call-seq: + * big ^ numeric => integer + * + * Performs bitwise +exclusive or+ between _big_ and _numeric_. + */ + VALUE rb_big_xor(x, y) VALUE x, y; @@ -1706,6 +1773,13 @@ rb_big_xor(x, y) static VALUE rb_big_rshift _((VALUE,VALUE)); +/* + * call-seq: + * big << numeric => integer + * + * Shifts big left _numeric_ positions (right if _numeric_ is negative). + */ + VALUE rb_big_lshift(x, y) VALUE x, y; @@ -1735,6 +1809,13 @@ rb_big_lshift(x, y) return bignorm(z); } +/* + * call-seq: + * big >> numeric => integer + * + * Shifts big right _numeric_ positions (left if _numeric_ is negative). + */ + static VALUE rb_big_rshift(x, y) VALUE x, y; @@ -1777,6 +1858,25 @@ rb_big_rshift(x, y) return bignorm(z); } +/* + * call-seq: + * big[n] -> 0, 1 + * + * Bit Reference---Returns the nth bit in the (assumed) binary + * representation of big, where big[0] is the least + * significant bit. + * + * a = 9**15 + * 50.downto(0) do |n| + * print a[n] + * end + * + * produces: + * + * 000101110110100000111000011110010100111100010111001 + * + */ + static VALUE rb_big_aref(x, y) VALUE x, y; @@ -1842,6 +1942,15 @@ rb_big_coerce(x, y) return Qnil; } +/* + * call-seq: + * big.abs -> aBignum + * + * Returns the absolute value of big. + * + * -1234567890987654321.abs #=> 1234567890987654321 + */ + static VALUE rb_big_abs(x) VALUE x; @@ -1872,6 +1981,18 @@ rb_big_rand(max, rand_buf) return rb_big_modulo((VALUE)v, max); } +/* + * call-seq: + * big.size -> integer + * + * Returns the number of bytes in the machine representation of + * big. + * + * (256**10 - 1).size #=> 12 + * (256**20 - 1).size #=> 20 + * (256**40 - 1).size #=> 40 + */ + static VALUE rb_big_size(big) VALUE big; -- cgit v1.2.3