Sign in to follow this  
Guest rkruijer

XML Operators

Recommended Posts

Happy New Year to you all. The operator && will check if the 2 last stack entries are both 1. Is there an operator that will check if both are 0 (zero) ?I could not find it in Anne Bartels listThere is a work around of course but stll wondering. Except from not showing does it still execute the code or does it skip the code all together? Roelof

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

"The operator && will check if the 2 last stackentries are both 1. "Doesn't && check that the last 2 stack entries are non-zero, not that they both are 1? Or am I confusing it with C?

Share this post


Link to post
Share on other sites

>"The operator && will check if the 2 last stack>entries are both 1. ">>Doesn't && check that the last 2 stack entries are non-zero,>not that they both are 1? Or am I confusing it with C?Search me... (-:Roelof

Share this post


Link to post
Share on other sites

>The operator && will check if the 2 last stack entries are>both 1. >>Is there an operator that will check if both are 0 (zero) ?>I could not find it in Anne Bartels list>Roelof I think: || ! if{ } Will give you what you need. " IF NOT (true) st0 OR st 1 " Elementary Boolean algebra. Ron

Share this post


Link to post
Share on other sites

Hello (X:what ever, bool) 0 == (X:whatever, bool) 0 = && if both are true gives 1

Share this post


Link to post
Share on other sites

> Hello> (X:what ever, bool) 0 == (X:whatever, bool) 0 == && if both>are true gives 1That's what I ment when I said "Of course there is a work around." (-:Roelof

Share this post


Link to post
Share on other sites

> || !> if{ }>> Will give you what you need. >>> " IF NOT (true) st0 OR st 1 ">> Elementary Boolean algebra.>> RonYou're right! Only 0 0 wil result in 1Very effective and it beats (var1,bool) 0 == (var2,bool) 0 == &&I will add it to the list. YhanksRoelof

Share this post


Link to post
Share on other sites

>>> || !>> if{ }>> Will give you what you need. >> " IF NOT (true) st0 OR st 1 ">> Elementary Boolean algebra.>> Ron>You're right! Only 0 0 wil result in 1>Very effective and it beats (var1,bool) 0 == (var2,bool) 0 ==>&&>I will add it to the list. Yhanks>Roelof There is a simple way to convert AND to NOT-OR by using "DeMorgan's Theorem". It was often used in digital logic design. In fact, one could design any digital system with only one TTL integrated circuit (Quad NAND). One normally draws bars over the Bools and Operators to indicate 'NOT' and "Negative Logic". This is just a limited example of the process:. - - ------ A AND B == A OR B Where the upper bar indicates 'NOT'. In this case: (NOT A) AND (NOT :( == NOT (A OR :( In this conversion one also replaces an AND with OR, or vice versa. I had to verify the result by considering 'both == 0' -- it's been some time since I used the Theorem. Wickpedia must have some info on Boolean Algegra, etc. Learning how to use it and convert between equivalent expressions would certainly aid working out more complex combinations of XML Logic. Or, Logic in any programming languge. Ron

Share this post


Link to post
Share on other sites

>The operator && will check if the 2 last stack>entries are both 1. In FS XML, not exactly :-)&& (or "and") will check that BOTH 2 last stack entries are >= 1 OR <= -1, giving 1 OR 0 otherwise. If you are testing two bool vars, of course the only posibilities are 1 or 0. BUT, what happens when those values are not boolean?ie:2.5 1.1 && gives 10.66 1.34 && gives 0-1.45 3.55 && gives 1-0.45 0.99 && gives 0etc..Is there an operator that will check if both are 0 (zero) ?Not a direct one that I know.The classic would be "Value1 0 == Value2 0 == and"|| ! (OR NOT) as proposed by Ron will work only for boolean values, but it won't if both values are between 1 and -1 Tom

Share this post


Link to post
Share on other sites

>>The operator && will check if the 2 last stack>>entries are both 1. >>In FS XML, not exactly :-)>&& (or "and") will check that BOTH 2 last stack entries are>>= 1 OR <= -1, giving 1 OR 0 otherwise. If you are testing two>bool vars, of course the only posibilities are 1 or 0. >BUT, what happens when those values are not boolean?>ie:>2.5 1.1 && gives 1>0.66 1.34 && gives 0>-1.45 3.55 && gives 1>-0.45 0.99 && gives 0>etc.. One shouldn't use non bool variables when doing Bool Logic.> .............>>|| ! (OR NOT) as proposed by Ron will work only for boolean>values, but it won't if both values are between 1 and -1 >Tom "0" is almost always False, but what value(s) is recognized as True depends on the convention of the language. I've often defined: F = 0 T = not F in ASM, BASIC, etc. so 'T' is set to the language's convention. I think that sets T = -1 in some langages. In fact, that worked in XML Macros, but wasn't worth the trouble. It is shorter to use '0' or '1' to define False or True. Unfortunately, the varabile type doesn't mean much in MS XML. One can set "1.5 (>L:Var,enum)". "++" increments it to 2.5. In fact, an 'enum' should be a Cardinal, 0 to max_integer. Never fractional or less than 0. While type 'bool' would normally contain two states, True or False. Using Bool Logic on general variables may give defined results, but is dangerous. Much better to use only real Bools for the variables. If one needs a general comparison, he can first do something like: "(L:Var1,number) l2 >" to set the stack top to 1 or 0 so the following "if[ " block has a real Bool to work with.Ron

