Permalink
Browse files

re-implemented #rand and #srand to use random(3) and srandom(3), fast…

…er and thread-safe (patch contributed by Thibault Martin-Lagardette)

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@2826 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent ddad2fa commit 8f9d863c989e31aa44736751dc850b6ed371fdae @lrz lrz committed Oct 16, 2009
Showing with 195 additions and 388 deletions.
  1. +9 −3 bignum.c
  2. +3 −0 include/ruby/intern.h
  3. +8 −1 numeric.c
  4. +139 −384 random.c
  5. +32 −0 vm.cpp
  6. +4 −0 vm.h
View
@@ -1377,8 +1377,8 @@ rb_big_eql(VALUE x, SEL sel, VALUE y)
* Unary minus (returns a new Bignum whose value is 0-big)
*/
-static VALUE
-rb_big_uminus(VALUE x, SEL sel)
+VALUE
+rb_big_uminus(VALUE x)
{
VALUE z = rb_big_clone(x);
@@ -1387,6 +1387,12 @@ rb_big_uminus(VALUE x, SEL sel)
return bignorm(z);
}
+static VALUE
+rb_big_uminus_imp(VALUE x, SEL sel)
+{
+ return rb_big_uminus(x);
+}
+
/*
* call-seq:
* ~big => integer
@@ -2833,7 +2839,7 @@ Init_Bignum(void)
rb_objc_define_method(rb_cBignum, "to_s", rb_big_to_s, -1);
rb_objc_define_method(rb_cBignum, "coerce", rb_big_coerce, 1);
- rb_objc_define_method(rb_cBignum, "-@", rb_big_uminus, 0);
+ rb_objc_define_method(rb_cBignum, "-@", rb_big_uminus_imp, 0);
rb_objc_define_method(rb_cBignum, "+", rb_big_plus_imp, 1);
rb_objc_define_method(rb_cBignum, "-", rb_big_minus_imp, 1);
rb_objc_define_method(rb_cBignum, "*", rb_big_mul_imp, 1);
View
@@ -124,6 +124,7 @@ VALUE rb_big_or(VALUE, VALUE);
VALUE rb_big_xor(VALUE, VALUE);
VALUE rb_big_lshift(VALUE, VALUE);
VALUE rb_big_rshift(VALUE, VALUE);
+VALUE rb_big_uminus(VALUE x);
/* rational.c */
VALUE rb_rational_raw(VALUE, VALUE);
#define rb_rational_raw1(x) rb_rational_raw(x, INT2FIX(1))
@@ -415,6 +416,8 @@ VALUE rb_num_coerce_relop(VALUE, VALUE, SEL);
VALUE rb_float_new(double);
VALUE rb_num2fix(VALUE);
VALUE rb_fix2str(VALUE, int);
+VALUE rb_fix_minus(VALUE x, VALUE y);
+VALUE rb_fix_uminus(VALUE num);
VALUE rb_dbl_cmp(double, double);
/* object.c */
VALUE rb_send_dup(VALUE);
View
@@ -2131,10 +2131,17 @@ rb_flo_induced_from(VALUE klass, SEL sel, VALUE x)
* Negates <code>fix</code> (which might return a Bignum).
*/
+VALUE
+rb_fix_uminus(VALUE num)
+{
+ return LONG2NUM(-FIX2LONG(num));
+}
+
+
static VALUE
fix_uminus(VALUE num, SEL sel)
{
- return LONG2NUM(-FIX2LONG(num));
+ return rb_fix_uminus(num);
}
VALUE
Oops, something went wrong.

0 comments on commit 8f9d863

Please sign in to comment.