Expressions: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
m (→‎Sample Expressions: Clarification about order, since SGPropertyNodes are generally used as unordered associative containers versus vectors)
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Stub}}
{{Stub}}
{{-}}
'''Expressions''' (or '''SGExpressions''') are a feature of the SimGear library and provide a nice way of implementing complex math formulas using XML syntax.
'''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.
They are supported in many systems within the FlightGear code.


'''Beware:''' 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 Not-a-Number Errors|Cascading NaNs]].
{{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.}}


== Usage ==
== Usage ==
Line 13: Line 14:


== Sample Expressions ==
== 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).
This is a sample expression for <code>c = sqrt(a*a + b^2)</code>. Children/arguments are parsed in the order they appear in in the file (or the order in which they are set via property methods).
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<expression>
<expression>
Line 33: Line 34:
== Supported elements ==
== Supported elements ==
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<abs> <!-- also: fabs -->
<acos>
<acos>
<asin>
<asin>
<atan>
<atan>
<atan2>
<ceil>
<ceil>
<clip>
<cos>
<cos>
<cosh>
<cosh>
<difference> <!-- also: dif -->
<div>
<exp>
<exp>
<floor>
<floor>
<log>
<log>
<log10>
<log10>
<max>
<min>
<mod>
<pow>
<product> <!-- also: prod -->
<property> <!-- Unlike elsewhere, 'prop' does not work in expressions. -->
<rad2deg>
<rad2deg>
<deg2rad>
<sin>
<sin>
<sinh>
<sinh>
<sqr>
<sqrt>
<sqrt>
<sum>
<table>
<tan>
<tan>
<tanh>
<tanh>
<atan2>
<div>
<mod>
<pow>
<value>
<value>
<property>
<abs> <!-- also: fabs -->
<sqr>
<clip>
<div>
<mod>
<sum>
<difference> <!-- also: dif -->
<product> <!-- also: prod -->
<min>
<max>
<table>
</syntaxhighlight>
</syntaxhighlight>
== Related content ==
=== Wiki articles ===
* [[Conditions]]
* [[PropertyList XML files]]
=== Source code ===
* {{simgear file|simgear/structure/SGExpression.hxx}}
* {{simgear file|simgear/structure/SGExpression.cxx}}
[[Category:XML]]

Revision as of 17:17, 3 May 2019

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.

Usage

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).

<expression>
  <sqrt>
    <sum>
      <product>
        <property>/value/a</property>
        <property>/value/a</property>
      </product>
      <pow>
        <property>/value/b</property>
        <value>2</value>
      </pow>
    </sum>
  </sqrt>
</expression>

Supported elements

<abs> <!-- also: fabs -->
<acos>
<asin>
<atan>
<atan2>
<ceil>
<clip>
<cos>
<cosh>
<difference> <!-- also: dif -->
<div>
<exp>
<floor>
<log>
<log10>
<max>
<min>
<mod>
<pow>
<product> <!-- also: prod -->
<property> <!-- Unlike elsewhere, 'prop' does not work in expressions. -->
<rad2deg>
<deg2rad>
<sin>
<sinh>
<sqr>
<sqrt>
<sum>
<table>
<tan>
<tanh>
<value>

Related content

Wiki articles

Source code