Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to add functions outside of evalmath #3

Open
jcubic opened this issue Aug 21, 2016 · 3 comments
Open

A way to add functions outside of evalmath #3

jcubic opened this issue Aug 21, 2016 · 3 comments

Comments

@jcubic
Copy link

jcubic commented Aug 21, 2016

RIght now you can only add functions by calling evaluate, there should be a way to add function like this:

$math = new EvalMath();
$math->fn['square'] = function($x) {
    return $x*$x;
};
$math->evaluate('square(10)');
@optimistex
Copy link

Альтернативный вариант для достижения той же цели:

    $math = new EvalMath();
    var_dump($math->evaluate('square(x) = x*x'));
    var_dump($math->evaluate('square(10)'));

@koosvanderkolk
Copy link

Альтернативный вариант для достижения той же цели: = An alternative for achieving the same goal: :-)

@jcubic
Copy link
Author

jcubic commented Sep 21, 2017

Yes but what about things like functions that are not possible inside EvalMath like using this library functions and have:

$math = new EvalMath();
$math->fn['gcd'] = function($x) {
    return Algebra::gcd($x);
};
$math->evaluate('square(10)');

or some complicated calculation that's not possible in EvalMath. I've added that function in my fork jcubic/expression.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants