private static SObject wrapF(object o) { if (o is Int32 && SFixnum.inFixnumRange((int)o)) { return(Factory.makeFixnum((int)o)); } else { return(Factory.makeForeignBox(o)); } }
public static SObject op1_fxnegative(SObject arg) { expect1(arg.isFixnum(), arg, Constants.EX_FXNEG); int a = ((SFixnum)arg).value; if (!SFixnum.inFixnumRange(-a)) { Exn.fault(Constants.EX_FXNEG, "result not a fixnum", arg); } return(Factory.makeNumber(-a)); }
public static SObject makeNumber(int num) { // Bignums are sign + magnitude, so we need to convert // negative numbers to the positive equivalent. // We have to be tricky here because simply negating // the num might fall out of the range of representable // signed integers. Therefore, we cast it to a long first. return (SFixnum.inFixnumRange(num) ? SFixnum.makeFixnum(num) : (num < 0) ? (SObject)makeBignum((ulong)(-((long)(num))), false) : (SObject)makeBignum((ulong)num, true)); }
public static SObject op2_fxmul(SObject arg1, SObject arg2) { expect2(arg1.isFixnum(), arg1, arg2.isFixnum(), arg2, Constants.EX_FXMUL); int a = ((SFixnum)arg1).value; int b = ((SFixnum)arg2).value; int c = a * b; if (!SFixnum.inFixnumRange(c)) { Exn.fault(Constants.EX_FXMUL, "result not a fixnum", arg1, arg2); } return(Factory.makeNumber(c)); }
public static SObject makeNumber(long num) { // Bignums are sign + magnitude, so we need to convert // negative numbers to the positive equivalent. // We have to be tricky here because simply negating // the num might fall out of the range of representable // signed longs. We therefore add 1 before negating it // (effectively subtracting 1 from the magnitude) and // then add 1 after casting to restore magnitude. return (SFixnum.inFixnumRange(num) ? SFixnum.makeFixnum((int)num) : (num < 0) ? (SObject)makeBignum(((ulong)(-(num + 1))) + 1, false) : (SObject)makeBignum((ulong)num, true)); }
public static SObject makeNumber(ulong num) { return(SFixnum.inFixnumRange(num) ? SFixnum.makeFixnum((int)num) : (SObject)makeBignum(num, true)); }