mglib

Personal IDL library for M. Galloy

single page | use frames     summary     class     fields     routine details     file attributes

analysis/

mg_evalexpr.pro

includes main-level program

Evaluates a mathematical expression using the basic arithmetic operators +, -, *, /, and ^ along with parentheses for grouping and simple function calls of a single variable.

This routine does not use EXECUTE, so it is safe to use in the Virtual Machine.

Examples

For example, simple arithmetic expressions can be evaluated:

IDL> print, mg_evalexpr('1 + 2 + 3', error=error), error 6 0
Note that the ERROR keyword returns whether there was an error in evaluating the expression. Expressions can also take variables, if their values are provided via a structure or hash-like object:
IDL> print, mg_evalexpr('exp(i * pi)', { pi: !dpi, i: complex(0, 1) }) ( -1.0000000, 1.2246468e-16)

Author information

Author

Michael D. Galloy, 2012

Other file information

Bugs:

does not support functions of multiple variables

Requires:

IDL 8.0

Routines

top mg_evalexpr

result = mg_evalexpr(expr [, vars] [, /error])

Evaluates a mathematical expression.

Return value

double or long64

Parameters

expr in required type=string

expression to evaluate

vars in optional type=structure or hash

variables to substitute into expression specified as a structure or hash-like object; if a structure, the variable names are case-insensitive

Keywords

error out optional type=boolean

set to named variable to return if there was an error evaluating the expression

File attributes

Modification date: Wed May 14 15:07:14 2014
Lines: 171
Docformat: rst rst
Personal library of Michael Galloy
Contact me if you have enhancement requests or bug fixes.