示例#1
0
文件: Expr.cs 项目: buptkang/MathCog
        public override bool Equals(object obj)
        {
            if (obj.GetType() != this.GetType())
            {
                return(false);
            }
            DoubleNumber dn = (DoubleNumber)obj;

            return(_num == dn._num);
        }
示例#2
0
        private T _Translate(DoubleNumber n)
        {
            string chars = n.Annotations["chars"] as string;

            if (chars != null)
            {
                return(__TranslateNumber(n, chars));
            }
            else
            {
                return(__Translate(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));
        }
示例#4
0
 protected abstract T __Translate(DoubleNumber n);
示例#5
0
文件: Expr.cs 项目: buptkang/MathCog
 /* next two constructors are just here so you can use autoconversions */
 public ComplexNumber(DoubleNumber re, DoubleNumber im)
 {
     _re = re; _im = im;
 }