Пример #1
0
        public static async Task Calc(CommandContext bc)
        {
            if (bc.MessageTokens.Length == 1)
            {
                await bc.SendReply("Syntax: !calc <expression>");
                return;
            }

            var mp = new MathParser();
            mp.Evaluate(bc.MessageTokens.Join(1));
            await bc.SendReply(@"\c07{0}\c => \c07{1}\c", mp.Expression, mp.ValueAsString);
        }
Пример #2
0
        public static bool TryCalc(string s, out double result_value)
        {
            result_value = 0;

            if (s == null)
            {
                return false;
            }

            s = s.Trim();
            if (s.Length == 0)
            {
                return false;
            }

            // evaluate and output the result
            var c = new MathParser();
            c.Evaluate(s);
            if (c.Value != null)
            {
                result_value = (double) c.Value;
                return true;
            }

            return false;
        }