Skip to content

Instantly share code, notes, and snippets.

@kronos
Created April 6, 2010 23:50
Show Gist options
  • Select an option

  • Save kronos/358283 to your computer and use it in GitHub Desktop.

Select an option

Save kronos/358283 to your computer and use it in GitHub Desktop.
diff --git a/vm/builtin/fixnum.cpp b/vm/builtin/fixnum.cpp
index 679c5f1..5d51798 100644
--- a/vm/builtin/fixnum.cpp
+++ b/vm/builtin/fixnum.cpp
@@ -126,7 +126,7 @@ namespace rubinius {
native_int denominator = other->to_native();
native_int quotient = div(state, other)->to_native();
native_int modulo = numerator - denominator * quotient;
-
+
if((modulo < 0 && denominator > 0) || (modulo > 0 && denominator < 0)) {
return Fixnum::from(modulo + denominator);
} else {
@@ -283,14 +283,20 @@ namespace rubinius {
Integer* Fixnum::left_shift(STATE, Fixnum* bits) {
native_int shift = bits->to_native();
+ native_int self = to_native();
+
+ if (self == 0) {
+ return Fixnum::from(0);
+ }
+
if(shift < 0) {
return right_shift(state, Fixnum::from(-shift));
}
- native_int self = to_native();
+ native_int check = self > 0 ? self : -self;
if(shift >= (native_int)FIXNUM_WIDTH
- || self >> ((native_int)FIXNUM_WIDTH - shift) > 0) {
+ || check >> ((native_int)FIXNUM_WIDTH - shift) > 0) {
return Bignum::from(state, self)->left_shift(state, bits);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment