Esempio n. 1
0
        private T _Translate(IntegerNumber n)
        {
            string chars   = n.Annotations["chars"] as string;
            bool   dominus = false;

            if (chars == null)
            {
                chars   = n.Num.ToString();
                dominus = chars[0] == '-';
                if (dominus)
                {
                    chars = chars.Substring(1, chars.Length - 1);
                }
            }
            T t = __TranslateNumber(dominus ? null : n, chars);

            if (dominus)
            {
                return(__WrapTranslatedExpr(n, __TranslateOperator(null, Unicode.M.MINUS_SIGN, Syntax.TType.Op), t));
            }
            else
            {
                return(t);
            }
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            if (obj.GetType() != this.GetType())
            {
                return(false);
            }
            IntegerNumber intn = (IntegerNumber)obj;

            return(_num.Equals(intn._num));
        }
Esempio n. 3
0
        private T _Translate(ComplexNumber n)
        {
            IntegerNumber  ri = n.Re as IntegerNumber;
            RationalNumber rr = n.Re as RationalNumber;
            IntegerNumber  ii = n.Im as IntegerNumber;
            RationalNumber ir = n.Im as RationalNumber;
            List <T>       ts = new List <T>();

            if (!((ri != null && ri.Num == 0) || (rr != null && rr.Num == 0)))
            {
                ts.Add(Translate(n.Re));
            }
            int? isgn    = null;
            bool?isone   = null;
            bool special = false;

            if (ii != null)
            {
                isgn    = ii.Num > 0 ? 1 : ii.Num < 0 ? -1 : 0;
                isone   = ii.Num == 1 || ii.Num == -1;
                special = true;
            }
            else if (ir != null)
            {
                isgn    = ir.Num > 0 ? 1 : ir.Num < 0 ? -1 : 0;
                isone   = ir.Num == 1 || ir.Num == -1;
                special = true;
            }
            if (special)
            {
                if (isgn == 0)
                {
                    if (ts.Count == 0)
                    {
                        ts.Add(Translate(n.Re));
                    }
                }
                else
                {
                    if (isone.Value)
                    {
                        if (isgn == 1)
                        {
                            if (ts.Count != 0)
                            {
                                ts.Add(__TranslateOperator(null, '+', Syntax.TType.Op));
                            }
                        }
                        else
                        {
                            ts.Add(__TranslateOperator(null, Unicode.M.MINUS_SIGN, Syntax.TType.Op));
                        }
                    }
                    else
                    {
                        if (isgn == 1 && ts.Count != 0)
                        {
                            ts.Add(__TranslateOperator(null, '+', Syntax.TType.Op));
                        }
                        ts.Add(Translate(n.Im));
                    }
                    ts.Add(Translate(WellKnownSym.i));
                }
            }
            else
            {
                DoubleNumber dn = (DoubleNumber)n.Im;
                string       im = dn.ToString();
                if (im[0] != '-' && ts.Count != 0)
                {
                    ts.Add(__TranslateOperator(null, '+', Syntax.TType.Op));
                }
                ts.Add(Translate(n.Im));
                ts.Add(Translate(WellKnownSym.i));
            }
            return(__WrapTranslatedExpr(n, ts));
        }
Esempio n. 4
0
 public ComplexNumber(IntegerNumber re, IntegerNumber im)
 {
     _re = re; _im = im;
 }