glynn.clements at virgin.net
Thu Feb 14 01:59:31 EST 2002
I've committed r.mapcalc3 to the release branch.
This program should be fully compatible with the old r.mapcalc, except
1. It supports both FCELL ("float") and DCELL ("double") values (as
well as integer CELL values). As in C, a floating-point constant is
"float" if it has a trailing "f" or "F", e.g. "1.0f", and "double"
otherwise. Values may be coerced to "float" using "float(...)" and to
"double" using "double(...)". "math.h" functions (e.g. sqrt, exp, log,
sin etc) return "double".
2. For functions whose return type varies according to the operand
types, the new version may be slightly more "strict" in the type
coercion; e.g. "eval(1.0, 1)" returns the integer 1.
3. The power operator (^) behaves like the other infix binary
operators (+,-,*,/) in that its return type is the "greatest" of the
operand types, so raising one integer to the power of another integer
produces an integer result. OTOH, the two-argument form of the exp()
operator always returns "double".
I would appreciate it if people could test it for compatibility.
FWIW, the main reason for re-writing r.mapcalc was to simplify the
code. The old version used a separate program ($GISBASE/etc/polish) to
convert the expression to reverse-Polish notation, and then performed
the evaluation using explicit operand/operator stacks. The new version
has the parser built in, and operates directly on the parse tree,
using a set of mutually-recursive functions. This should make it
easier to add new features (e.g. more detailed error messages).
Glynn Clements <glynn.clements at virgin.net>
More information about the grass-dev