Skip to content

Commit

Permalink
Rewrite numor, numand, and numxor to handle BigIntegers.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Jan 5, 2013
1 parent 95f809a commit aea5a41
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions lib/Builtins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,9 +1552,18 @@ [ImplicitConsts] public static Variable numand(Constants c, Variable v1, Variabl
if (!(o1.mo.is_any && o2.mo.is_any))
return HandleSpecial2(c, v1,v2, o1,o2, numand_d);

int r1 = (int)o1.mo.mro_raw_Numeric.Get(v1);
int r2 = (int)o2.mo.mro_raw_Numeric.Get(v2);
return c.setting.MakeInt(r1 & r2);
int small1, small2; BigInteger big1, big2;
bool b1 = GetAsInteger(v1, out small1, out big1);
bool b2 = GetAsInteger(v2, out small2, out big2);
var s = c.setting;

if (b1 || b2 || small1 == int.MinValue || small2 == int.MinValue) {
if (!b1) big1 = small1;
if (!b2) big2 = small2;
return s.MakeInt(big1 & big2);
} else {
return s.MakeInt(small1 & small2);
}
}

static readonly Func<Constants,Variable,Variable,Variable> numor_d = numor;
Expand All @@ -1563,9 +1572,18 @@ [ImplicitConsts] public static Variable numor(Constants c, Variable v1, Variable
if (!(o1.mo.is_any && o2.mo.is_any))
return HandleSpecial2(c, v1,v2, o1,o2, numor_d);

int r1 = (int)o1.mo.mro_raw_Numeric.Get(v1);
int r2 = (int)o2.mo.mro_raw_Numeric.Get(v2);
return c.setting.MakeInt(r1 | r2);
int small1, small2; BigInteger big1, big2;
bool b1 = GetAsInteger(v1, out small1, out big1);
bool b2 = GetAsInteger(v2, out small2, out big2);
var s = c.setting;

if (b1 || b2 || small1 == int.MinValue || small2 == int.MinValue) {
if (!b1) big1 = small1;
if (!b2) big2 = small2;
return s.MakeInt(big1 | big2);
} else {
return s.MakeInt(small1 | small2);
}
}

static readonly Func<Constants,Variable,Variable,Variable> numxor_d = numxor;
Expand All @@ -1574,9 +1592,18 @@ [ImplicitConsts] public static Variable numxor(Constants c, Variable v1, Variabl
if (!(o1.mo.is_any && o2.mo.is_any))
return HandleSpecial2(c, v1,v2, o1,o2, numxor_d);

int r1 = (int)o1.mo.mro_raw_Numeric.Get(v1);
int r2 = (int)o2.mo.mro_raw_Numeric.Get(v2);
return c.setting.MakeInt(r1 ^ r2);
int small1, small2; BigInteger big1, big2;
bool b1 = GetAsInteger(v1, out small1, out big1);
bool b2 = GetAsInteger(v2, out small2, out big2);
var s = c.setting;

if (b1 || b2 || small1 == int.MinValue || small2 == int.MinValue) {
if (!b1) big1 = small1;
if (!b2) big2 = small2;
return s.MakeInt(big1 ^ big2);
} else {
return s.MakeInt(small1 ^ small2);
}
}

static readonly Func<Constants,Variable,Variable,Variable> numlshift_d = numlshift;
Expand Down

0 comments on commit aea5a41

Please sign in to comment.