Core Function Math
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> Math( <expression> ) </pre> === Description === Parse a string containing mathematical equations. === Parameters === ==== expression ==== Any valid numeric expression....") |
(→Return Value) |
||
(2 intermediate revisions by one user not shown) | |||
Line 15: | Line 15: | ||
=== Return Value === | === Return Value === | ||
− | Returns the resolved number. | + | Success: Returns the resolved number. |
+ | |||
+ | Failure: Returns NULL. | ||
=== Remarks === | === Remarks === | ||
This is very similar to Eval() however attempts to return the numeric value and is better than Eval() for this task. | This is very similar to Eval() however attempts to return the numeric value and is better than Eval() for this task. | ||
+ | |||
+ | This function will not throw an exception or trigger an error if something goes wrong with parsing the expression although it will complain if it doesn't find a function etc as you would expect. | ||
=== Example === | === Example === | ||
Line 33: | Line 37: | ||
println($val); | println($val); | ||
− | // Using constants and functions | + | // Using constants and functions even a call to another Math() function |
$val = Math(" @PI + 100 + ($a / 2) + Abs(-1000) + Math( '100 + 1337' ) "); | $val = Math(" @PI + 100 + ($a / 2) + Abs(-1000) + Math( '100 + 1337' ) "); | ||
println($val); | println($val); |
Latest revision as of 20:40, 19 August 2014
Math( <expression> )
Contents |
Description
Parse a string containing mathematical equations.
Parameters
expression
Any valid numeric expression.
Return Value
Success: Returns the resolved number.
Failure: Returns NULL.
Remarks
This is very similar to Eval() however attempts to return the numeric value and is better than Eval() for this task.
This function will not throw an exception or trigger an error if something goes wrong with parsing the expression although it will complain if it doesn't find a function etc as you would expect.
Example
// A simple one $val = Math(" 100 + (100 / 2) "); println($val); // Using variables $a = 90; $val = Math(" 100 + ($a / 2) "); println($val); // Using constants and functions even a call to another Math() function $val = Math(" @PI + 100 + ($a / 2) + Abs(-1000) + Math( '100 + 1337' ) "); println($val);