From FlightGear wiki
(Redirected from Expression)
Jump to navigation Jump to search
This article is a stub. You can help the wiki by expanding it.

Expressions (or SGExpressions) are a feature of the SimGear library and provide a nice way of implementing complex math formulas using XML syntax. They are supported in many systems within the FlightGear code.

Caution  Expressions do not check if your math creates floating point exceptions (like division by zero conditions, taking the square root of a negative number, etc.). This can cause undefined behavior and may result in NaNs or even Cascading NaNs.


Expressions are supported in

Sample Expressions

This is a sample expression for c = sqrt(a*a + b^2). Children/arguments are parsed in the order they appear in in the file (or the order in which they are set via property methods).


Supported elements

<abs> <!-- also: fabs -->
<clip> <!-- <clipMin> <clipMax> -->
<difference> <!-- also: dif -->
<product> <!-- also: prod -->
<property> <!-- Unlike elsewhere, 'prop' does not work in expressions. -->
<table> <!-- <entry><ind> value </ind><dep> value </dep></entry> -->


The table expression uses the following syntax, similarly to the <interpolation> element:

	<!-- put an input element here, this can be <property> or any other operation
		<ind>0.0</ind> <!-- the value of the input (independent value) -->
		<dep>0.0</dep> <!-- the value of the output (dependent value) -->
        ... <!-- you can put as many entries as you want -->


The table:

0.0 5.0
0.5 7.5
0.9 -5.0
1.0 25.0

translates to the following code:

	<!-- put an input element here, this can be a <property> or any other operation -->


An expression to limit e.g. rotation:


Hints and tips


While there is no element for rounding, this workaround can be used for that:


Related content

Wiki articles

Source code