Class Dobjects::MathEvaluator
In: lib/Dobjects/Dvector_extras.rb
Parent: Object

MathEvaluator enables one to evaluate a simple mathematical expression such as "x[0] + cos(x[1])", where the array x is given at each call to compute, or "x + y**z", or…

This class acts as a backend for Dvector.compute_formula, to make sure that the Math module is included, without the drawback of cluttering all Math functions in Dvector, which would admittedly be quite stupid.

Methods

compute   compute_unsafe   new  

Included Modules

Math

Public Class methods

Creates an evaluator for a formula. formula is the formula. It is transformed into a block that takes argname as an argument — argname can be whatever you want. mods are the modules you would like the formula to include. Math is included by default, but you can include other ones to make other kinds of functions available.

 MathEvaluator.new("col[0] + col[1]", "col")
 MathEvaluator.new("x*cos(y)", "x,y")

Public Instance methods

This function does the actual evaluation with the blocks given.

 e = MathEvaluator.new("x*y", "x,y")
 e.compute(1,2)         -> 2

If an exception arises, NaN is returned. Note that compilation problems will be caught before ;-)…

This function does the actual evaluation with the blocks given.

 e = MathEvaluator.new("x*y", "x,y")
 e.compute(1,2)         -> 2

No care is taken to intercept exceptions.

[Validate]