Esempio n. 1
0
        private static object Combin(List <Expression> p)
        {
            Int32 n = (int)p[0];
            Int32 k = (int)p[1];

            return(XLMath.Combin(n, k));
        }
Esempio n. 2
0
        private static object Even(List <Expression> p)
        {
            var num      = (int)Math.Ceiling(p[0]);
            var addValue = num >= 0 ? 1 : -1;

            return(XLMath.IsEven(num) ? num : num + addValue);
        }
Esempio n. 3
0
        private static object Arabic(List <Expression> p)
        {
            string input = ((string)p[0]).Trim();

            try
            {
                if (input == "")
                {
                    return(0);
                }
                if (input == "-")
                {
                    throw new NumberException();
                }
                else if (input[0] == '-')
                {
                    return(-XLMath.RomanToArabic(input.Substring(1)));
                }
                else
                {
                    return(XLMath.RomanToArabic(input));
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                throw new CellValueException();
            }
            catch
            {
                throw;
            }
        }
Esempio n. 4
0
        private static object Roman(List <Expression> p)
        {
            if (p.Count == 1 ||
                (Boolean.TryParse(p[1]._token.Value.ToString(), out bool boolTemp) && boolTemp) ||
                (Int32.TryParse(p[1]._token.Value.ToString(), out int intTemp) && intTemp == 1))
            {
                return(XLMath.ToRoman((int)p[0]));
            }

            throw new ArgumentException("Can only support classic roman types.");
        }
Esempio n. 5
0
        private static object Atanh(List <Expression> p)
        {
            double input = p[0];

            if (Math.Abs(input) >= 1)
            {
                throw new NumberException();
            }

            return(XLMath.ATanh(p[0]));
        }
Esempio n. 6
0
        private static object Acosh(List <Expression> p)
        {
            double number = p[0];

            if (number < 1)
            {
                throw new NumberException();
            }

            return(XLMath.ACosh(p[0]));
        }
Esempio n. 7
0
        private static object Base(List <Expression> p)
        {
            long number;
            int  radix;
            int  minLength = 0;

            var rawNumber = p[0].Evaluate();

            if (rawNumber is long || rawNumber is int || rawNumber is byte || rawNumber is double || rawNumber is float)
            {
                number = Convert.ToInt64(rawNumber);
            }
            else
            {
                throw new CellValueException();
            }

            var rawRadix = p[1].Evaluate();

            if (rawRadix is long || rawRadix is int || rawRadix is byte || rawRadix is double || rawRadix is float)
            {
                radix = Convert.ToInt32(rawRadix);
            }
            else
            {
                throw new CellValueException();
            }

            if (p.Count > 2)
            {
                var rawMinLength = p[2].Evaluate();
                if (rawMinLength is long || rawMinLength is int || rawMinLength is byte || rawMinLength is double || rawMinLength is float)
                {
                    minLength = Convert.ToInt32(rawMinLength);
                }
                else
                {
                    throw new CellValueException();
                }
            }

            if (number < 0 || radix < 2 || radix > 36)
            {
                throw new NumberException();
            }

            return(XLMath.ChangeBase(number, radix).PadLeft(minLength, '0'));
        }
Esempio n. 8
0
        private static object CombinA(List <Expression> p)
        {
            Int32 number = (int)p[0]; // casting truncates towards 0 as specified
            Int32 chosen = (int)p[1];

            if (number < 0 || number < chosen)
            {
                throw new NumberException();
            }
            if (chosen < 0)
            {
                throw new NumberException();
            }

            int n = number + chosen - 1;
            int k = number - 1;

            return(n == k || k == 0
                ? 1
                : (long)XLMath.Combin(n, k));
        }
Esempio n. 9
0
        private static object Combin(List <Expression> p)
        {
            Int32 n;
            Int32 k;

            var rawN = p[0].Evaluate();
            var rawK = p[1].Evaluate();

            if (rawN is long || rawN is int || rawN is byte || rawN is double || rawN is float)
            {
                n = (int)Math.Floor((double)rawN);
            }
            else
            {
                throw new NumberException();
            }

            if (rawK is long || rawK is int || rawK is byte || rawK is double || rawK is float)
            {
                k = (int)Math.Floor((double)rawK);
            }
            else
            {
                throw new NumberException();
            }


            n = (int)p[0];
            k = (int)p[1];

            if (n < 0 || n < k || k < 0)
            {
                throw new NumberException();
            }

            return(XLMath.Combin(n, k));
        }
Esempio n. 10
0
 private static object Atanh(List <Expression> p)
 {
     return(XLMath.ATanh(p[0]));
 }
Esempio n. 11
0
 private static object Acosh(List <Expression> p)
 {
     return(XLMath.ACosh(p[0]));
 }
Esempio n. 12
0
 public void IsOdd()
 {
     Assert.IsTrue(XLMath.IsOdd(3));
     Assert.IsFalse(XLMath.IsOdd(2));
 }
Esempio n. 13
0
 public void IsEven()
 {
     Assert.IsTrue(XLMath.IsEven(2));
     Assert.IsFalse(XLMath.IsEven(3));
 }