Acme-AlgebraicToRPN
view release on metacpan or search on metacpan
lib/Acme/AlgebraicToRPN.pm view on Meta::CPAN
atan
atan2
acot
sinh
cosh
asinh
acosh
Plus any that you may add in constructor [1].
undef is returned if the parens don't balance. That's all the
checking we do.
[1] If you supply a custom function, you can supply arguments
to it. When you see your function name on the returned stack,
the next thing on the stack is the I<number> of arguments,
and then the arguments themselves. For example, let's say
you registered your function 'foo' (in constructor)
and you gave B<rpn> this equation: 4*foo(a,3)
You'd get back this:
lib/Acme/AlgebraicToRPN.pm view on Meta::CPAN
my $rpn;
eval q(
$tree = $.parser->parse($algebraic);
$rpn = $tree->to_string('prefix');
);
if ($@) {
print STDERR "$.Class - equation didn't parse; did you forget ",
"to add a userFunc?\n";
return undef;
}
$rpn =~ s/\s//g;
./_Eval($rpn);
my @result = ./_Cleanup();
# reset, ready for next equation
$.stack = [];
return @result;
}
( run in 1.877 second using v1.01-cache-2.11-cpan-d80b1682f3f )