Example #1
0
            internal static bool TryPulling(TrigTable table, ComplexNumber arg, out Entity res)
            {
                if (arg.IsImaginary())
                {
                    res = null;
                    return(false);
                }
                // arg in [0; 2pi]
                var dArg = arg.Real.Value;

                EDecimal Remainder(EDecimal a, EDecimal divisor)
                => a.RemainderNoRoundAfterDivide(divisor, MathS.Settings.DecimalPrecisionContext);

                var twoPi = RealNumber.CtxMultiply(2, MathS.DecimalConst.pi);

                dArg = Remainder(
                    RealNumber.CtxAdd(       // (
                        Remainder(dArg       //     dArg
                                  ,          //     %
                                  twoPi)     //     2pi
                        ,                    //   +
                        twoPi                //   2pi
                        )                    // )
                    ,                        // %
                    twoPi                    // 2pi
                    );

                int begin = 0;
                int end   = table.Count - 1;

                while (end - begin > 1)
                {
                    var mid = (end + begin) / 2;
                    if (EDecimalWrapper.IsGreater(table[mid].arg, dArg))
                    {
                        begin = mid;
                    }
                    else
                    {
                        end = mid;
                    }
                    if (end >= table.Count)
                    {
                        res = null;
                        return(false);
                    }
                }

                for (var j = begin; j <= end; j++)
                {
                    if (Number.Functional.IsZero(table[j].arg - dArg))
                    {
                        res = table[j].res;
                        return(true);
                    }
                }
                res = null;
                return(false);
            }
Example #2
0
        /// <summary>
        /// if num is ABC, the initial number was 0.ABC
        /// </summary>
        /// <param name="num"></param>
        /// <param name="N"></param>
        /// <returns></returns>
        internal static EDecimal FloatFromBaseN(string num, int N)
        {
            EDecimal res = 0;

            for (int i = 0; i < num.Length; i++)
            {
                char digit = num[i];
                res = RealNumber.CtxAdd(res, RealNumber.CtxDivide(ALPHABET_FROMCHAR[digit], EDecimal.FromInt32(N).Pow(i + 1)));
            }
            return(res);
        }