{"id":3351,"date":"2022-10-11T12:37:23","date_gmt":"2022-10-11T12:37:23","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3351"},"modified":"2023-01-25T10:15:37","modified_gmt":"2023-01-25T10:15:37","slug":"calculate","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3351","title":{"rendered":"Calculate"},"content":{"rendered":"\n<p>Executes a given mathematical formula using the provided variables.<\/p>\n\n\n\n<h3>Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">number calculate(string $expression, object $variables)<\/code><\/pre>\n\n\n\n<p><strong>Note:<\/strong> A variable can only be of type: number.<\/p>\n\n\n\n<h3>Parameters<\/h3>\n\n\n\n<p><strong>$expression:<\/strong> The mathematical formula to calculate. Must be a string value. A list of available mathematical operators is provided below.<br><strong>$variables:<\/strong> The variables or numbers to feed into the $expression formula. Must be an object containing keys and values for all variables used in $expression.<\/p>\n\n\n\n<h3>Example<\/h3>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"inputVariables\": {\n        \"a\": 10,\n        \"b\": 20\n    }\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n    result: calculate('a+b', inputVariables)\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"result\": 30.0\n}<\/code><\/pre>\n\n\n\n<p>In this example, no sample data is needed as the data is defined the variables of the function. The $expression is defined to add the value of two variables &#8220;a&#8221; and &#8220;b&#8221;. The variables are defined to have values of 10 and 20 respectively, thus the sum of the variables is 30.<\/p>\n\n\n\n<h3>Notes<\/h3>\n\n\n\n<p><strong>Available mathematical operators<\/strong><\/p>\n\n\n\n<p>These are the operators that can be used to construct the $expression to be calculated.<\/p>\n\n\n\n<ul><li>Addition: +<\/li><li>Subtraction: \u2013<\/li><li>Multiplication: *<\/li><li>Division: \/<\/li><li>Prioritisation: ( )<\/li><li>Modulo: %<\/li><li>Exponentiation: ^<\/li><li>Negation: !<\/li><\/ul>\n\n\n\n<p><strong>Base functions<\/strong><\/p>\n\n\n\n<p>These base functions are also available and potentially helpful when using the calculate function.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Function<\/th><th>Arguments<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>sin<\/td><td>sin(a1)<\/td><td>Sine<\/td><\/tr><tr><td>cos<\/td><td>cos(a1)<\/td><td>Cosine<\/td><\/tr><tr><td>asin<\/td><td>asin(a1)<\/td><td>Arcsine<\/td><\/tr><tr><td>acos<\/td><td>acos(a1)<\/td><td>Arccosine<\/td><\/tr><tr><td>tan<\/td><td>tan(a1)<\/td><td>Tangent<\/td><\/tr><tr><td>cot<\/td><td>cot(a1)<\/td><td>Cotangent<\/td><\/tr><tr><td>atan<\/td><td>atan(a1)<\/td><td>Arctangent<\/td><\/tr><tr><td>acot<\/td><td>acot(a1)<\/td><td>Arccotangent<\/td><\/tr><tr><td>loge<\/td><td>loge(a1)<\/td><td>Natural logarithm<\/td><\/tr><tr><td>log10<\/td><td>log10(a1)<\/td><td>Logarithm with base 10<\/td><\/tr><tr><td>logn<\/td><td>logn(a1, a2)<\/td><td>Logarithm<\/td><\/tr><tr><td>sqrt<\/td><td>sqrt(a1)<\/td><td>Square root<\/td><\/tr><tr><td>if<\/td><td>if(a1, a2, a3)<\/td><td>IF a1 IS true THEN a2 ELSE a3<\/td><\/tr><tr><td>max<\/td><td>max(a1, &#8230;, a_n)<\/td><td>Maximum<\/td><\/tr><tr><td>min<\/td><td>min(a1, &#8230;, a_n)<\/td><td>Minimum<\/td><\/tr><tr><td>avg<\/td><td>avg(a1, &#8230;, a_n)<\/td><td>Average<\/td><\/tr><tr><td>median<\/td><td>median(a1, &#8230;, a_n)<\/td><td>Median<\/td><\/tr><tr><td>round<\/td><td>round(a1)<\/td><td>Round<\/td><\/tr><tr><td>random<\/td><td>random()<\/td><td>Generate a random double value<br>between 0.0 and 1.0<\/td><\/tr><\/tbody><\/table><figcaption>Base functions<\/figcaption><\/figure>\n\n\n\n<p><strong>Decimal separator<\/strong><\/p>\n\n\n\n<p>Decimal separator is a dot, and not a comma as in some regions of the world. i.e. &#8220;5.8&#8221; rather than &#8220;5,8&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Executes a given mathematical formula using the provided variables. Syntax Note: A variable can only be of type: number. Parameters $expression: The mathematical formula to calculate. Must be a string value. A list of available mathematical operators is provided below.$variables: The variables or numbers to feed into the $expression formula. Must be an object containing [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"parent":271,"menu_order":20,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3351"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3351"}],"version-history":[{"count":7,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3351\/revisions"}],"predecessor-version":[{"id":3830,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3351\/revisions\/3830"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/271"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}