예제 #1
0
 private static SObject wrapF(object o)
 {
     if (o is Int32 && SFixnum.inFixnumRange((int)o))
     {
         return(Factory.makeFixnum((int)o));
     }
     else
     {
         return(Factory.makeForeignBox(o));
     }
 }
예제 #2
0
파일: ClassicOps.cs 프로젝트: zen3d/larceny
        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));
        }
예제 #3
0
파일: Factory.cs 프로젝트: zen3d/larceny
 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));
 }
예제 #4
0
파일: ClassicOps.cs 프로젝트: zen3d/larceny
        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));
        }
예제 #5
0
파일: Factory.cs 프로젝트: zen3d/larceny
        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));
        }
예제 #6
0
파일: Factory.cs 프로젝트: zen3d/larceny
 public static SObject makeNumber(ulong num)
 {
     return(SFixnum.inFixnumRange(num)
        ? SFixnum.makeFixnum((int)num)
        : (SObject)makeBignum(num, true));
 }