Sine/Cosine as Fixed Point Math

Post Reply
Foxi4
Posts: 14
Joined: Wed Feb 22, 2012 10:49 pm

Sine/Cosine as Fixed Point Math

Post by Foxi4 » Wed Feb 22, 2012 10:49 pm

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. :)

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Sine/Cosine as Fixed Point Math

Post by elhobbs » Thu Feb 23, 2012 7:48 pm

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

Code: Select all

LIBS    :=      -lnds9
to:

Code: Select all

LIBS    :=      -lnds9 -lm
If you are calling sin/cos a few times per frame it is not going to hurt anything.

User avatar
vuurrobin
Posts: 219
Joined: Fri Jul 11, 2008 8:49 pm
Location: The Netherlands
Contact:

Re: Sine/Cosine as Fixed Point Math

Post by vuurrobin » Thu Feb 23, 2012 10:53 pm

also, libnds has fixed point sin/cos functions that you can use.

http://libnds.devkitpro.org/a00150.html

Foxi4
Posts: 14
Joined: Wed Feb 22, 2012 10:49 pm

Re: Sine/Cosine as Fixed Point Math

Post by Foxi4 » Tue Mar 06, 2012 12:19 am

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. :)

WinterMute
Site Admin
Posts: 1856
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Sine/Cosine as Fixed Point Math

Post by WinterMute » Tue Mar 06, 2012 12:32 pm

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

Personal Blog

Foxi4
Posts: 14
Joined: Wed Feb 22, 2012 10:49 pm

Re: Sine/Cosine as Fixed Point Math

Post by Foxi4 » Tue Mar 06, 2012 8:10 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests