View unanswered posts | View active topics It is currently Wed Jan 16, 2019 11:29 am

Reply to topic  [ 6 posts ] 
 Sine/Cosine as Fixed Point Math 
Author Message

Joined: Wed Feb 22, 2012 10:49 pm
Posts: 14
The subject of the thread sort of exhausts the question - I'm trying to implement sin/cos calculation in my project and seeing that the DS *hates* floats, standard cos(angle) sin(angle) functions from math.h are out of question.

Besides, for some odd reason, Visual C++ Express 2008 rejects the function whenever I'm trying to pass an argument into it (error 'cos' undeclared) while it works perfectly fine if I simply input a number and I don't have a devkitPro template for the 2010 Edition which apparently fixed this issue (I already googled it, it was a re-occouring thing).

So, I came to the conclusion that I can go in either of ways - I can create an array of possible values for Sin/Cos *or* I can create a custom function that will count Sin/Cos according to Fixed Point Arithmetic in real-time.

What's your take on the issue? How would you approach it?

Thanks in advance for any tips. :)

Wed Feb 22, 2012 10:49 pm

Joined: Thu Jul 02, 2009 1:19 pm
Posts: 352
floats are only a problem on the ds if you are using them in high use areas - for instance floating point software 3d texture mapping probably is not going to perform well. If you are using floats sparingly then they are not a problem.

Not sure what you mean by "Visual C++ Express 2008 rejects the function" - are you talking about Intellisense? That does not really matter so much as gcc is actually doing the compiling not visual studio - it just means you do not have intellisense paths/settings setup correctly for your project. if you are getting a linker error then make sure you add libm to your library list in your makefile. change
LIBS    :=      -lnds9

LIBS    :=      -lnds9 -lm

If you are calling sin/cos a few times per frame it is not going to hurt anything.

Thu Feb 23, 2012 7:48 pm
User avatar

Joined: Fri Jul 11, 2008 8:49 pm
Posts: 222
Location: The Netherlands
also, libnds has fixed point sin/cos functions that you can use.

my blog:

Thu Feb 23, 2012 10:53 pm
Profile WWW

Joined: Wed Feb 22, 2012 10:49 pm
Posts: 14
What I meant by "rejects" is that when I include the Math.h file and use the standard cos(); function with a value, such as cos(123); it compiles perfectly fine and the resulting build calculates the value, however when I pass an argument, such as cos(AVariable); the compiler informs me that "cos" is an undeclared function, which is a load of croak. This happens regardless of what type AVariable is - I tried double, I tried float, same result. I checked it online and it appears to be a problem that "sometimes" occours in 2008's edition and Microsoft's only patch for it is "Install the 2010 Edition", so yeah.

However, as mentioned in the post directly above, I already switched to the built-in functions and they're working just fine. :)

Tue Mar 06, 2012 12:19 am
Site Admin

Joined: Tue Aug 09, 2005 3:21 am
Posts: 1314
Location: UK
I'm not really sure how MSVS 2008 can affect devkitARM like this, what were you trying to compile? A snippet of code would be useful.

Help keep devkitPro toolchains free, Donate today

devkitPro IRC support
Personal Blog

Tue Mar 06, 2012 12:32 pm
Profile ICQ WWW

Joined: Wed Feb 22, 2012 10:49 pm
Posts: 14
I'm 100% certain that this is not an issue with devkitPro - it's an issue with 2008 Express. I tried compiling literally the same code for Windows Console and the DS (of course with DS-specific functions in the DS version) with the same result, and a best code snippet I could give to you is simply "just the includes and main" with "just cos(angle);" because even cutting it down to literally just this causes an error. ;)

Not to worry though, I'm using the Fixed Point functions now and it's working just dandy.

Tue Mar 06, 2012 8:10 pm
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
  Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.
Get devkitPro at Fast, secure and Free Open Source software downloads