Jump to content

Recommended Posts

Tom, just had a thought. Can your micro approach be modified to extract more the one digit? For example, extract 345 from 1234567.cheers,nick

Share this post


Link to post
Share on other sites

>Tom, just had a thought. Can your micro approach be modified>to extract more the one digit? For example, extract 345 from>1234567.>cheers,>nick>Tom, just had a thought. Can your micro approach be modified>to extract more the one digit? For example, extract 345 from>1234567.>cheers,>nickNickSimple as well :) with a few changespseudocode:"extract from N value, n number of digits, starting at digit n right most, including n number of decimals"Macro (raw):@1 sp0@4 0 > if{ l0 10 @4 pow * sp0 }l0 int 10 @3 pow % 10 @3 1 - @2 1 - - 0 max pow / intcalling:@ExtDig2((LVar),nCant,nStartDigit,nDecimals)Examples:for a value of 12345678.4567@ExtDig2(lVar,3,4,0) returns 567@ExtDig2(lVar,3,1,0) returns 8@ExtDig2(lVar,5,5,2) returns 67845 ; 100 / will give 678.45etc etcNOW, @ExtDig2(lVar,5,5,3) returns an erroneous value, the concept is the integer used for intermediate conversions must not exceed 10 digits; in this case that would be 12345678456 (11 digits)BUT for 12345.1234 --> @ExtDig2(lVar,5,5,3) will return 45123 ok.Hope all this was understandable and not a messy group of lines! :)Regards,TomEDIT: If you don't want to consider the decimals,@ExtDig2((LVar),nCant,nStartDigit) will work ok too.

Share this post


Link to post
Share on other sites

Hi Guys,I've been away in this forum for a little while, due to other pressing interests :-)I haven't read all the replies, but can someone explain to me how Nick's simple question about the Modulo function can lead to a thread with allready more then 33 (now: 34) replies ???:-) :-) :-) Glad to be back :-)Cheers, Rob

Share this post


Link to post
Share on other sites
Guest Ron Freimuth

>Many thanks Tom, will take a good look at this,>(now 35 replies)>nick:-) I see there is also 'div', which is an integer divide. It gives the integer of the division, "16 3 div" should put 5 on the stack. Modulo, "%", is also good for generating pseudo random numbers. It was said here there is no way to generate a Rand in FS XML. I wrote a Rand Macro in two lines. Might be useful for dithering gauge readings, etc. to add a small variation. However, to end this thread, any request for the Rand macro should be in a new thread. Ron

Share this post


Link to post
Share on other sites

Hi Tom, are you there?Ref,@1 sp0@4 0 > if{ l0 10 @4 pow * sp0 }l0 int 10 @3 pow % 10 @3 1 - @2 1 - - 0 max pow / intwould you be kind enough to explain the significance of the @ character, that is, what does @1, @4, etc. achieve?Also, what does 'pow' do.I also see in the sdk table,lg, neg (negative ? but how used), eps. Can you possibly explain these as well.I have used the macro in,@AltDigit((A:Indicated Altitude,feet) 100000 + 100000 % s0,2,0) 9 == if{ @AltDigit(l0,3,0) @AltDigit(l0,1,0) 10 / + } els{ @AltDigit(l0,3,0) }which scrolls a rolling number to the next value while the preceding rolling number rolls from 9 to zero. Is it possible to build into the macro(A:Indicated Altitude,feet)? I know this process can be achieved with modulus, but this is a simple way to understand the application.Ron, your random code would be relevant here as an example, Please share.much appreciated,nick

Share this post


Link to post
Share on other sites

Hi Nick,>>@1 sp0>@4 0 > >if{ l0 10 @4 pow * sp0 }>l0 int 10 @3 pow % 10 @3 1 - @2 1 - - 0 max pow / int>>would you be kind enough to explain the significance of the @>character, that is, what does @1, @4, etc. achieve?Sure :-)The @ character symbolizes a paramater passed to a macro, and the number to the right is the order in the sequence of the total parameters passed, each of them separated by comma.For example @1 2 * @2 + @3 +Then, calling @Macro1(10,20,30) will pass 10 to @1, 20 to @2 and 30 to @3.Now, what kind of values can receive a parameter "@" ?1) literal stack values : @Macro1(10)2) A,L,G var values : @Macro1((A:Indicated Altitude, feet)) 3) Register values : @Macro1(l0,l1,l2)4) Part of var names : @Macro1(A:Indicated Altitude) or @Macro1(feet)5) Macro names : @Macro1(@NestedMacro)6) Resultant stack values : @Macro1(5 2 *,4 3 +) will pass 10 and 77) "Popped" stack values : 20 @Macro1(10) will pass 10 to @1 AND 20 to @2 if that exists in the called This is an essential description, hope it was clear enough>Also, what does 'pow' do.>I also see in the sdk table,>lg, neg (negative ? but how used), eps. Can you possibly>explain these as well."pow" raises a number to an exponent, the same as "^"Ie 10 2 pow = 100 10 3 pow = 1000"lg" is the logarithm base 10 of a numberie10 lg = 120 lg = 1.30103 "neg" is the same as "/-/"ie 5 neg = -5 -5 neg = 5I don't know what is "eps", sorry.>@AltDigit((A:Indicated Altitude,feet) 100000 +>100000 % s0,2,0) 9 == if{ @AltDigit(l0,3,0) @AltDigit(l0,1,0)>10 / + } els{ @AltDigit(l0,3,0) }>>which scrolls a rolling number to the next value while the>preceding rolling number rolls from 9 to zero. Is it possible>to build into the macro(A:Indicated Altitude,feet)? I know>this process can be achieved with modulus, but this is a>simple way to understand the application.I'm not sure what you mean here, maybe what you want is to fix the Avar directly inside the @AltDigit macro?Tom

Share this post


Link to post
Share on other sites

>I'm not sure what you mean here, maybe what you want is to fix the Avar directly inside the @AltDigit macro?Yes, absolutely correct. I'm using the macro several times to control the movement of the rolling numbers in an altitude gauge. So I'd like to place the A:Variable into the macro to save repeating it in the code lines that move the rolling number strips.Also, you say "lg" is the logarithm base 10 of a number. I see in the SDK, 'log' and 'ln'. Now 'ln' would be natual log to the base e. Would 'log' and 'lg' be the same thing? Also would 'exp' and 'pow' be the same?Cheers Tom, and thanks for the education,nick

Share this post


Link to post
Share on other sites

>Also, you say "lg" is the logarithm base 10 of a number. I see in >the SDK, 'log' and 'ln'. Now 'ln' would be natual log to the base >e. Would 'log' and 'lg' be the same thing? Also would 'exp' >and 'pow' be the same?"Log" needs an exponent ie:"20 10 log" is the same as "20 lg" = 1.301etc"exp" raises a number to the e exponent (is NOT the same as POW)ie 1 exp = 2.7182 exp = 7.389>So I'd like to place the A:Variable into the macro to save >repeating it in the code lines that move the rolling number strips.Hold on and I'll try to give an example here.Tom

Share this post


Link to post
Share on other sites

>So I'd like to place the A:Variable into the macro to save >repeating it in the code lines that move the rolling number strips.This is an example of the rolling numbers in my altimeter (757)http://forums.avsim.net/user_files/135822.jpgAnd the code is : (A:Indicated Altitude, feet) sp0 l0 int 10 @2 pow % 10 @2 1 - @1 1 - - 0 max pow / int/Macro>For the tenths thousands: @AltDigit(4,4) s1 9980 >= l1 100 % 80 - 20 / * @AltDigit(1,5) +etc..For the thousands:@AltDigit(3,3) s1 980 >=l1 100 % 80 - 20 / * @AltDigit(1,4) +For the hundreds:@AltDigit(2,2) s1 80 >=l1 80 - 20 / * @AltDigit(1,3) +And the tenths, "standard" code :-)(A:Indicated Altitude, feet) abs 100 % 10 / Notes:Each digit starts to roll at 80 % of the reference value; I gues this should be similar in most commercial altimeters. Also rolling occurs from top to bottom ie your bmp needs to have this layout:0987etc. Most altimeters I've seen (even on payware addons) roll the wrong way.Tom

Share this post


Link to post
Share on other sites

Many thanks Tom for taking the time to explain all this. Much appreciated. This info is now tucked away in my XML reference folder.I'm pleased to say that my numbers roll the correct way:-) cheers and thanks for everything,nick

Share this post


Link to post
Share on other sites

Hi all,If 123 10 % strips out the 3 and places it on top of the stack, what number is pushed down the stack?I'm thinking it is either 123 or 120. I need to know that if I use r to reverse the stack some time after 123 10 %, will I get 123 or 120.cheers,nick

Share this post


Link to post
Share on other sites

That question has already been answered in this thread.

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  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...