Personal IDL library for M. Galloy

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


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.


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


Michael D. Galloy, 2012

Other file information


does not support functions of multiple variables

top source mg_evalexpr

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

Evaluates a mathematical expression.

Return value

double or long64


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


error out optional type=boolean

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

File attributes

Modification date: Mon Jan 30 14:30:40 2012
Lines: 379
Docformat: rst rst
Personal library of Michael Galloy
Contact me if you have enhancement requests or bug fixes.