Пример #1
0
        private static Func <int, byte, byte> MakeCalculationFunc(MathMode mode, bool wrapAround)
        {
            Func <int, byte>       wrapAroundFunc = MakeWrapAroundFunc(wrapAround);
            Func <int, byte, byte> calculationFunc;

            switch (mode)
            {
            case MathMode.Add:
                calculationFunc = (providedValue, inputByte) => wrapAroundFunc(inputByte + providedValue);
                break;

            case MathMode.Subtract:
                calculationFunc = (providedValue, inputByte) => wrapAroundFunc(inputByte - providedValue);
                break;

            case MathMode.Divide:
                calculationFunc = (providedValue, inputByte) =>
                {
                    if (providedValue == 0)
                    {
                        return(inputByte);
                    }
                    else
                    {
                        return(wrapAroundFunc(inputByte / providedValue));
                    }
                };
                break;

            case MathMode.Multiply:
                calculationFunc = (providedValue, inputByte) => wrapAroundFunc(inputByte * providedValue);
                break;

            default:
                throw new ArgumentException("Unknown math mode", nameof(mode));
            }

            return(calculationFunc);
        }
Пример #2
0
 /// <summary>
 /// Enables fast generation of fast math methods using the math mode provided.
 /// </summary>
 /// <param name="mathMode">The math mode to use.</param>
 /// <returns>The current builder instance.</returns>
 public Builder Math(MathMode mathMode)
 {
     MathMode = mathMode;
     return(this);
 }
Пример #3
0
 public string ConvertContent(string content)
 {
     content = new MathMode(content, "").WriteComponent();
     content = Regex.Replace(content, @"(?<!\n)\r", Environment.NewLine);
     return($"{content}");
 }
Пример #4
0
 internal CodeTableInfo(string word, string tex, MathMode mm)
 {
     Word     = word;
     TeX      = tex;
     MathMode = mm;
 }