Example #1
0
        public static object Abs(object o)
        {
            if (o is int)
            {
                return(IntOps.Abs((int)o));
            }
            if (o is long)
            {
                return(Int64Ops.Abs((long)o));
            }
            if (o is double)
            {
                return(FloatOps.Abs((double)o));
            }
            if (o is bool)
            {
                return(((bool)o) ? 1 : 0);
            }
            if (o is string)
            {
                throw Ops.TypeError("bad operand type for abs()");
            }
            BigInteger bi = o as BigInteger;

            if (!Object.Equals(bi, null))
            {
                return(LongOps.Abs(bi));
            }
            if (o is Complex64)
            {
                return(ComplexOps.Abs((Complex64)o));
            }

            object ret;

            if (Ops.TryToInvoke(o, SymbolTable.AbsoluteValue, out ret))
            {
                return(ret);
            }
            else
            {
                throw Ops.TypeError("bad operand type for abs()");
            }
        }