Page 1 of 2

xml math functions

Posted: Fri Nov 11, 2016 7:44 pm
by bomber
 sum (takes n arguments)

 difference (takes n arguments)

 product (takes n arguments)

 quotient (takes 2 arguments)

 pow (takes 2 arguments)

 exp (takes 2 arguments)

 abs (takes n arguments)

 sin (takes 1 arguments)

 cos (takes 1 arguments)

 tan (takes 1 arguments)

 asin (takes 1 arguments)

 acos (takes 1 arguments)

 atan (takes 1 arguments)

 atan2 (takes 2 arguments)

 min (takes n arguments)

 max (takes n arguments)

 avg (takes n arguments)

 fraction (takes 1 argument)

 mod (takes 2 arguments)

 random (Gaussian random number, takes no arguments)

 integer (takes one argument)

I thought it would be a good idea as the manual is pretty sketchy as to what these all do to try and understand them...

I'm short on understanding of these


 mod (takes 2 arguments)
 integer (takes one argument)
 fraction (takes 1 argument)
 exp (takes 2 arguments)

any ideas ?

Re: xml math functions

Posted: Fri Nov 11, 2016 7:57 pm
by IAHM-COL
The module should find the remainder of the division

Example

if you divide 4 / 2 then the module is zero
(or 4%2= 0)

if you divide 2/4 then the module is two
(or 2%4 = 2)


You will see it clearer if you try per example 11/2
you can divide the first 10 completely (with no remainder left)
as 10/2 is 5. but the other 1 left cant be fully divided,.
so you express like this

10/2 + 1/2

That one left is the remainder (the part you couldn't fully divide) and thus

11%2 should return you 1


Another example for final clarity

try 35/4

So that's 8.75. Because 32 of those 35 can be fully divided and return 8. but the 0.75 results from the remaining 3 being not fully divisible

therefore

35/4 == 32/4 + 3/4
where the 3 is the remainder

35%4 = 3

Now.
Is the xml operator working as such?

Re: xml math functions

Posted: Fri Nov 11, 2016 8:03 pm
by IAHM-COL
Integer should be the non-decimal part of any real number.

Like
3.5 the integer should return 3

4.532342 the interger should return 4

pi, the integer should return 3

e, the integer should return 2

554.29392 , the integer should return 554

h, the integer should return 0

etc.

Now, does your xml function operate as such?

Re: xml math functions

Posted: Fri Nov 11, 2016 8:06 pm
by IAHM-COL
exp should give you the exponential function result as in

exp(x,n) is X to the power of n

like in

exp(10,3) should be 1000
exp(2,3) should be 8
exp(4,0.5) should be 2

etc.

Does it work like that?

Re: xml math functions

Posted: Fri Nov 11, 2016 8:13 pm
by IAHM-COL
Not sure what to think of the operator fraction, but try this

fraction (0.5) should give you 1 and 2 (since 1/2 is 0.5)
fraction (0.1) should give you 1 and 10

I wonder if a xml function can give you 2 output parameters, thou. or how could it handle this?

Re: xml math functions

Posted: Fri Nov 11, 2016 8:24 pm
by sanhozay
I think fraction should give you the fractional part of a decimal number, so fraction (1.23) should give 0.23 and fraction(10.7) should give you 0.7.

EDIT: I'm not sure fraction is actually implemented. I can't find it in here:

https://sourceforge.net/p/flightgear/si ... ession.hxx
https://sourceforge.net/p/flightgear/si ... ession.cxx

(And there seem to be some that are not listed on the Wiki, e.g. deg2rad, rad2deg and clip).

Re: xml math functions

Posted: Fri Nov 11, 2016 8:52 pm
by bomber

Code: Select all

       <fcs_function name="T4T/test/mod">
      <function>
         <mod>
            <value> 35 </value>
            <value> 4 </value>
         </mod>
      </function>
   </fcs_function>

returns 3


Code: Select all

   <fcs_function name="T4T/test/exp">
      <function>
         <exp>
            <value> 2 </value>
            <value> 3 </value>
         </exp>
      </function>
   </fcs_function>

returns 7.389056099


Code: Select all

   <fcs_function name="T4T/test/integer">
      <function>
         <integer>
            <value> 3.142 </value>
         </integer>
      </function>
   </fcs_function>

returns 3


Code: Select all

   <fcs_function name="T4T/test/fraction">
      <function>
         <fraction>
            <value> 3.142 </value>
         </fraction>
      </function>
   </fcs_function>

returns 0.142

Re: xml math functions

Posted: Fri Nov 11, 2016 9:00 pm
by OPFOR77
http://jsbsim.sourceforge.net/JSBSim/classJSBSim_1_1FGFunction.html explains all of them with examples.

<mod> is modulo, not module.

<exp> raises "e" to the power of the immediate child element.

<fraction> returns the fractional part of the value of the immediate child element.

Re: xml math functions

Posted: Fri Nov 11, 2016 9:03 pm
by bomber
sanhozay wrote:I think fraction should give you the fractional part of a decimal number, so fraction (1.23) should give 0.23 and fraction(10.7) should give you 0.7.

EDIT: I'm not sure fraction is actually implemented. I can't find it in here:

https://sourceforge.net/p/flightgear/si ... ession.hxx
https://sourceforge.net/p/flightgear/si ... ession.cxx

(And there seem to be some that are not listed on the Wiki, e.g. deg2rad, rad2deg and clip).



I think we should first clear up any confusion with those functions supplied by JSBsim alone.... then move on to any traditional xml functions that flightgear provide.

Does that make sense ?

Simon

Re: xml math functions

Posted: Fri Nov 11, 2016 9:57 pm
by sanhozay
Ah, JSBSim functions. I misunderstood. They are documented with examples here:

https://sourceforge.net/p/flightgear/fl ... Function.h