Share this post


Link to post
Share on other sites

>One shouldn't use non bool variables when doing Bool>Logic.I agree, but as he refered to "the 2 last stack entries", I though it was useful to clarify a bit. Values put on the stack are treated as bytes until an operation is made with them, so they initialy "don't understand" of bool, number, etc.>"0" is almost always False, but what value(s) is>recognized as True depends on the convention of the language. Here, any value >= 1 or <= -1 is treated as True, otherwise is treated as False>Using Bool Logic on general variables may give defined>results, but is dangerous. Much better to use only real>Bools for the variables. Agree also. However, as code errors are not easy to debug in XML, sometimes an unpredicted result may appear. That's the reason I think it's worth to know how the stack is interpreted.Tom

Share this post


Link to post
Share on other sites

>>Using Bool Logic on general variables may give defined>>results, but is dangerous. Much better to use only real>>Bools for the variables. >>Agree also. However, as code errors are not easy to debug in>XML, sometimes an unpredicted result may appear. That's the>reason I think it's worth to know how the stack is>interpreted.>>Tom It might be good to display bools in a test gauge. I wrote some to general, FP strings so I saw 1.000 or 0.000. One could code the Bool display to indicate 'T', 'F', or '?', where "?" is displayed if not 1 or 0. Even if the "?" indication worked, one would do well to find why 1 or 0 were not in what are supposed to be bool variables. I suspect all 'numbers' are IEEE 64 bit values. And, that 'FCOMP' (NPX compare) is probably used on 'numbers', whether they are supposed to be float8, integer, or bool. Storing Bools (1 bit) in 64 bits is very inefficent, but the simplicity of making all such 'numbers' float8 on the stack makes it a reasonable approach. Futher, the NPX is as about as fast on float8 values as the CPU's ALU is on integers. I noted in one of the FS Blogs that the XML RPN stack will hold 30 values, including operators. I suspect that means 8*30 bytes, which is not much. I suspect '+' is encoded on the stack with the binary instruction for 'FADD', and null padded if necessary to bring it to 8 bytes. Nulls are seen as NOP as far as instructions go. The string values and string instructions may well be different. Generally, stings are composed of bytes, not quad words (8 bytes). Ron

Share this post


Link to post
Share on other sites

Sorry I forgot to answer this:> Except from not showing does>it still execute the code or does it skip the code all>together? only affects outputs to FS, ie Image, String, CustomDraws, Polys, etc.If the last stack entry before the is EXACTLY 0, those won't show; ANY other value and those will be visible.The rest of the code in the , ie inside , etc, will be executed no matter its condition; including var and/or events assignments; etc.Tom

Share this post


Link to post
Share on other sites

The SDK says there are stack operators s0...s49, l0...l49, and sp0...sp49.That suggests to me that there are stack would hold 50 values. I would have thought that would be enough. An expression would have to be very complicated to push 50 values on the stack without popping any. Having said that, I wait for someone to provide one!

Share this post


Link to post
Share on other sites

>The SDK says there are stack operators s0...s49, l0...l49, and>sp0...sp49.These are not stack operators but registers where stack values can be saved. Saving a value to a register (s0,s1...) doesn't remove it from the stack unless you use the "p" operator (sp0,sp1...)>That suggests to me that there are stack would hold 50>values.No, the limit is 30 stack values regardless of the operators.>An expression would have to be very complicated to push 50>values on the stack without popping any. Having said that, I>wait for someone to provide one! Not too complicated, just long!ie: a "case" operator with 27 values (very useful for reading tables)Tom

Share this post


Link to post
Share on other sites

>The SDK says there are stack operators s0...s49, l0...l49,>and sp0...sp49.>>That suggests to me that there are stack would hold 50 values. No, those are registers, not stack variables. Note my HP-15C had 20 general registers, 0 to 9, and .0 to .9. And, only four stack levels.>I would have thought that would be enough. An expression would>have to be very complicated to push 50 values on the stack>without popping any. Having said that, I wait for someone to>provide one! One of the MSFS bloggers experimented, and found the stack could hold up to 30 valuesoperators. He noted that the FS9 GPU used as many as 27. When I was learning 8087 coding I assumed loading variables on the stack simply pushed the top ones off. As in an HP RPN calculator. It was only after I got Code View that I saw loading one too many variables on the stack resulted in NAN's for later operations. So, I had to be careful not to load too many variables. I also used 'FINIT' before a block of NPX operations to be sure the stack was empty. 'c' clears the stack in XML RPN, and I put that at the start of every block. If one codes carefully, the stack should end up empty; but it's easy to leave some things on it. Ron

Share this post


Link to post
Share on other sites

>Sorry I forgot to answer this:>>> Except from not showing does>>it still execute the code or does it skip the code all>>together? >> only affects outputs to FS, ie Image, String,>CustomDraws, Polys, etc.>If the last stack entry before the is EXACTLY 0,>those won't show; ANY other value and those will be visible.>The rest of the code in the , ie inside , etc,>will be executed no matter its condition; including>var and/or events assignments; etc.>>TomThanks Tom. I thought... "Noboddy has a clue." Anyway I know now!I stirred up quite a thing with this question. Interesting stuff!Roelof

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this