Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
19 May, 2013, 09:21:52 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: Inverse Cosine of an 8.8 number -  (Read 538 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
LincolnB
Check It Out Now
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: 20 February, 2013, 05:44:25
Date Registered: 02 May, 2011, 00:56:28
Location: Utah Valley
Posts: 1114


Topic starter
Total Post Ratings: +121

View Profile
« on: 22 February, 2012, 00:09:38 »
0

Two questions: What is the format for an 8.8 number in Axe, and can you take the inverse cosine of an 8.8 number?
Logged

Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler for Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)


geekygenius
LV1 Newcomer (Next: 20)
*
Offline Offline

Last Login: 01 July, 2012, 08:42:32
Date Registered: 08 March, 2012, 08:06:48
Posts: 17

Total Post Ratings: +4

View Profile
« Reply #1 on: 19 March, 2012, 03:12:25 »
0

I don't know much about floating point numbers in axe, but maybe try going back to the unit circle.
Logged
Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 07:47:41
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5642


Total Post Ratings: +589

View Profile
« Reply #2 on: 19 March, 2012, 03:22:53 »
0

You might want to look into the taylor expansion of inverse-cosine


But out of curiosity, and with the potential to solve this issue with vectors, what do you need inverse cosine for?
Logged

Quigibo
The Executioner
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: Yesterday at 00:55:01
Date Registered: 22 January, 2010, 05:02:37
Location: Los Angeles
Posts: 2022


Total Post Ratings: +1019

View Profile
« Reply #3 on: 19 March, 2012, 05:00:02 »
+1

To answer the question of doing arbitrarily complicated "advanced" math in Axe (A system which does not support many math functions) is to approximate using more simple functions.  This is in fact what Axe does natively for sin, cos, arctan, etc.  I will demonstrate how I would approach this problem, the same way I did those other functions.  Hopefully this will be helpful to everyone.  Take a look at how arccos looks:



First things first, since we are using 8.8 and brads (binary radians) the same picture should range from -256 to 256 left to right, and 256 to 0 up to down.

Next, does the shape look like anything simple that you're familiar with?  What if we split it into 2 mirror images at the center?  Yes!  The left and right halves look like rotated and/or flipped square root functions, close enough!



So what are the functions for left and right?  Lets do the right side first.  By the shape, we know its going to take the form of sqrt(-x).  But its shifted to the right by 256 so sqrt(256-x) and also we want it to go through point (0,128) and so when x=0, sqrt(256-x) should be 128, but its actually just 16.  So multiply by 8 and finally you get y = 8*sqrt(256-x) for the right half.  Follow a similar process for the left and you get: y = 256 - 8*sqrt(256+x)

One cool thing to notice is that in fixed point, all math is modulo 256 and so 256.0 is actually the same as 0.0 so these equations strangely optimize to a case where it looks like we're taking the square root of a negative number all the time, but that's just modular arithmetic for you!  This also forces us to add an extra special case.


1
2
3
y = 8.0*sqrt(-x) when x>0
y = -8.0*sqrt(x) when x<0
y = 128.0 when x=0

So now the code should be easy and straightforward.  Here is an unoptimized version for readability:


1
2
3
4
5
6
7
8
9
:Lbl acos
:If r1=0.0
:  Return 128.0
:ElseIf r1<<0.0
:  Return -√(r1)r*8.0
:Else
:  Return √(-r1)r*8.0
:End

This is all untested, but I believe it should work  Smiley
« Last Edit: 19 March, 2012, 05:04:20 by Quigibo » Logged

___Axe_Parser___
Today the calculator, tomorrow the world!
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.257 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.