Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: Omar Chehab on December 02, 2013, 01:51:23 pm
-
I recently started using Axe for my TI programming. I read the manual and the commands files and still could not get an answer. Upon compiling my program, it gives an error saying invalid token.
The error is at ":8*(randInt(1,8)+2)→A" and I am guessing that the line after that too is wrong. In TI basic randInt( generates a number between a range though in axe it is not accepting randInt( as a command. So my question is:
What can I use to replace or fix randInt( as I want to generate a random number in a given range.
* * *
:8*(randInt(1,8)+2)→A
:8*(randInt(1,4)+2)→B→C
-
First of all, I believe you can optimise the randInts a little bit, seeing as you can just change the paramaters.
Besides that, →B→C doesn't work, from what I remember, since storing things isn't nestable.
Changing it so that it might work, though, we'd end up with this:
:8*randInt(3,10)→A
:8*randInt(3,6)→B:Ans→C
Of course, my own basic skills being rusty, to say the least, there's probably ways to make this even smaller ;)
-
Even after fixing what you told me the error still occurs, so I am certain that the error invalid token is caused by the randInt( command.
-
nesting stores does work in axe, but I don't think the randint does. Instaed of doing randInt(1,8)+2, you can do rand^8+3. rand in axe generates a random 16-bit number, ^ calculates the remainder of a division by 8 which makes in the range of 0-7 (it doesn't mean power in axe!), and the +3 adds 3 to it to give you the correct range.
-
Thank you for the quick reply. Your answer was very informative it fixed my error, though can you please explain what the ^ is if it's not power?
-
It's the modulus operator. This is basically a divide, but instead of the quitient of the division, it returns the remainder. Usually, programming languages use the per cent sign (%) for this, but as it's quite hard to get on an 83+ line calculator, axe uses the ^ instead.
-
And by the way very few languages have a power operator (Python has ** but most languages have a pow(number, power) function in the advanced math library).
-
Don't know why noone said that already : Axe doesn't have a randInt( routine. If you want randInt(X,Y), do rand^(Y-X)+X instead.
-
You are missing a +1 in the Y-X, otherwise, randInt(0,1) would be rand^1+0 which always returns 0 ;)
Also, while yours gives the general solution, the particular solution was given in ben_g's first post.
-
It can be annoying getting used to the little things Axe does funny but stay with it and it will get way easier. The only thing that still bugs the crap out of me is the lack of negative numbers... :w00t:
-
Thank you, all!
-
It can be annoying getting used to the little things Axe does funny but stay with it and it will get way easier. The only thing that still bugs the crap out of me is the lack of negative numbers... :w00t:
err.. negative number in axe does exist, they just a little different that we expect. As we work with 2 bytes number, negative number start from the highest value possible, and then progressively decrease (well, idk if I am very clear) : some code :
-1->B //this is a correct syntax
//now B=65535
Disp B>Dec,i
//and you can do :
B*8->B
Disp B>Dec,i
//B still negative !
//B=65528 (-8)
B*-1->B //we now get a positive number
Disp B>Dec,i //B=8
in fact on two bytes we can code number from -32767 to 32768 using this method (who is implement in axe)
You may find that if the multiplication is signed, the division (/) is not. However it exist a signed division (it's the // symbol)
-
True I should have cleared up. I meant how confusing it can be using negative numbers. Especially how with regular variables, -1 is 65535 but with variables in L1 its 255... I had to mess with all that in my game blox (http://ourl.ca/20214).
But thank you I didn't know the division thing :)
-
it's pretty strange then :o cause if you use variable in L1 you have exactly the same thing than with a normal var (it's just a memory location in all case). Can I see some problematic code please ?
-
With one byte values in memory you have to use signed{} to convert 8 bit and 16 bit signed numbers. Actually the way signed numbers work in Axe and ASM is called two's complement which is a particular way to code negative numbers and have them usable exactly like positive ones with the same operations (due to the way modular math works). I hope I make sense. If not, look it up on Wikipedia. ;)
-
For your "variables in L1", just store them in two bytes instead of one (using r) and you'll get the exact same results than with "regular variables" and with custom variables.
-
it's pretty strange then :o cause if you use variable in L1 you have exactly the same thing than with a normal var (it's just a memory location in all case). Can I see some problematic code please ?
It's untested, but this is the idea.
:Fill(L1,20,0)
:{L1}--
:Disp {L1}>Dec
:0->A
:A--
:Disp A>Dec
With one byte values in memory you have to use signed{} to convert 8 bit and 16 bit signed numbers.
Cool, I'm looking that up now.
For your "variables in L1", just store them in two bytes instead of one (using r) and you'll get the exact same results than with "regular variables" and with custom variables.
I didn't use ^r though.
-
that understandable then, cause your reading and writing an one byte variable. With signed{ or the use of two bytes number, evrything work fine :)