Author Topic: Why does Axe not recognise commands such as randInt( and R>Pr ?  (Read 4875 times)

0 Members and 1 Guest are viewing this topic.

Offline SamTebbs33

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Why does Axe not recognise commands such as randInt( and R>Pr ?
« on: January 11, 2014, 07:52:13 pm »
I recently made the switch from TI-Basic to Axe, but was very disappointed when I realised that I can't use some of my favourite commands such as fPart( (which I used to use all the time for data compression), iPart( and angle commands such as R>Pr.

Why is this and will they be useable in the future?

P.S Since the fPart and iPart commands can't be used, how would I go about getting the integer and decimal parts of numbers? This functionality is VERY important for the game I'm making.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Why does Axe not recognise commands such as randInt( and R>Pr ?
« Reply #1 on: January 11, 2014, 08:03:58 pm »
SamTebbs33, Axe doesn't use floats. It uses 16- and 8-bit integers, and has some 8.8 fixed point support.

Axe is a much lower level language then TI-BASIC, which means that it works closer to the processor level. You get to be more precise about what you want to happen allowing you to get much faster results than TI-BASIC. However, TI-BASIC has all of the coding for very complicated (and time consuming) mathematics.

Axe is a very different language from BASIC, so the BASIC tricks that you might want to use in Axe aren't very useful and likely inefficient.

What exactly are you trying to do? In Axe, there is probably a much better solution than one you might use in BASIC. It'll take some getting used to, but Axe is well worth learning :)

Also, welcome to Omnimaga! You should introduce yourself.

EDIT: Have you read the Readme that came with Axe? It describes these a little bit, as well as the idea of pointers and such-- you won't be able to use strings the way you would in BASIC, for example.

Also, to answer the question "will they be useable in the future" Runer112 has mentioned in the past that he wants to add a broader range of variable types to Axe, among them being floats. For now, you can use fixed point 8.8 numbers.

Integers are usually better if you can figure out a way to use them, but occasionally you actually need fixed-point for optimal coding. Internally, fixed-point numbers are stored times 256. So 1.5 is really 368. 256 is the first number that doesn't fit in an 8-bit (1 byte) range and dividing or multiplying by 256 is very easy (remember that in Axe, dividing by a number is like int(A/B) in BASIC).
Anyways, if you did 1.5*1.5, you can think of this mathematically as 368*368/(256*256) then multiplied again by 256 to convert it back to fixed point. At the assembly, you just multiply 368*368 and get rid of the lower byte of the result, keeping bits 8 to 23.

Offline SamTebbs33

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Re: Why does Axe not recognise commands such as randInt( and R>Pr ?
« Reply #2 on: January 11, 2014, 08:43:53 pm »
Thanks for the quick reply!

I see, I guess I'm just going to have to get some intense practice...

Have you heard of a game called Elite? Well I am making a remake of said game but due to the limitations of Ti-Basic I scrapped the idea of including 3D graphics. However, as soon as I saw demos of Axe (the spinning cube really got me) I decided to give it a shot. The reason why I need to get the fraction and inter parts of a number is for data compression, since I need to generate stats for 2048 worlds and store it somehow (to be an accurate remake of the 1984 original). In Ti-Basic I was compressing 4 numbers into one by using the following formula: A+(B/10)+(C+(D/10))i
This would compress the following numbers: 12, 8, 23, 3 into 12.8+23.3i which allowed me to store masses of data.

Thank you for the explanation, but I am a little confused by your last paragraph, could you please recap how I would retrieve the integer and decimal parts of e.g. 20/8?

Thanks!

Offline ClrDraw

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 627
  • Rating: +61/-2
    • View Profile
    • GitHub
Re: Why does Axe not recognise commands such as randInt( and R>Pr ?
« Reply #3 on: January 11, 2014, 08:49:39 pm »
Quote
Integers are usually better if you can figure out a way to use them, but occasionally you actually need fixed-point for optimal coding. Internally, fixed-point numbers are stored times 256. So 1.5 is really 368. 256 is the first number that doesn't fit in an 8-bit (1 byte) range and dividing or multiplying by 256 is very easy (remember that in Axe, dividing by a number is like int(A/B) in BASIC).
Anyways, if you did 1.5*1.5, you can think of this mathematically as 368*368/(256*256) then multiplied again by 256 to convert it back to fixed point. At the assembly, you just multiply 368*368 and get rid of the lower byte of the result, keeping bits 8 to 23.
I've used Axe for a while and I never knew that... Thanks!

Quote
However, as soon as I saw demos of Axe (the spinning cube really got me) I decided to give it a shot.
Have you seen what Matrefeytontias is up to?
http://www.ticalc.org/archives/files/fileinfo/457/45784.html
« Last Edit: January 11, 2014, 08:49:57 pm by ClrDraw »
Visit my GitHub for all my TI programs as well as other projects.
Also check out my website.

Offline SamTebbs33

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Re: Why does Axe not recognise commands such as randInt( and R>Pr ?
« Reply #4 on: January 11, 2014, 08:59:29 pm »
Have you seen what Matrefeytontias is up to?
http://www.ticalc.org/archives/files/fileinfo/457/45784.html

Wow, that's some nice face culling

P.S. At the top of the CUBE source code, some hex values are enclosed in square brackets but not passed to any variables, what does this do?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Why does Axe not recognise commands such as randInt( and R>Pr ?
« Reply #5 on: January 11, 2014, 09:14:07 pm »
Your BASIC solution to storing data isn't as good as you might think, unfortunately. Internally, a Real number is stored as 9 bytes, a complex number is stored as 18 bytes. All four of those numbers could be stored as 1 byte each in Axe, and you can store them as an array of data.

Now to get the integer and decimal part of 20/8, for example, note that there are no such things as fractional numbers to the processor. The processor only works with integers 0 to 255 (or 0 to 65535 in some cases). TI-BASIC works with this just by representing and working with these integers in specific ways to pretend it is using floats. In Axe, since I am assuming you don't have assembly experience or similar experience with low-level language, this would be very difficult to simulate.

To give you an idea, the OS stores the number "pi" as the sequence of 1-byte integers:
{0,128,49,65,89,38,83,88,152}

That probably makes no sense and it will probably just confuse you more to work out the details of it.

My point is, I think you want to think of things in terms of decimals, but they don't exist on the calculator unless you make them. You make them just by handling your data differently. For example, 20/8 is 2. 21/8 is 2. 22/8 is 2.

I know how to get the fractional part, but my worry is that you are going to cling to this and that will make it a lot harder for you to learn Axe. Also, the explanation would require lots of math.
Spoiler For How To Do It:
/8 is actually really easy in Axe. Remember that 20/8=2. However, if you use fixed point division (use /*), 20/*8 will return 840. This might seem illogical, but you will notice that 840/256=2.5 = 20.0/8.0. Axe is not the only language that uses integers unless you tell it specifically not to. C, C++, Python, MatLab, Sage, Mathematica-- all expect integer operations unless you tell it specifically not to. Now, if you try to do 20/*7 on the other hand, you get 731, and 731/256 is not exactly 20.0/7.0. This is due to precision errors because we have only a finite amount of memory to work with and in this case, that precision ends at 8 bits. The calculator has 14 decimal digits of precision, many standard computer routines have 24 bits, 53 bits, or 64 bits of precision (approximately 7,16, and 19 decimal digits). The 24-bit one has been the standard for decades. The Z80 processor is an 8-bit processor, so it is much slower to work with anything larger than 8 or 16 bits.

What I think will be more beneficial is if you learn how pointers work. You also will benefit from knowing how memory reading/writing works. Remember, TI-BASIC uses 9 bytes for their floats. Axe uses 2 bytes for integers/pointers (all variables in Axe are pointers). You can also store arrays in Axe and reading/writing to and from arrays works with one byte a t a time. This means that if you can represent your data with integers 0 to 255, you can use a single byte instead of 9 or 18.

As some things you should try:
Code: [Select]
.TEST
"HELLO WORLD!→Str1
Text(0,0,Str1
Str1 does not contain a string. Str1 is a 16-bit integer that poitn to the spot in RAM that the string is located at. Try this:
Code: [Select]
.TEST
"HELLO WORLD!→Str1
Text(0,0,Str1+1
You should see "ELLO WORLD" displayed because Str1+1 points to the "E" in the string instead of the "H".

Also be sure to look at the command index. Read through it. Get some ideas of what you can do with certain commands, like the Data() command or []. You should have a copy of it with Axe, but there is also a convenient copy here.

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Why does Axe not recognise commands such as randInt( and R>Pr ?
« Reply #6 on: January 11, 2014, 09:19:29 pm »
And randInt(A,B) would be rand^(B-A)+A in Axe.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline SamTebbs33

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Re: Why does Axe not recognise commands such as randInt( and R>Pr ?
« Reply #7 on: January 11, 2014, 09:29:40 pm »
Thanks for the explanation, I think I need to investigate the assembly number system a bit more. The only real knowledge of binary that I have is bitwise operations and the basics (so I was very excited when I saw that the " and " et.c commands are bitwise operations in Axe :D, I had to write my own in TI-Basic).

Regarding my choice of data compression, I originally used that method to 'bypass' the dimension max of lists in Ti-Basic, it meant that I could store multiple numbers in just one list element. But I do understand that it uses large amounts of memory due to the decimals and imaginary numbers.

I'll put aside my games programming and just go back to basics to ensure that I understand the system fully (such as the r command et.c)

One last question for the moment, how would I recall the data that I stored to the memory by using [<hex code>]? Would I use a GDB pointer?

And randInt(A,B) would be rand^(B-A)+A in Axe.

Thanks! I'll keep that in mind.
« Last Edit: January 11, 2014, 09:36:45 pm by SamTebbs33 »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Why does Axe not recognise commands such as randInt( and R>Pr ?
« Reply #8 on: January 12, 2014, 02:47:58 am »
P.S. At the top of the CUBE source code, some hex values are enclosed in square brackets but not passed to any variables, what does this do?
Wait wait wait. I think you got it now, but Axe is not Basic. I just say it again to be sure.
Now, you must be talking about things like that:
[0244621867152648]→Pic0
[2456781569324587]
[1554236578955456]


So, first of all, Pic0 is not a variable, it is a pointer. So {Pic0} is the value pointed by Pic0, which is $02=2. And {Pic0+1}=$44=68. Etc. And Pic0+8=$24, which is the number that follows the last number before the"→Pic0", and Pic0+9=$56.

Basically, you can write what I wrote like that:
[0244621867152648 2456781569324587 1554236578955456]→Pic0

Or like that:
[]→Pic0
[0244621867152648]
[2456781569324587]
[1554236578955456]


Or like that:
Data(2)→Pic0
[44621867152648]
Data(E24,E56)[781569324587 1554236578955456]

All those ways to write it are equivalent when compiled. It is just more understandable to you if you are for example "declaring" a bunch of sprites to put them one beneath each other.

tl;dr: Pointers=/=Variables
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline ClrDraw

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 627
  • Rating: +61/-2
    • View Profile
    • GitHub
Re: Why does Axe not recognise commands such as randInt( and R>Pr ?
« Reply #9 on: January 12, 2014, 10:44:52 am »
Here is a list of commands that Axe does recognize:
http://axe.eeems.ca/Commands.html#systemCommands
Visit my GitHub for all my TI programs as well as other projects.
Also check out my website.