├── Math expression eval ├── org.matheval │ ├── matheval.pfx │ ├── matheval.org.pfx │ ├── Parser │ │ └── Node │ │ │ ├── NullNode.cs │ │ │ ├── StringNode.cs │ │ │ ├── BoolNode.cs │ │ │ ├── VariableNode.cs │ │ │ ├── Node.cs │ │ │ ├── NumberNode.cs │ │ │ ├── UnaryNode.cs │ │ │ ├── BinanyNode.cs │ │ │ ├── CallFuncNode.cs │ │ │ ├── IfElseNode.cs │ │ │ └── SwitchCaseNode.cs │ ├── org.matheval.csproj │ ├── Functions │ │ ├── IFunction.cs │ │ ├── Impl │ │ │ ├── piFunction.cs │ │ │ ├── todayFunction.cs │ │ │ ├── bitnotFunction.cs │ │ │ ├── intFunction.cs │ │ │ ├── degreesFunction.cs │ │ │ ├── notFunction.cs │ │ │ ├── lenFunction.cs │ │ │ ├── randFunction.cs │ │ │ ├── charFunction.cs │ │ │ ├── codeFunction.cs │ │ │ ├── absFunction.cs │ │ │ ├── bitOrFunction.cs │ │ │ ├── isblankFunction.cs │ │ │ ├── bitandFunction.cs │ │ │ ├── bitxorFunction.cs │ │ │ ├── bitlshiftFunction.cs │ │ │ ├── bitrshiftFunction.cs │ │ │ ├── isnumberFunction.cs │ │ │ ├── concatFunction.cs │ │ │ ├── radiansFunction.cs │ │ │ ├── cotFunction.cs │ │ │ ├── secFunction.cs │ │ │ ├── sinFunction.cs │ │ │ ├── cothFunction.cs │ │ │ ├── cscFunction.cs │ │ │ ├── sinhFunction.cs │ │ │ ├── acotFunction.cs │ │ │ ├── lnFunction.cs │ │ │ ├── lowerFunction.cs │ │ │ ├── sqrtFunction.cs │ │ │ ├── log10Function.cs │ │ │ ├── upperFunction.cs │ │ │ ├── expFunction.cs │ │ │ ├── substituteFunction.cs │ │ │ ├── tanFunction.cs │ │ │ ├── coshFunction.cs │ │ │ ├── reptFunction.cs │ │ │ ├── tanhFunction.cs │ │ │ ├── trimFunction.cs │ │ │ ├── atanFunction.cs │ │ │ ├── factFunction.cs │ │ │ ├── cosFunction.cs │ │ │ ├── acosFunction.cs │ │ │ ├── powerFunction.cs │ │ │ ├── asinFunction.cs │ │ │ ├── orFunction.cs │ │ │ ├── reverseFunction.cs │ │ │ ├── andFunction.cs │ │ │ ├── roundFunction.cs │ │ │ ├── atan2Function.cs │ │ │ ├── boolFunction.cs │ │ │ ├── leftFunction.cs │ │ │ ├── modFunction.cs │ │ │ ├── ceilingFunction.cs │ │ │ ├── floorFunction.cs │ │ │ ├── rightFunction.cs │ │ │ ├── xorFunction.cs │ │ │ ├── midFunction.cs │ │ │ ├── rpadFunction.cs │ │ │ ├── lpadFunction.cs │ │ │ ├── valueFunction.cs │ │ │ └── replaceFunction.cs │ │ └── FunctionDef.cs │ └── Operators │ │ ├── IOperator.cs │ │ ├── Unary │ │ ├── UnaryNegOperator.cs │ │ ├── UnaryPosOperator.cs │ │ └── AbstractUnaryOperator.cs │ │ ├── Binop │ │ ├── ConcatOperator.cs │ │ ├── AndOperator.cs │ │ ├── OrOperator.cs │ │ └── MulOperator.cs │ │ └── BaseOperator.cs ├── UnitTest │ └── UnitTest.csproj └── Math expression eval.sln ├── CONTRIBUTING.md ├── .gitignore └── LICENSE /Math expression eval/org.matheval/matheval.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matheval/expression-evaluator-c-sharp/HEAD/Math expression eval/org.matheval/matheval.pfx -------------------------------------------------------------------------------- /Math expression eval/org.matheval/matheval.org.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matheval/expression-evaluator-c-sharp/HEAD/Math expression eval/org.matheval/matheval.org.pfx -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution highly appreciated! 2 | 3 | ### You can contributing to the repo by any of the following ways 4 | - Buy pro version that fully support datetime 5 | - Giving a star to the repo :-) 6 | - Finding and reporting bugs 7 | - Asking for new nice features 8 | - Implementing new features -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | bin/ 3 | obj/ 4 | Debug/ 5 | release/ 6 | scripts/ 7 | artifacts/ 8 | .dotnet 9 | TestResults/ 10 | .vs/ 11 | *.suo 12 | *.user 13 | *.exe 14 | *.dll 15 | *.pdb 16 | *.nupkg 17 | bin 18 | Bin 19 | obj 20 | _ReSharper* 21 | *.csproj.user 22 | *.resharper.user 23 | *.suo 24 | *.cache 25 | TestResult.xml 26 | AppPackages/ 27 | *.bak 28 | packages 29 | *.orig 30 | *.DotSettings 31 | *.ide/ 32 | .nuget 33 | project.lock.json 34 | .vs 35 | /Math expression eval/UnitTest/UnitTest.csproj.user 36 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/NullNode.cs: -------------------------------------------------------------------------------- 1 | namespace org.matheval.Node 2 | { 3 | /// 4 | /// Nullnode, used to hold null value 5 | /// 6 | public class NullNode : Implements.Node 7 | { 8 | /// 9 | /// Initializes a new instance 10 | /// 11 | /// numberVal 12 | // public NullNode() : base(typeof(int)) 13 | public NullNode() : base(typeof(object)) 14 | { 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Math expression eval/UnitTest/UnitTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1; 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/StringNode.cs: -------------------------------------------------------------------------------- 1 | namespace org.matheval.Node 2 | { 3 | /// 4 | /// Stringnode, used to hold string value 5 | /// 6 | public class StringNode : Implements.Node 7 | { 8 | /// 9 | /// Value 10 | /// 11 | public string Value; 12 | 13 | /// 14 | /// Initializes a new instance structure to a specified type string value 15 | /// 16 | /// value 17 | public StringNode(string value) : base(typeof(string)) 18 | { 19 | this.Value = value; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/BoolNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace org.matheval.Node 4 | { 5 | /// 6 | /// Boolnode, used to hold boolean value 7 | /// 8 | public class BoolNode : Implements.Node 9 | { 10 | /// 11 | /// Value 12 | /// 13 | public Boolean Value; 14 | 15 | /// 16 | /// Initializes a new instance structure to a specified type Boolean value 17 | /// 18 | /// value 19 | public BoolNode(Boolean value) : base(typeof(Boolean)) 20 | { 21 | this.Value = value; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/VariableNode.cs: -------------------------------------------------------------------------------- 1 | namespace org.matheval.Node 2 | { 3 | /// 4 | /// Variablenode, used to hold variable 5 | /// 6 | public class VariableNode : Implements.Node 7 | { 8 | /// 9 | /// Name 10 | /// 11 | public string Name; 12 | 13 | /// 14 | /// Initializes a new instance structure to a specified type string value 15 | /// 16 | /// name 17 | //public VariableNode(string name) : base(typeof(VariableNode)) 18 | public VariableNode(string name) : base(typeof(object)) 19 | { 20 | this.Name = name; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/Node.cs: -------------------------------------------------------------------------------- 1 | namespace org.matheval.Implements 2 | { 3 | /// 4 | /// Create abstract Node 5 | /// 6 | public abstract class Node 7 | { 8 | /// 9 | /// Return Type 10 | /// 11 | public System.Type ReturnType; 12 | 13 | /// 14 | /// Initializes a new instance 15 | /// 16 | public Node() 17 | { 18 | ReturnType = null; 19 | } 20 | 21 | /// 22 | /// Initializes a new instance structure to a specified System.Type returnType 23 | /// 24 | /// returnType 25 | public Node(System.Type returnType) 26 | { 27 | this.ReturnType = returnType; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/NumberNode.cs: -------------------------------------------------------------------------------- 1 | namespace org.matheval.Node 2 | { 3 | /// 4 | /// Doublenode, used to hold number value 5 | /// 6 | public class NumberNode : Implements.Node 7 | { 8 | /// 9 | /// Number Value 10 | /// 11 | public decimal NumberValue; 12 | 13 | /// 14 | /// Need to be rounded 15 | /// 16 | public bool mustRoundFlag; 17 | 18 | /// 19 | /// Initializes a new instance structure to a specified type decimal value 20 | /// 21 | /// numberVal 22 | /// mustRoundFlag 23 | public NumberNode(decimal numberVal, bool mustRoundFlag) : base(typeof(decimal)) 24 | { 25 | this.NumberValue = numberVal; 26 | this.mustRoundFlag = mustRoundFlag; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/UnaryNode.cs: -------------------------------------------------------------------------------- 1 | using org.matheval.Operators; 2 | 3 | namespace org.matheval.Node 4 | { 5 | /// 6 | /// Create class UnaryNode implements node 7 | /// Unary node, used to hold unary operator 8 | /// 9 | public class UnaryNode : Implements.Node 10 | { 11 | /// 12 | /// Expr 13 | /// 14 | public Implements.Node Expr; 15 | 16 | /// 17 | /// Iop 18 | /// 19 | public IOperator Iop; 20 | 21 | /// 22 | /// Initializes a new instance structure to a specified type IOperator iop and type Node expr 23 | /// 24 | /// iop 25 | /// expr 26 | public UnaryNode(IOperator iop, Implements.Node expr) : base(typeof(decimal)) 27 | { 28 | this.Iop = iop; 29 | this.Expr = expr; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 https://matheval.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/BinanyNode.cs: -------------------------------------------------------------------------------- 1 | using org.matheval.Operators; 2 | using System; 3 | 4 | namespace org.matheval.Node 5 | { 6 | /// 7 | /// Create class BinanyNode implements node 8 | /// 9 | public class BinanyNode : Implements.Node 10 | { 11 | /// 12 | /// Node Left 13 | /// 14 | public Implements.Node LHS; 15 | 16 | /// 17 | /// Node Right 18 | /// 19 | public Implements.Node RHS; 20 | 21 | /// 22 | /// iOp 23 | /// 24 | public IOperator iOp; 25 | 26 | /// 27 | /// Initializes a new instance structure to a specified 28 | /// 1. IOperator value 29 | /// 2. Node left 30 | /// 3. Node right 31 | /// 4. Return type 32 | /// 33 | /// iop 34 | /// lhs 35 | /// rhs 36 | /// returnType 37 | public BinanyNode(IOperator iop, Implements.Node lhs, Implements.Node rhs, Type returnType) : base(returnType) 38 | { 39 | this.iOp = iop; 40 | this.LHS = lhs; 41 | this.RHS = rhs; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/CallFuncNode.cs: -------------------------------------------------------------------------------- 1 | using org.matheval.Functions; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace org.matheval.Node 6 | { 7 | /// 8 | /// Create class CallFuncNode implements node 9 | /// Call function node, used to call function 10 | /// 11 | public class CallFuncNode : Implements.Node 12 | { 13 | /// 14 | /// Function Name 15 | /// 16 | public string FuncName; 17 | 18 | /// 19 | /// Excuter 20 | /// 21 | public IFunction Excuter; 22 | 23 | /// 24 | /// List node args 25 | /// 26 | public List args; 27 | 28 | /// 29 | /// Initializes a new instance structure to a specified 30 | /// 1. Function Name 31 | /// 2. List Value args 32 | /// 3. Return type 33 | /// 34 | /// funcName 35 | /// args 36 | /// returnType 37 | public CallFuncNode(string funcName, List args,Type returnType, IFunction excuter) : base(returnType) 38 | { 39 | this.FuncName = funcName; 40 | this.args = args; 41 | this.Excuter = excuter; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/IfElseNode.cs: -------------------------------------------------------------------------------- 1 | namespace org.matheval.Node 2 | { 3 | /// 4 | /// Create class IfElseNode implements node 5 | /// Condition node, used to hold condition 6 | /// 7 | public class IfElseNode : Implements.Node 8 | { 9 | /// 10 | /// Node Condition 11 | /// 12 | public Implements.Node Condition; 13 | 14 | /// 15 | /// Node have value is true 16 | /// 17 | public Implements.Node IfTrue; 18 | 19 | /// 20 | /// Node have value is false 21 | /// 22 | public Implements.Node IfFalse; 23 | 24 | /// 25 | /// Initializes a new instance structure to a specified 26 | /// 1. Node Condition 27 | /// 2. Node have value is true 28 | /// 3. Node have value is false 29 | /// 4. Type return 30 | /// 31 | /// condition 32 | /// ifTrue 33 | /// ifFalse 34 | /// returnType 35 | public IfElseNode(Implements.Node condition, Implements.Node ifTrue, Implements.Node ifFalse, System.Type returnType) : base(returnType) 36 | { 37 | this.Condition = condition; 38 | this.IfTrue = ifTrue; 39 | this.IfFalse = ifFalse; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Parser/Node/SwitchCaseNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace org.matheval.Node 5 | { 6 | /// 7 | /// Create class SwitchCaseNode implements node 8 | /// Condition node, used to hold CASE condition 9 | /// 10 | public class SwitchCaseNode : Implements.Node 11 | { 12 | /// 13 | /// Node condition 14 | /// 15 | public Implements.Node conditionExpr; 16 | 17 | /// 18 | /// List node result 19 | /// 20 | public List varResultExprs; 21 | 22 | /// 23 | /// Node default 24 | /// 25 | public Implements.Node defaultExpr; 26 | 27 | /// 28 | /// Initializes a new instance structure to a specified 29 | /// 1. Node condition 30 | /// 2. List node result 31 | /// 3. Node default 32 | /// 4. Return type 33 | /// 34 | /// conditionExpr 35 | /// varResultExprs 36 | /// defaultExpr 37 | /// returnType 38 | public SwitchCaseNode(Implements.Node conditionExpr, List varResultExprs, Implements.Node defaultExpr, Type returnType) : base(returnType) 39 | { 40 | this.conditionExpr = conditionExpr; 41 | this.varResultExprs = varResultExprs; 42 | this.defaultExpr = defaultExpr; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/org.matheval.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1;netcoreapp3.1;net35;net40;net45;net46;net461;net462;net47;net471;net472;net48;netstandard2.0 5 | Library 6 | Matheval 7 | org.matheval 8 | Math expression eval 9 | 10 | Matheval is a mathematical expressions evaluator library for .NET. Allows to evaluate mathematical, boolean, string and datetime expressions on the fly. Official document and usage examples: https://matheval.org/math-expression-eval-for-c-sharp/ 11 | Copyright © MathEval.org 2021 12 | org.matheval 13 | org.matheval 14 | matheval.org 15 | 16 | https://matheval.org/ 17 | Math Mathematics Mathematical Expression Fomular Eval Evaluator Calculator Solve Unary Decimal 18 | 19 | https://github.com/matheval/expression-evaluator-c-sharp/ 20 | MIT 21 | false 22 | 1.0.0.2 23 | 1.0.0.2 24 | 1.0.0.2 25 | false 26 | git 27 | 28 | 29 | -------------------------------------------------------------------------------- /Math expression eval/Math expression eval.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "org.matheval", "org.matheval\org.matheval.csproj", "{85774930-C0E9-432C-A23F-015FB26F3897}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "UnitTest\UnitTest.csproj", "{3FFECB40-1C8E-4362-9476-BEBB4EE329BD}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {85774930-C0E9-432C-A23F-015FB26F3897}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {85774930-C0E9-432C-A23F-015FB26F3897}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {85774930-C0E9-432C-A23F-015FB26F3897}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {85774930-C0E9-432C-A23F-015FB26F3897}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {3FFECB40-1C8E-4362-9476-BEBB4EE329BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {3FFECB40-1C8E-4362-9476-BEBB4EE329BD}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {3FFECB40-1C8E-4362-9476-BEBB4EE329BD}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {3FFECB40-1C8E-4362-9476-BEBB4EE329BD}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {86D79D03-F1AE-4376-91E8-F69D9E1AA826} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/IFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using System; 25 | using System.Collections.Generic; 26 | 27 | namespace org.matheval.Functions 28 | { 29 | /// 30 | /// Function executer interface 31 | /// 32 | public interface IFunction 33 | { 34 | /// 35 | /// Get function define info, used to validate function in expression 36 | /// 37 | /// List value Function 38 | List GetInfo(); 39 | 40 | /// 41 | /// Execute 42 | /// 43 | /// args 44 | /// dc 45 | /// Value 46 | object Execute(Dictionary args, ExpressionContext dc); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/piFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// PI() -> ~3.141593 32 | /// 33 | public class piFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Pi, null, typeof(decimal), 0) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | return Convert.ToDecimal(Math.PI, dc.WorkingCulture); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/todayFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace org.matheval.Functions 30 | { 31 | /// 32 | /// Returns the current date in the current user's time zone. 33 | /// TODAY() 34 | /// 35 | public class todayFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List{new FunctionDef(Afe_Common.Const_TODAY, null, typeof(DateTime), 0)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// TODAY 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | return DateTime.Today; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/bitnotFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// BITNOT(6) 32 | /// 33 | public class bitnotFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Bitnot, new System.Type[] { typeof(decimal) }, typeof(Boolean), 1) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | return ~int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), dc.WorkingCulture); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/intFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// INT(123.4) -> 123 32 | /// 33 | public class intFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List{ 42 | new FunctionDef(Afe_Common.Const_Int, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | return Convert.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture)); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/degreesFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// DEGREES(PI()) -> 180 32 | /// 33 | public class degreesFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Degrees, new System.Type[] { typeof(decimal) }, typeof(decimal), 1) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | return Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture) * (decimal)(180 / Math.PI); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/notFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Logical not function 32 | /// NOT(true) -> false 33 | /// 34 | public class notFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List { new FunctionDef(Afe_Common.Const_Not, new System.Type[] { typeof(Boolean) }, typeof(Boolean), 1) }; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | return !Boolean.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture)); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/lenFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Gets the number of characters in the current String object. 32 | /// len("abc") => 3 33 | /// 34 | public class lenFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List { new FunctionDef(Afe_Common.Const_Len, new System.Type[] { typeof(string) }, typeof(decimal), 1) }; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | return Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture).Length; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/randFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// RAND() 32 | /// 33 | public class randFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List{ 42 | new FunctionDef(Afe_Common.Const_Random, null, typeof(decimal), 0)}; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | // Random r = new Random(); 54 | //return Afe_Common.Round(r.Next(), dc); 55 | return Convert.ToDecimal(new Random().NextDouble(), dc.WorkingCulture); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/charFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Return character from ascii code 32 | /// CHAR(97) -> a 33 | /// 34 | public class charFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef("char", new System.Type[]{ typeof(decimal) }, typeof(string), 1)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | return Convert.ToChar(Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/codeFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns a ascii code for a character 32 | /// CODE("a") -> 97 33 | /// 34 | public class codeFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef(Afe_Common.Const_Code, new System.Type[]{ typeof(string) }, typeof(decimal), 1)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | return (decimal)Convert.ToChar(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture)); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Operators/IOperator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using System; 25 | using static org.matheval.Common.Afe_Common; 26 | 27 | namespace org.matheval.Operators 28 | { 29 | /// 30 | /// Create interface IOperator 31 | /// 32 | public interface IOperator 33 | { 34 | /// 35 | /// Get Prec 36 | /// 37 | /// Value is type int 38 | int GetPrec(); 39 | 40 | /// 41 | /// Get Op 42 | /// 43 | /// Value is type string 44 | string GetOp(); 45 | 46 | /// 47 | /// Get Ass 48 | /// 49 | /// Value is type enum Assoc 50 | Assoc GetAss(); 51 | 52 | /// 53 | /// Calculate 54 | /// 55 | /// Value is type Object result Calculate 56 | object Calculate(object left, object right, ExpressionContext dc); 57 | 58 | /// 59 | /// Validate 60 | /// 61 | /// Value is System.Type 62 | Type Validate(Type typeLeft, Type typeRight); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/absFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns the absolute value of a specified number. 32 | /// Examples: 33 | /// abs(-1) -> 1 34 | /// abs(1) -> 1 35 | /// 36 | public class absFunction : IFunction 37 | { 38 | /// 39 | /// Get Information 40 | /// 41 | /// FunctionDefs 42 | public List GetInfo() 43 | { 44 | return new List{ 45 | new FunctionDef(Afe_Common.Const_Abs, new Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 46 | } 47 | 48 | /// 49 | /// Execute 50 | /// 51 | /// args 52 | /// dc 53 | /// Value 54 | public object Execute(Dictionary args, ExpressionContext dc) 55 | { 56 | return Afe_Common.Round(Math.Abs(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture)), dc); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/bitOrFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// BITOR(23,10) -> 31 32 | /// 33 | public class bitorFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Bitor, new System.Type[] { typeof(decimal), typeof(decimal) }, typeof(Boolean), 2) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | return int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), dc.WorkingCulture) | int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_Two], dc.WorkingCulture), dc.WorkingCulture); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/isblankFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns TRUE when a given string is null or empty, otherwise return FALSE 32 | /// ISBLANK("") -> TRUE 33 | /// 34 | public class isblankFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef(Afe_Common.Const_Isblank, new System.Type[]{ typeof(Object) }, typeof(Boolean), 1)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// True or False 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | return string.IsNullOrEmpty(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture)); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/bitandFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// BITAND(13,25) -> 9 32 | /// 33 | public class bitandFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Bitand, new System.Type[] { typeof(decimal), typeof(decimal) }, typeof(Boolean), 2) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | return int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), dc.WorkingCulture) & int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_Two], dc.WorkingCulture), dc.WorkingCulture); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/bitxorFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// BITXOR(5,3) -> 6 32 | /// 33 | public class bitxorFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Bitxor, new System.Type[] { typeof(decimal), typeof(decimal) }, typeof(Boolean), 2) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | return int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), dc.WorkingCulture) ^ int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_Two], dc.WorkingCulture), dc.WorkingCulture); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/FunctionDef.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | namespace org.matheval.Functions 25 | { 26 | public class FunctionDef 27 | { 28 | /// 29 | /// Function name 30 | /// 31 | public string Name; 32 | 33 | /// 34 | /// Param type holder 35 | /// 36 | public System.Type[] Args; 37 | 38 | /// 39 | /// Return type holder 40 | /// 41 | public System.Type ReturnType; 42 | 43 | /// 44 | /// Param count 45 | /// 46 | public int ParamCount; 47 | 48 | /// 49 | /// Function def constructor 50 | /// 51 | /// Function name 52 | /// Param type 53 | /// return datatype 54 | /// param count 55 | public FunctionDef(string name, System.Type[] args, System.Type returnType, int paramCount) 56 | { 57 | Name = name.ToLowerInvariant(); 58 | Args = args; 59 | ReturnType = returnType; 60 | ParamCount = paramCount; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/bitlshiftFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// BITLSHIFT(4,2) -> 16 32 | /// 33 | public class bitlshiftFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Bitlshift, new System.Type[] { typeof(decimal), typeof(decimal) }, typeof(Boolean), 2) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | return int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), dc.WorkingCulture) << int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_Two], dc.WorkingCulture), dc.WorkingCulture); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/bitrshiftFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// BITRSHIFT(13,2) -> 3 32 | /// 33 | public class bitrshiftFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Bitrshift, new System.Type[] { typeof(decimal), typeof(decimal) }, typeof(Boolean), 2) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | return int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), dc.WorkingCulture) >> int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_Two], dc.WorkingCulture), dc.WorkingCulture); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/isnumberFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Text.RegularExpressions; 28 | 29 | namespace org.matheval.Functions 30 | { 31 | /// 32 | /// Check if a value is a number. 33 | /// ISNUMBER("0.23") -> true 34 | /// ISNUMBER("abc") -> false 35 | /// 36 | public class isnumberFunction : IFunction 37 | { 38 | /// 39 | /// Get Information 40 | /// 41 | /// FunctionDefs 42 | public List GetInfo() 43 | { 44 | return new List { new FunctionDef(Afe_Common.Const_Isnumber, new System.Type[] { typeof(object) }, typeof(Boolean), 1) }; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | Regex rg = new Regex("^-?\\d*(\\.\\d+)+$"); 56 | return rg.IsMatch(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture)); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/concatFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Combines the text from multiple strings 32 | /// CONCAT("A","B","C") -> ABC 33 | /// 34 | public class concatFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List { new FunctionDef(Afe_Common.Const_Concat, new System.Type[] { typeof(Object) }, typeof(string), -1) }; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | string value = string.Empty; 54 | 55 | foreach (Object item in args.Values) 56 | { 57 | value += Afe_Common.ToString(item, dc.WorkingCulture); 58 | } 59 | return value; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/radiansFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// RADIANS(180.5) -> ~3.150319 32 | /// 33 | public class radiansFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Radians, new System.Type[] { typeof(decimal) }, typeof(decimal), 1) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | //double v180 = double.Parse("180"); 53 | //return Afe_Common.Round(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]) * (decimal)(Math.PI / v180), dc); 54 | return Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture) * (decimal)(Math.PI / 180d); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/cotFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// COT(PI()/6) -> 1.73205 32 | /// 33 | public class cotFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Cot, new System.Type[] { typeof(decimal) }, typeof(decimal), 1) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | //return Afe_Common.Round(1 / Math.Tan(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 53 | Double result = 1d / Math.Tan(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 54 | return Convert.ToDecimal(result, dc.WorkingCulture); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/secFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// SEC(PI()/6) -> ~ 1.1547 32 | /// 33 | public class secFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Sec, new System.Type[] { typeof(decimal) }, typeof(decimal), 1) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | //return Afe_Common.Round(1 / Math.Cos(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 53 | double result = 1d / Math.Cos(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 54 | return Convert.ToDecimal(result, dc.WorkingCulture); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/sinFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// SIN(PI()/2) -> 1 32 | /// 33 | public class sinFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List{ 42 | new FunctionDef(Afe_Common.Const_Sin, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | //return Afe_Common.Round(Math.Sin(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 54 | double result = Math.Sin(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 55 | return Convert.ToDecimal(result, dc.WorkingCulture); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/cothFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// COTH(PI()/6) -> ~2.081283 32 | /// 33 | public class cothFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List { new FunctionDef(Afe_Common.Const_Coth, new System.Type[] { typeof(decimal) }, typeof(decimal), 1) }; 42 | } 43 | 44 | /// 45 | /// Execute 46 | /// 47 | /// args 48 | /// dc 49 | /// Value 50 | public Object Execute(Dictionary args, ExpressionContext dc) 51 | { 52 | //return Afe_Common.Round(1 / Math.Tanh(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 53 | Double result = 1d / Math.Tanh(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 54 | return Convert.ToDecimal(result, dc.WorkingCulture); 55 | 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/cscFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// CSC(PI()/6) -> ~2 32 | /// 33 | public class cscFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List{ 42 | new FunctionDef(Afe_Common.Const_Csc, new System.Type[]{typeof(decimal)}, typeof(decimal), 1)}; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | // return Afe_Common.Round(1 / Math.Sin(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 54 | Double result = 1d / Math.Sin(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 55 | return Convert.ToDecimal(result, dc.WorkingCulture); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/sinhFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// SINH(PI()/2) -> ~2.301298 32 | /// 33 | public class sinhFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List{ 42 | new FunctionDef(Afe_Common.Const_Sinh, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | //return Afe_Common.Round(Math.Sinh(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 54 | double result = Math.Sinh(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 55 | return Convert.ToDecimal(result, dc.WorkingCulture); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/acotFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// ACOT(PI()/6) -> ~1.088448 32 | /// 33 | public class acotFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List{ 42 | new FunctionDef(Afe_Common.Const_Acot, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | Double result = Math.Atan(1d / Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 54 | return Convert.ToDecimal(result, dc.WorkingCulture); 55 | //return Afe_Common.Round(Math.Atan(1 / Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/lnFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// LN(10) -> ~2.302585 32 | /// LN(e) -> 1 33 | /// 34 | public class lnFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef(Afe_Common.Const_Ln, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | //return Afe_Common.Round(Math.Log(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 55 | Double result = Math.Log(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 56 | return Convert.ToDecimal(result, dc.WorkingCulture); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/lowerFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Converts all letters in the specified string to lowercase 32 | /// LOWER("aBc") -> abc 33 | /// 34 | public class lowerFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List { new FunctionDef(Afe_Common.Const_Lower, new System.Type[] { typeof(string) }, typeof(string), 1) }; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | if (!string.IsNullOrEmpty(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture))) 54 | { 55 | return Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture).ToLower(dc.WorkingCulture); 56 | } 57 | return string.Empty; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/sqrtFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// SQRT(16) -> 4 32 | /// SQRT(16.32) -> ~ 4.039802 33 | /// 34 | public class sqrtFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef(Afe_Common.Const_Sqrt, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | // return Afe_Common.Round(Math.Sqrt(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 55 | double result = Math.Sqrt(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 56 | return Convert.ToDecimal(result, dc.WorkingCulture); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/log10Function.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// LOG10(10^5) -> 5 32 | /// LOG10(86) -> ~ 1.934498 33 | /// 34 | public class log10Function : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef(Afe_Common.Const_Log10, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | //return Afe_Common.Round(Math.Log10(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 55 | Double result = Math.Log10(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 56 | return Convert.ToDecimal(result, dc.WorkingCulture); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/upperFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace org.matheval.Functions 30 | { 31 | /// 32 | /// Converts all letters in the specified string to uppercase 33 | /// upper("aBc") -> ABC 34 | /// 35 | public class upperFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List { new FunctionDef(Afe_Common.Const_Upper, new System.Type[] { typeof(string) }, typeof(string), 1) }; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | if (!string.IsNullOrEmpty(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture))) 55 | { 56 | return Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture).ToUpper(dc.WorkingCulture); 57 | } 58 | return string.Empty; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Operators/Unary/UnaryNegOperator.cs: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | The MIT License 4 | 5 | Copyright (c) 2021 MathEval.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | using org.matheval.Common; 26 | using System; 27 | 28 | namespace org.matheval.Operators.Unary 29 | { 30 | /// 31 | /// Unary negative operator 32 | /// 3+-2--4 -> 5 33 | /// 34 | public class UnaryNegOperator : AbstractUnaryOperator 35 | { 36 | /// 37 | /// Initializes a new instance structure to a specified type string value and type int value 38 | /// 39 | /// op 40 | /// precedence 41 | public UnaryNegOperator(string op, int precedence) : base(op, precedence) 42 | { 43 | } 44 | 45 | /// 46 | /// Calculate 47 | /// 48 | /// left 49 | /// right 50 | /// dc 51 | /// Calculate value 52 | public override object Calculate(object left, object right, ExpressionContext dc) 53 | { 54 | base.Calculate(left, right, dc); 55 | if (left is decimal) 56 | { 57 | decimal retValue = -(decimal)left; 58 | return retValue; 59 | } 60 | throw new Exception(Afe_Common.MSG_UNARY_INVALID); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/expFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns e raised to the specified power. 32 | /// EXP(3) -> ~20.085537 33 | /// 34 | public class expFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef(Afe_Common.Const_Exp, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | //return Afe_Common.Round(Math.Exp(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 55 | Double result = Math.Exp(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 56 | return Convert.ToDecimal(result, dc.WorkingCulture); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/substituteFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Replaces text in a given string by matching 32 | /// SUBSTITUTE("123-455-3321","-","") -> 1234553321 33 | /// 34 | public class substituteFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef(Afe_Common.Const_Substitute, new System.Type[]{ typeof(string), typeof(string), typeof(string)}, typeof(string), 3) }; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value Replace 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | return Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture).Replace(Afe_Common.ToString(args[Afe_Common.Const_Key_Two], dc.WorkingCulture), Afe_Common.ToString(args[Afe_Common.Const_Key_Three], dc.WorkingCulture)); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Operators/Unary/UnaryPosOperator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | 27 | namespace org.matheval.Operators.Unary 28 | { 29 | /// 30 | /// Unary positive operator 31 | /// Examples: 32 | /// 3++2-+4 -> 1 33 | /// 34 | public class UnaryPosOperator : AbstractUnaryOperator 35 | { 36 | /// 37 | /// Initializes a new instance structure to a specified type string value and type int value 38 | /// 39 | /// op 40 | /// precedence 41 | public UnaryPosOperator(string op, int precedence) : base(op, precedence) 42 | { 43 | } 44 | 45 | /// 46 | /// Calculate 47 | /// 48 | /// left 49 | /// right 50 | /// dc 51 | /// Calculate value 52 | public override object Calculate(object left, object right, ExpressionContext dc) 53 | { 54 | base.Calculate(left, right, dc); 55 | if (left is decimal) 56 | { 57 | decimal retValue = +(decimal)left; 58 | return retValue; 59 | } 60 | throw new Exception(Afe_Common.MSG_UNARY_INVALID); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/tanFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace org.matheval.Functions 30 | { 31 | /// 32 | /// Returns the tangent of the specified angle. 33 | /// tan(-123456789) -> -7.059154 34 | /// 35 | public class tanFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List{ 44 | new FunctionDef(Afe_Common.Const_Tan, new System.Type[]{typeof(decimal)}, typeof(decimal), 1)}; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | //return Afe_Common.Round(Math.Tan(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 56 | double result = Math.Tan(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 57 | return Convert.ToDecimal(result, dc.WorkingCulture); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/coshFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns the hyperbolic cosine of the specified angle. 32 | /// cosh(60) -> 5.710037 33 | /// 34 | public class coshFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef(Afe_Common.Const_Cosh, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | //return Afe_Common.Round(Math.Cosh(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 55 | Double result = Math.Cosh(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 56 | return Convert.ToDecimal(result, dc.WorkingCulture); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/reptFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Repeats characters a given number of times 32 | /// REPT("x",5) -> xxxxx 33 | /// 34 | public class reptFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef("rept", new System.Type[]{ typeof(string), typeof(decimal) }, typeof(string), 2)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | string temp = string.Empty; 55 | for (int i = 1; i <= Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture)); i++) 56 | { 57 | temp += Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture); 58 | } 59 | return temp; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/tanhFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace org.matheval.Functions 30 | { 31 | /// 32 | /// Returns the hyperbolic tangent of the specified angle. 33 | /// tanh(-1.12356789) -> -0.808806 34 | /// 35 | public class tanhFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List{ 44 | new FunctionDef(Afe_Common.Const_Tanh, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | //return Afe_Common.Round(Math.Tanh(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 56 | double result = Math.Tanh(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 57 | return Convert.ToDecimal(result, dc.WorkingCulture); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/trimFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace org.matheval.Functions 30 | { 31 | /// 32 | /// Returns a new string in which all leading and trailing occurrences of a set of specified characters from the current string are removed. 33 | /// trim(" abc ") => abc 34 | /// 35 | public class trimFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List { new FunctionDef(Afe_Common.Const_Trim, new System.Type[] { typeof(string) }, typeof(string), 1) }; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | if (!string.IsNullOrEmpty(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture))) 55 | { 56 | return Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture).Trim(); 57 | } 58 | return string.Empty; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/atanFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// is an inbuilt Math class method which returns the angle whose tangent is given as a double value argument. 32 | /// If the argument is NaN, then the result will be NaN. 33 | /// 34 | public class atanFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef(Afe_Common.Const_atan, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | //return Afe_Common.Round(Math.Atan(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 55 | Double result = Math.Atan(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 56 | return Convert.ToDecimal(result, dc.WorkingCulture); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/factFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// FACT(8) -> 40320 32 | /// 33 | public class factFunction : IFunction 34 | { 35 | /// 36 | /// Get Information 37 | /// 38 | /// FunctionDefs 39 | public List GetInfo() 40 | { 41 | return new List{ 42 | new FunctionDef(Afe_Common.Const_Fact, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | return this.Fact(Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 54 | } 55 | 56 | /// 57 | /// Fact 58 | /// 59 | /// 60 | /// 61 | public long Fact(int n) 62 | { 63 | if (n < 0) 64 | { 65 | return 0; 66 | } 67 | return (n < 2) ? 1 : n * Fact(n - 1); 68 | } 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/cosFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns the cosine of the specified angle. 32 | /// It is the angle(measured in radian) whose cosine is to be returned and the type of this parameter is System.Double. 33 | /// COS(PI()) -> -1 34 | /// 35 | public class cosFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List{ 44 | new FunctionDef(Afe_Common.Const_Cos, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | //return Afe_Common.Round(Math.Cos(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One]))), dc); 56 | Double result = Math.Cos(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture))); 57 | return Convert.ToDecimal(result, dc.WorkingCulture); 58 | 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/acosFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// It is the number that represents cosine and type of this parameter is System.Double. 32 | /// It must be greater than or equal to -1, but less than or equal to 1. 33 | /// 34 | public class acosFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List{ 43 | new FunctionDef(Afe_Common.Const_Acos, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | double input = Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture)); 55 | if (input >= -1 && input <= 1) 56 | { 57 | //return Afe_Common.Round(Math.Acos(input), dc); 58 | return Convert.ToDecimal(Math.Acos(input), dc.WorkingCulture); 59 | } 60 | throw new Exception(Afe_Common.MSG_WRONG_OP_ACOS); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/powerFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// POWER(4,2.1) ~ 18.379174 32 | /// POWER(2,8) -> 256 33 | /// POWER(-2,2) -> 4 34 | /// 35 | public class powerFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List{ 44 | new FunctionDef(Afe_Common.Const_Power, new System.Type[]{ typeof(decimal), typeof(decimal) }, typeof(decimal), 2)}; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | //return Afe_Common.Round(Math.Pow(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One])), Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two]))), dc); 56 | Double result = Math.Pow(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture)), Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture))); 57 | return Convert.ToDecimal(result, dc.WorkingCulture); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/asinFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// It is the number that represents a sine and type of this parameter is System.Double 32 | /// It must be greater than or equal to -1, but less than or equal to 1. 33 | /// ASIN(0.5) -> ~0.523599 34 | /// 35 | public class asinFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List{ 44 | new FunctionDef(Afe_Common.Const_Asin, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1)}; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | double input = Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture)); 56 | if (input >= -1 && input <= 1) 57 | { 58 | //return Afe_Common.Round(Math.Asin(input), dc); 59 | return Convert.ToDecimal(Math.Asin(input), dc.WorkingCulture); 60 | } 61 | throw new Exception(Afe_Common.MSG_WRONG_OP_ACOS); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/orFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Logical or function 32 | /// OR(2>1,3>9/2) -> true 33 | /// IF(OR(2>1,3>9/2),1,2) -> 1 34 | /// 35 | public class orFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List { new FunctionDef(Afe_Common.Const_Or, new System.Type[] { typeof(Boolean) }, typeof(Boolean), -1) }; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | return this.LogicalOr(args); 55 | } 56 | 57 | /// 58 | /// LogicalOr 59 | /// 60 | /// args 61 | /// Value LogicalOr 62 | private Boolean LogicalOr(Dictionary args) 63 | { 64 | foreach (Object item in args.Values) 65 | { 66 | if ((item is Boolean) && (Boolean)item) 67 | { 68 | return true; 69 | } 70 | } 71 | return false; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/reverseFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Reverse a string 32 | /// REVERSE("abcd") -> dcba 33 | /// 34 | public class reverseFunction : IFunction 35 | { 36 | /// 37 | /// Get Information 38 | /// 39 | /// FunctionDefs 40 | public List GetInfo() 41 | { 42 | return new List { new FunctionDef(Afe_Common.Const_Reverse, new System.Type[] { typeof(string) }, typeof(string), 1) }; 43 | } 44 | 45 | /// 46 | /// Execute 47 | /// 48 | /// args 49 | /// dc 50 | /// Value 51 | public Object Execute(Dictionary args, ExpressionContext dc) 52 | { 53 | return this.Reverse(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture)); 54 | } 55 | 56 | /// 57 | /// Formula Reverse 58 | /// 59 | /// str 60 | /// Value Reverse 61 | private string Reverse(string str) 62 | { 63 | if (str.Length > 0) 64 | { 65 | return str[str.Length - 1] + Reverse(str.Substring(0, str.Length - 1)); 66 | } 67 | else 68 | { 69 | return str; 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/andFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace org.matheval.Functions 30 | { 31 | /// 32 | /// Logical and function 33 | /// AND(2>1,3<9/2) -> true 34 | /// IF(AND(2>1,3<9/2),1,2) -> 1 35 | /// 36 | public class andFunction : IFunction 37 | { 38 | /// 39 | /// Get Information 40 | /// 41 | /// FunctionDefs 42 | public List GetInfo() 43 | { 44 | return new List { new FunctionDef(Afe_Common.Const_And, new System.Type[] { typeof(Boolean) }, typeof(Boolean), -1) }; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | return this.LogicalAnd(args); 56 | } 57 | 58 | /// 59 | /// LogicalAnd 60 | /// 61 | /// args 62 | /// Value LogicalAnd 63 | private Boolean LogicalAnd(Dictionary args) 64 | { 65 | foreach (Object item in args.Values) 66 | { 67 | if (!(item is Boolean) || !(Boolean)item) 68 | { 69 | return false; 70 | } 71 | } 72 | return true; 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Operators/Binop/ConcatOperator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using System; 25 | using static org.matheval.Common.Afe_Common; 26 | 27 | namespace org.matheval.Operators.Binop 28 | { 29 | /// 30 | /// Create class Concat string Operator implements AbstractBinOperator 31 | /// Example: 32 | /// "abc"&"def" -> abcdef 33 | /// 34 | public class ConcatOperator : AbstractBinOperator 35 | { 36 | /// 37 | /// Initializes a new instance structure to a specified type string value and type int value and value assoc 38 | /// 39 | /// op 40 | /// precedence 41 | /// assoc 42 | public ConcatOperator(string op, int precedence, Assoc assoc) : base(op, precedence, assoc) 43 | { 44 | } 45 | 46 | /// 47 | /// Calculate result 48 | /// 49 | /// left 50 | /// right 51 | /// dc 52 | /// value Calculate 53 | public override object Calculate(object left, object right, ExpressionContext dc) 54 | { 55 | return left.ToString() + right.ToString(); 56 | } 57 | 58 | /// 59 | /// Validate 60 | /// 61 | /// typeLeft 62 | /// typeRight 63 | /// Type 64 | public override Type Validate(Type typeLeft, Type typeRight) 65 | { 66 | return typeof(string); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/roundFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Rounds a value to the nearest integer or to the specified number of fractional digits. 32 | /// ROUND(20.085537,2) -> 20.09 33 | /// ROUND(20.085537,4) -> 20.0855 34 | /// ROUND(20126.1234567890123456789,17) -> 20126.123457 35 | /// 36 | public class roundFunction : IFunction 37 | { 38 | /// 39 | /// Get Information 40 | /// 41 | /// FunctionDefs 42 | public List GetInfo() 43 | { 44 | return new List{ 45 | new FunctionDef(Afe_Common.Const_Round, new System.Type[]{ typeof(decimal), typeof(decimal) }, typeof(decimal), 2)}; 46 | } 47 | 48 | /// 49 | /// Execute 50 | /// 51 | /// args 52 | /// dc 53 | /// Value 54 | public Object Execute(Dictionary args, ExpressionContext dc) 55 | { 56 | int digits = Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture)) ;// int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_Two])); 57 | 58 | /*if (digits < 0 || digits > 28) 59 | { 60 | throw new Exception("Input digits must be between 0 and 28"); 61 | } */ 62 | return Math.Round(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture), digits, dc.Rd); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/atan2Function.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns the angle whose tangent is the quotient of two specified numbers. 32 | /// value1: y coordinate of the point of type System.Double. 33 | /// value2: x coordinate of the point of type System.Double. 34 | /// Example 35 | /// atan2(1.123456789, 2.123456789) -> 0.486632 36 | /// 37 | public class atan2Function : IFunction 38 | { 39 | /// 40 | /// Get Information 41 | /// 42 | /// FunctionDefs 43 | public List GetInfo() 44 | { 45 | return new List{ 46 | new FunctionDef(Afe_Common.Const_Atan2, new System.Type[]{ typeof(decimal), typeof(decimal) }, typeof(decimal), 2)}; 47 | } 48 | 49 | /// 50 | /// Execute 51 | /// 52 | /// args 53 | /// dc 54 | /// Value 55 | public Object Execute(Dictionary args, ExpressionContext dc) 56 | { 57 | //return Afe_Common.Round(Math.Atan2(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One])), Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two]))), dc); 58 | 59 | Double result = Math.Atan2(Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture)), Decimal.ToDouble(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture))); 60 | return Convert.ToDecimal(result, dc.WorkingCulture); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/boolFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | public class boolFunction : IFunction 31 | { 32 | /// 33 | /// Get Information 34 | /// 35 | /// FunctionDefs 36 | public List GetInfo() 37 | { 38 | return new List{ 39 | new FunctionDef(Afe_Common.Const_Bool, new System.Type[]{ typeof(string) }, typeof(Boolean), 1), 40 | new FunctionDef(Afe_Common.Const_Bool, new System.Type[] { typeof(decimal) }, typeof(Boolean), 1)}; 41 | } 42 | 43 | /// 44 | /// Execute 45 | /// 46 | /// args 47 | /// dc 48 | /// Value 49 | public Object Execute(Dictionary args, ExpressionContext dc) 50 | { 51 | return this.ToBool(args[Afe_Common.Const_Key_One]); 52 | } 53 | 54 | /// 55 | /// ToBool 56 | /// 57 | /// value 58 | /// Value ToBool 59 | private Boolean ToBool(Object value) 60 | { 61 | if (value is decimal) 62 | { 63 | return (decimal)value == 1; 64 | } 65 | else if (!(value.ToString().Equals(Afe_Common.Const_Key_One) || value.ToString().Equals(Afe_Common.Const_Key_Zero))) 66 | { 67 | throw new Exception(string.Format("{0} {1}", Afe_Common.ShowMessage, "BOOL(), expect 1 or 0")); 68 | } 69 | return value.ToString().Equals(Afe_Common.Const_Key_One); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/leftFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Extracts a given number of characters from 32 | /// the left side of a supplied text string 33 | /// Example: 34 | /// LEFT("abcd",3) -> abc 35 | /// 36 | public class leftFunction : IFunction 37 | { 38 | /// 39 | /// Get Information 40 | /// 41 | /// FunctionDefs 42 | public List GetInfo() 43 | { 44 | return new List { new FunctionDef(Afe_Common.Const_LEFT, new System.Type[] { typeof(string), typeof(decimal) }, typeof(string), 2) }; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | return this.Left(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture))); 56 | } 57 | 58 | /// 59 | /// Formula Left 60 | /// 61 | /// stringValue 62 | /// count 63 | /// Value Left 64 | private string Left(string stringValue, int count) 65 | { 66 | if (!string.IsNullOrEmpty(stringValue)) 67 | { 68 | return stringValue.Substring(0, count > stringValue.Length ? stringValue.Length : count); 69 | } 70 | return string.Empty; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Operators/BaseOperator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using System; 25 | using static org.matheval.Common.Afe_Common; 26 | 27 | namespace org.matheval.Operators 28 | { 29 | /// 30 | /// Create abstract BaseOperator implements IOperator 31 | /// 32 | public abstract class BaseOperator : IOperator 33 | { 34 | /// 35 | /// Op 36 | /// 37 | public string Op { get; set; } 38 | 39 | /// 40 | /// Prec 41 | /// 42 | public int Prec { get; set; } 43 | 44 | /// 45 | /// Calculate 46 | /// 47 | /// left 48 | /// right 49 | /// dc 50 | /// Value is type Object result Calculate 51 | public virtual object Calculate(object left, object right, ExpressionContext dc) 52 | { 53 | return new NotImplementedException(); 54 | } 55 | 56 | /// 57 | /// Get Ass 58 | /// 59 | /// Value is type enum Assoc 60 | public virtual Assoc GetAss() 61 | { 62 | throw new NotImplementedException(); 63 | } 64 | 65 | /// 66 | /// Get Op 67 | /// 68 | /// Value is type string 69 | public virtual string GetOp() 70 | { 71 | return Op; 72 | } 73 | 74 | /// 75 | /// Get Prec 76 | /// 77 | /// Value is type int 78 | public virtual int GetPrec() 79 | { 80 | return Prec; 81 | } 82 | 83 | /// 84 | /// Validate 85 | /// 86 | /// Value is System.Type 87 | public virtual Type Validate(Type typeLeft, Type typeRight) 88 | { 89 | throw new NotImplementedException(); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Operators/Unary/AbstractUnaryOperator.cs: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | The MIT License 4 | 5 | Copyright (c) 2021 MathEval.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | using org.matheval.Operators; 26 | using System; 27 | using static org.matheval.Common.Afe_Common; 28 | 29 | namespace org.matheval.Operators.Unary 30 | { 31 | /// 32 | /// Create abstract AbstractUnaryOperator implements abstract BaseOperator and interface IOperator 33 | /// Base class for executing Unary op 34 | /// 35 | public abstract class AbstractUnaryOperator : BaseOperator, IOperator 36 | { 37 | /// 38 | /// Initializes a new instance structure to a specified type string value and type int value 39 | /// 40 | /// op 41 | /// precedence 42 | public AbstractUnaryOperator(string op, int precedence) 43 | { 44 | Op = op; 45 | Prec = precedence; 46 | } 47 | 48 | /// 49 | /// Calculate result 50 | /// 51 | /// left 52 | /// right 53 | /// dc 54 | /// Calculate Value 55 | public new virtual object Calculate(object left, object right, ExpressionContext dc) 56 | { 57 | if (right != null) 58 | { 59 | throw new Exception(MSG_UNARY_INVALID); 60 | } 61 | return null; 62 | } 63 | 64 | /// 65 | /// GetAss 66 | /// 67 | /// Enum 68 | public new Assoc GetAss() 69 | { 70 | throw new NotImplementedException(); 71 | } 72 | /// 73 | /// Validate 74 | /// 75 | /// typeLeft 76 | /// typeRight 77 | /// Type 78 | public new virtual Type Validate(Type typeLeft, Type typeRight) 79 | { 80 | throw new NotImplementedException(); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/modFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// MOD(11,2) -> 1 32 | /// MOD(6.25,1) -> 0.25 33 | /// MOD(100,33) -> 1 34 | /// 35 | public class modFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List{ 44 | new FunctionDef(Afe_Common.Const_Mod, new System.Type[]{ typeof(decimal), typeof(decimal) }, typeof(decimal), 2)}; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | return this.Mod(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture), Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture), dc); 56 | } 57 | 58 | /// 59 | /// Mod 60 | /// 61 | /// left 62 | /// right 63 | /// Value Mod 64 | public decimal Mod(Object left, Object right, ExpressionContext dc) 65 | { 66 | if (left is decimal leftDecimal && right is decimal rightDecimal) 67 | { 68 | //decimal leftDecimal = decimal.Parse((decimal)left.ToString(), dc.WorkingCulture); 69 | //decimal rightDecimal = decimal.Parse(right.ToString(), dc.WorkingCulture); 70 | decimal quotient = Math.Floor(leftDecimal / rightDecimal); 71 | return leftDecimal - (rightDecimal * quotient); 72 | } 73 | throw new Exception("Remainder operator can be only apply for integer/long"); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Operators/Binop/AndOperator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using System; 25 | using static org.matheval.Common.Afe_Common; 26 | 27 | namespace org.matheval.Operators.Binop 28 | { 29 | /// 30 | /// Create class AndOperator implements AbstractBinOperator 31 | /// Example 32 | /// (2>1)&&(6>7) -> false 33 | /// 34 | public class AndOperator : AbstractBinOperator 35 | { 36 | /// 37 | /// Initializes a new instance structure to a specified type string value and type int value ang Assoc value 38 | /// 39 | /// op 40 | /// precedence 41 | public AndOperator(string op, int precedence, Assoc assoc) : base(op, precedence, assoc) 42 | { 43 | } 44 | 45 | /// 46 | /// Calculate 47 | /// 48 | /// left 49 | /// right 50 | /// dc 51 | /// Calculate value 52 | public override object Calculate(object left, object right, ExpressionContext dc) 53 | { 54 | if (left is bool && right is bool) 55 | { 56 | return (bool)left == true && (bool)right == true; 57 | } 58 | throw new Exception(string.Format(MSG_WRONG_OP_PARAM_EX, new string[] { "Logical AND", "Boolean" })); 59 | } 60 | 61 | /// 62 | /// Validate 63 | /// 64 | /// typeLeft 65 | /// typeRight 66 | /// Type Boolean or null 67 | public override Type Validate(Type typeLeft, Type typeRight) 68 | { 69 | if ( 70 | (typeLeft.Equals(typeof(bool)) || typeLeft.Equals(typeof(object))) 71 | && 72 | (typeRight.Equals(typeof(bool)) || typeRight.Equals(typeof(object))) 73 | ) 74 | { 75 | return typeof(bool); 76 | } 77 | return null; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/ceilingFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns the smallest integral value greater than or equal to the specified number. 32 | /// CEILING(2.1) -> 3 33 | /// CEILING(2.5, 1) -> 3 34 | /// CEILING(-2.5, -2) -> -4 35 | /// 36 | public class ceilingFunction : IFunction 37 | { 38 | /// 39 | /// Get Information 40 | /// 41 | /// FunctionDefs 42 | public List GetInfo() 43 | { 44 | return new List{ 45 | new FunctionDef(Afe_Common.Const_Ceiling, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1), 46 | new FunctionDef(Afe_Common.Const_Ceiling, new System.Type[] { typeof(decimal),typeof(decimal) }, typeof(decimal), 2)}; 47 | } 48 | 49 | /// 50 | /// Execute 51 | /// 52 | /// args 53 | /// dc 54 | /// Value 55 | public Object Execute(Dictionary args, ExpressionContext dc) 56 | { 57 | return this.Ceiling(args, dc); 58 | } 59 | 60 | /// 61 | /// Ceiling 62 | /// 63 | /// args 64 | /// Value Ceiling 65 | public decimal Ceiling(Dictionary args, ExpressionContext dc) 66 | { 67 | if (args.Count == 1) 68 | { 69 | return Math.Ceiling(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture)); 70 | } 71 | else 72 | { 73 | return Math.Ceiling(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture) / Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture)) * Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture); 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/floorFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns the largest integral value less than or equal to the specified number. 32 | /// FLOOR(3.7) -> 3 33 | /// FLOOR(3.7,2) -> 2 34 | /// FLOOR(1.58,0.1) -> 1.5 35 | /// FLOOR(0.234,0.01) -> 0.23 36 | /// FLOOR(-2.5,-2) -> -2 37 | /// 38 | public class floorFunction : IFunction 39 | { 40 | /// 41 | /// Get Information 42 | /// 43 | /// FunctionDefs 44 | public List GetInfo() 45 | { 46 | return new List{ 47 | new FunctionDef(Afe_Common.Const_Floor, new System.Type[]{ typeof(decimal) }, typeof(decimal), 1), 48 | new FunctionDef(Afe_Common.Const_Floor, new System.Type[] { typeof(decimal), typeof(decimal) }, typeof(decimal), 2)}; 49 | } 50 | 51 | /// 52 | /// Execute 53 | /// 54 | /// args 55 | /// dc 56 | /// Value 57 | public Object Execute(Dictionary args, ExpressionContext dc) 58 | { 59 | return this.Floor(args, dc); 60 | } 61 | 62 | /// 63 | /// Floor 64 | /// 65 | /// args 66 | /// Value Floor 67 | public decimal Floor(Dictionary args, ExpressionContext dc) 68 | { 69 | if (args.Count == 1) 70 | { 71 | return Math.Floor(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture)); 72 | } 73 | else 74 | { 75 | return Math.Floor(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture) / Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture)) * Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/rightFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Extracts a given number of characters from 32 | /// the right side of a supplied text string 33 | /// Example: 34 | /// RIGHT("abcd",3) -> bcd 35 | /// 36 | public class rightFunction : IFunction 37 | { 38 | /// 39 | /// Get Information 40 | /// 41 | /// FunctionDefs 42 | public List GetInfo() 43 | { 44 | return new List { new FunctionDef(Afe_Common.Const_RIGHT, new System.Type[] { typeof(string), typeof(decimal) }, typeof(string), 2) }; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | //return Afe_Common.Right(Afe_Common.ToString(args[Afe_Common.Const_Key_One]), int.Parse(Afe_Common.ToString(args[Afe_Common.Const_Key_Two]))); 56 | return this.Right(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture))); 57 | } 58 | 59 | /// 60 | /// Formula Right 61 | /// 62 | /// stringValue 63 | /// count 64 | /// Value Right 65 | private string Right(string stringValue, int count) 66 | { 67 | if (!string.IsNullOrEmpty(stringValue)) 68 | { 69 | int startIndex = stringValue.Length - count < 0 ? 0 : stringValue.Length - count; 70 | int endIndex = count > stringValue.Length ? stringValue.Length : count; 71 | return stringValue.Substring(startIndex, endIndex); 72 | } 73 | return string.Empty; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Operators/Binop/OrOperator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using System; 25 | using static org.matheval.Common.Afe_Common; 26 | 27 | namespace org.matheval.Operators.Binop 28 | { 29 | /// 30 | /// Create class Or Operator implements AbstractBinOperator 31 | /// Example: 32 | /// (2>1)||(6>7) -> true 33 | /// 34 | public class OrOperator : AbstractBinOperator 35 | { 36 | /// 37 | /// Initializes a new instance structure to a specified type string value and type int value and Assoc value 38 | /// 39 | /// op 40 | /// precedence 41 | /// assoc 42 | public OrOperator(string op, int precedence, Assoc assoc) : base(op, precedence, assoc) 43 | { 44 | } 45 | 46 | /// 47 | /// Calculate 48 | /// 49 | /// left 50 | /// right 51 | /// dc 52 | /// Calculate value or Exception 53 | public override object Calculate(object left, object right, ExpressionContext dc) 54 | { 55 | if (left is bool && right is bool) 56 | { 57 | return (bool)left == true || (bool)right == true; 58 | } 59 | throw new Exception(string.Format(MSG_WRONG_OP_PARAM_EX, new string[] { "Logical OR", "Boolean" })); 60 | } 61 | 62 | /// 63 | /// Validate 64 | /// 65 | /// typeLeft 66 | /// typeRight 67 | /// Type Boolean or null 68 | public override Type Validate(Type typeLeft, Type typeRight) 69 | { 70 | if ( 71 | (typeLeft.Equals(typeof(bool)) || typeLeft.Equals(typeof(object))) 72 | && 73 | (typeRight.Equals(typeof(bool)) || typeRight.Equals(typeof(object))) 74 | ) 75 | { 76 | return typeof(bool); 77 | } 78 | return null; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/xorFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace org.matheval.Functions 30 | { 31 | /// 32 | /// Logical xor function 33 | /// XOR(2>1,3<9/2) -> false 34 | /// XOR(2>1,3<9/2,6<10) -> true 35 | /// XOR(2>1,3<9/2,6<10,100<200) -> false 36 | /// 37 | public class xorFunction : IFunction 38 | { 39 | /// 40 | /// Get Information 41 | /// 42 | /// FunctionDefs 43 | public List GetInfo() 44 | { 45 | return new List{ 46 | new FunctionDef(Afe_Common.Const_Xor, new System.Type[]{ typeof(Boolean) }, typeof(Boolean), -1)}; 47 | } 48 | 49 | /// 50 | /// Execute 51 | /// 52 | /// args 53 | /// dc 54 | /// Value 55 | public Object Execute(Dictionary args, ExpressionContext dc) 56 | { 57 | return this.LogicalXor(args); 58 | } 59 | 60 | /// 61 | /// LogicalXor 62 | /// 63 | /// args 64 | /// Value 65 | public Boolean LogicalXor(Dictionary args) 66 | { 67 | if (args.Count < 2) 68 | { 69 | throw new Exception(string.Format("{0} {1}", "Too few agrument for method", "XOR")); 70 | } 71 | else if (args.Count == 2) 72 | { 73 | return ((Boolean)args[Afe_Common.Const_Key_One]) ^ ((Boolean)args[Afe_Common.Const_Key_Two]); 74 | } 75 | else 76 | { 77 | int trueCount = 0; 78 | foreach (Object obj in args.Values) 79 | { 80 | if (obj is Boolean || (Boolean)obj) 81 | { 82 | trueCount++; 83 | } 84 | } 85 | return (trueCount > 0 && trueCount % 2 == 1); 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/midFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Extracts a given number of characters 32 | /// from the middle of a supplied text string 33 | /// MID("abcd",1,2) -> ab 34 | /// 35 | public class midFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List { new FunctionDef(Afe_Common.Const_MID, new System.Type[] { typeof(string), typeof(decimal), typeof(decimal) }, typeof(string), 3) }; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | 55 | return this.Mid( 56 | Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), 57 | Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture)), 58 | Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Three], dc.WorkingCulture)) 59 | ); 60 | } 61 | 62 | /// 63 | /// Formula Mid 64 | /// 65 | /// stringValue 66 | /// index 67 | /// length 68 | /// Value get at mid 69 | private string Mid(string stringValue, int index, int length) 70 | { 71 | if (!string.IsNullOrEmpty(stringValue) && index > 0 && index <= stringValue.Length) 72 | { 73 | int len = index + length > stringValue.Length ? stringValue.Length - index + 1 : length; 74 | return stringValue.Substring(index - 1, len); 75 | } 76 | return string.Empty; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/rpadFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns a new string of a specified length in which the end of the current string is padded with spaces or with a specified Unicode character. 32 | /// rpad("abc",5,"*") => abc** 33 | /// rpad("abc",2,"*") => abc 34 | /// 35 | public class rpadFunction : IFunction 36 | { 37 | /// 38 | /// Get Information 39 | /// 40 | /// FunctionDefs 41 | public List GetInfo() 42 | { 43 | return new List { new FunctionDef(Afe_Common.Const_RPAD, new System.Type[] { typeof(string), typeof(decimal), typeof(string) }, typeof(string), 3) }; 44 | } 45 | 46 | /// 47 | /// Execute 48 | /// 49 | /// args 50 | /// dc 51 | /// Value 52 | public Object Execute(Dictionary args, ExpressionContext dc) 53 | { 54 | 55 | return this.RightPad(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture)), Afe_Common.ToString(args[Afe_Common.Const_Key_Three], dc.WorkingCulture)); 56 | } 57 | 58 | /// 59 | /// Formula RightPad 60 | /// 61 | /// stringValue 62 | /// length 63 | /// padString 64 | /// Value RightPad 65 | private string RightPad(string stringValue, int length, string padString) 66 | { 67 | if (!string.IsNullOrEmpty(stringValue) && string.IsNullOrEmpty(padString)) 68 | { 69 | return stringValue; 70 | }else if (!string.IsNullOrEmpty(padString)) 71 | { 72 | return stringValue.PadRight(length, char.Parse(padString)); 73 | } 74 | return string.Empty; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/lpadFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Returns a new string of a specified length in which the beginning of the current string is padded with spaces or with a specified Unicode character. 32 | /// For Example: 33 | /// lpad("abc",5,"*") => **abc 34 | /// lpad("abc",2,"*") => abc 35 | /// 36 | public class lpadFunction : IFunction 37 | { 38 | /// 39 | /// Get Information 40 | /// 41 | /// FunctionDefs 42 | public List GetInfo() 43 | { 44 | return new List{new FunctionDef(Afe_Common.Const_LPAD, new System.Type[]{ typeof(string), typeof(decimal), typeof(string)}, typeof(string), 3)}; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | return this.LeftPad(Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture), Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture)), Afe_Common.ToString(args[Afe_Common.Const_Key_Three], dc.WorkingCulture)); 56 | } 57 | 58 | /// 59 | /// Formula LeftPad 60 | /// 61 | /// stringValue 62 | /// length 63 | /// padString 64 | /// Value LeftPad 65 | private string LeftPad(string stringValue, int length, string padString) 66 | { 67 | if (!string.IsNullOrEmpty(stringValue) && string.IsNullOrEmpty(padString)) 68 | { 69 | return stringValue; 70 | } 71 | else if (!string.IsNullOrEmpty(padString)) 72 | { 73 | return stringValue.PadLeft(length, char.Parse(padString)); 74 | } 75 | return string.Empty; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/valueFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | 29 | namespace org.matheval.Functions 30 | { 31 | /// 32 | /// Convert text to a numeric value 33 | /// VALUE("123") -> 123 34 | /// VALUE(123) -> 123 35 | /// 36 | public class valueFunction : IFunction 37 | { 38 | /// 39 | /// Get Information 40 | /// 41 | /// FunctionDefs 42 | public List GetInfo() 43 | { 44 | return new List { new FunctionDef(Afe_Common.Const_Value, new System.Type[] { typeof(Object) }, typeof(decimal), 1) }; 45 | } 46 | 47 | /// 48 | /// Execute 49 | /// 50 | /// args 51 | /// dc 52 | /// Value 53 | public Object Execute(Dictionary args, ExpressionContext dc) 54 | { 55 | if (Afe_Common.IsNumber(args[Afe_Common.Const_Key_One])) 56 | { 57 | return Afe_Common.Round(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture), dc); 58 | } 59 | else if (args[Afe_Common.Const_Key_One] is TimeSpan) 60 | { 61 | TimeSpan ts = (TimeSpan)args[Afe_Common.Const_Key_One]; 62 | return Afe_Common.Round(ts.TotalMilliseconds / 1000 / 60 / 60 / 24, dc); 63 | } 64 | else if (args[Afe_Common.Const_Key_One] is DateTime) 65 | { 66 | DateTime dt = (DateTime)args[Afe_Common.Const_Key_One]; 67 | long ms = (long)(dt - new DateTime(1970, 1, 1)).TotalMilliseconds; 68 | return Afe_Common.Round(ms / 1000 / 60 / 60 / 24, dc); 69 | } 70 | else 71 | { 72 | try 73 | { 74 | return Afe_Common.Round(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_One], dc.WorkingCulture), dc); 75 | } 76 | catch(Exception e) 77 | { 78 | throw new Exception(string.Format(Afe_Common.MSG_METH_PARAM_INVALID, new string[] { "value" })); 79 | } 80 | } 81 | 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Functions/Impl/replaceFunction.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using System.Collections.Generic; 27 | 28 | namespace org.matheval.Functions 29 | { 30 | /// 31 | /// Replaces characters specified by location 32 | /// in a given text string with another text string 33 | /// REPLACE("ABC123",4,3,"456") -> ABC456 34 | /// REPLACE("ABC123",1,3,"45") -> 45123 35 | /// REPLACE("123-455-3321","-","") -> 1234553321 36 | /// 37 | public class replaceFunction : IFunction 38 | { 39 | /// 40 | /// Get Information 41 | /// 42 | /// FunctionDefs 43 | public List GetInfo() 44 | { 45 | return new List{ 46 | new FunctionDef(Afe_Common.Const_Replace, new System.Type[]{ typeof(string), typeof(string), typeof(string) }, typeof(string), 3), 47 | new FunctionDef(Afe_Common.Const_Replace, new System.Type[] { typeof(string), typeof(decimal), typeof(decimal), typeof(string) }, typeof(string), 4) }; 48 | } 49 | 50 | /// 51 | /// Execute 52 | /// 53 | /// args 54 | /// dc 55 | /// Value 56 | public Object Execute(Dictionary args, ExpressionContext dc) 57 | { 58 | if (args.Count == 3) 59 | { 60 | return Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture).Replace(Afe_Common.ToString(args[Afe_Common.Const_Key_Two], dc.WorkingCulture), Afe_Common.ToString(args[Afe_Common.Const_Key_Three], dc.WorkingCulture)); 61 | } 62 | else 63 | { 64 | string text = Afe_Common.ToString(args[Afe_Common.Const_Key_One], dc.WorkingCulture); 65 | string left = text.Substring(0, Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture)) - 1); 66 | string right = text.Substring(Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Two], dc.WorkingCulture)) - 1 + Decimal.ToInt32(Afe_Common.ToDecimal(args[Afe_Common.Const_Key_Three], dc.WorkingCulture))); 67 | return left + args[Afe_Common.Const_Key_Four].ToString() + right; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Math expression eval/org.matheval/Operators/Binop/MulOperator.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2021 MathEval.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using org.matheval.Common; 25 | using System; 26 | using static org.matheval.Common.Afe_Common; 27 | 28 | namespace org.matheval.Operators.Binop 29 | { 30 | /// 31 | /// Create class Mul Operator implements AbstractBinOperator 32 | /// Example: 33 | /// 3 * 5 -> 15 34 | /// 35 | public class MulOperator : AbstractBinOperator 36 | { 37 | /// 38 | /// Initializes a new instance structure to a specified type string value and type int value and value assoc 39 | /// 40 | /// op 41 | /// precedence 42 | /// assoc 43 | public MulOperator(string op, int precedence, Assoc assoc) : base(op, precedence, assoc) 44 | { 45 | } 46 | 47 | /// 48 | /// Calculate result 49 | /// 50 | /// left 51 | /// right 52 | /// dc 53 | /// value Calculate 54 | public override object Calculate(object left, object right, ExpressionContext dc) 55 | { 56 | if (Common.Afe_Common.IsNumber(left) && Common.Afe_Common.IsNumber(right)) 57 | { 58 | decimal leftDecimal = Afe_Common.ToDecimal(left, dc.WorkingCulture); 59 | decimal rightDecimal = Afe_Common.ToDecimal(right, dc.WorkingCulture); 60 | return decimal.Multiply(leftDecimal, rightDecimal); 61 | } 62 | throw new Exception(string.Format(MSG_WRONG_OP_PARAM_EX, new string[] { "MUL", "numeric" })); 63 | } 64 | 65 | /// 66 | /// Validate 67 | /// 68 | /// typeLeft 69 | /// typeRight 70 | /// Type 71 | public override Type Validate(Type typeLeft, Type typeRight) 72 | { 73 | if ( 74 | (typeLeft.Equals(typeof(decimal)) || typeLeft.Equals(typeof(object))) 75 | && 76 | (typeRight.Equals(typeof(decimal)) || typeRight.Equals(typeof(object))) 77 | ) 78 | { 79 | return typeof(decimal); 80 | } 81 | return null; 82 | } 83 | } 84 | } 85 | --------------------------------------------------------------------------------