Author Topic: Math  (Read 6766 times)

0 Members and 1 Guest are viewing this topic.

SirCmpwn

  • Guest
Math
« on: September 17, 2010, 08:47:21 pm »
Hello,
How do you do fixed point math in Axe?  For instance, 2.5 * 2.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Math
« Reply #1 on: September 17, 2010, 08:55:00 pm »
E0280**E0200 computes your example and returns E0500
In short, it treats the hex number AABB like AA.BB (note the hexadecimal point)
You have to use ** instead of *, but you can still use + and - (and >>, <<, >=>=, and <=<=)
I'm not sure about division.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Math
« Reply #2 on: September 17, 2010, 09:03:34 pm »




SirCmpwn

  • Guest
Re: Math
« Reply #3 on: September 17, 2010, 10:38:43 pm »
Ah, got it.  Thanks!
If anyone can shed light on division, I would appreciate it.  3D projection, anyone? ;)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Math
« Reply #4 on: September 17, 2010, 10:56:13 pm »
Mhmm... planning a new project? ;D

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Math
« Reply #5 on: September 17, 2010, 11:43:47 pm »
* Deep Thought wonders what this could be...

And about division, what about multiplying by a reciprocal? It might work sometimes.




_player1537

  • Guest
Re: Math
« Reply #6 on: September 18, 2010, 01:43:15 am »
Yay SIr!  You're working on this now!  Can't wait to play with it :D  I hope you keep it easy to use with other programs.  (all that assuming this is the program you showed me a long time ago :D)

Edit: http://ourl.ca/4772 :)
« Last Edit: September 18, 2010, 01:53:36 am by _player1537 »

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Math
« Reply #7 on: September 18, 2010, 01:59:34 am »
To find the reciprocal of a signed fixed point number "A", do this:


E8000//A*2*-1


Once you have the reciprocal, you can do a regular fixed point multiplication to do the actual "division".  One bit of accuracy is lost though when using this method.  I am thinking of having an inverse function built in for fixed point since I'm not using that token yet.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Math
« Reply #8 on: September 18, 2010, 02:07:59 am »
Oh wow I remember that project. It was great. I hope you can convert it to Axe

SirCmpwn

  • Guest
Re: Math
« Reply #9 on: September 18, 2010, 09:09:38 am »
Yeah, I've been meaning to try ever since fixed point support.
Quigibo, I don't quite understand, how would I divide 5/2 with this example of yours?
Also, how would I convert the result of a sine or cosine to a fixed point number?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Math
« Reply #10 on: September 18, 2010, 11:15:12 am »
Yeah, I've been meaning to try ever since fixed point support.
Quigibo, I don't quite understand, how would I divide 5/2 with this example of yours?
Also, how would I convert the result of a sine or cosine to a fixed point number?
Actually, if you are multiplying or dividing by an integer, you can simplify (and sometimes optimize) by doing it normally. 5/2 would be e0500//2.
Sine and cosine return a value from -128 to 128 (representing -1 to 1). In 8.8 fixed point, -256 is -1 and 256 is 1. So, you would have to multiply the sin/cos value by 2.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

SirCmpwn

  • Guest
Re: Math
« Reply #11 on: September 18, 2010, 01:30:31 pm »
So, I could say sin(42)*2->A and A would contain the fixed point value of the sine of 42?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Math
« Reply #12 on: September 18, 2010, 01:53:11 pm »
So, I could say sin(42)*2->A and A would contain the fixed point value of the sine of 42?
That is correct.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Math
« Reply #13 on: September 18, 2010, 04:01:02 pm »
By the way, if you're trying to model a 3D engine, you can check the source code of the CUBE.8xp example program.  It takes a list of lines defined by 2 points and draws them all to the screen.  In the cube's case, there were 12 lines representing the edges of the cube.  I don't even think I used fixed point operations in that one since they aren't absolutely necessary, you'll have to see what optimizes better.
« Last Edit: September 18, 2010, 04:01:56 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

SirCmpwn

  • Guest
Re: Math
« Reply #14 on: September 18, 2010, 06:07:49 pm »
Okay.  Fixed point for perspective 3D is pretty important.