Hi everyone!

in my current prizm add-in project I had to use Sine and Cosine. At first, I couldn't find them anywhere, because I had only installed the standard PrizmSDK v0.3. I scanned through the prizm wiki and found out that the libfxcg files included in v0.3 aren't up to date. I downloaded the latest ones from http://jenkins.taricorp.net/job/libfxcg/lastSuccessful/archive/ and pasted them into the lib and include folders of my SDK (On http://prizm.cemetech.net/index.php/Development_Methods_and_Tools it says it is as easy as that to update the libfxcg). I included the math.h file in my sourcecode, but the compiler still gives me these errors:

Code:
Lindenmayer.o: In function `_genLindString':
Lindenmayer.c:(.text+0x1c0): undefined reference to `_malloc'
Lindenmayer.o: In function `_genPArrFrLArr':
Lindenmayer.c:(.text+0x3ac): undefined reference to `_malloc'
Lindenmayer.c:(.text+0x3cc): undefined reference to `_sin'
Lindenmayer.c:(.text+0x3d8): undefined reference to `_cos'
collect2: ld returned 1 exit status
make[1]: *** [C:/Users/Simon/Bibliotheken/Dokumente/Programmierung/PrizmSDK-0.3/projects/Lindenmayer/Lindenmayer.bin] Error 1
make: *** [build] Error 2

(after i had "updated" the libfxcg, the "undefined reference to '_malloc'" errors appeared as well)
My code looks like this:

Code:
posX += (double) sin((double) (facing * PI / 180));
posY += (double) cos((double) (facing * PI / 180));

PI is a float I defined myself, posX and posY are normal floats.
I think I did the updating wrong, so how would I do it properly? Any help is appreciated!

PS: I'm using windows.
PPS: I'm pretty new to C, so I'm sorry if this is a dumb question.

Edit: I only pasted the math.h file into my lib folder and not the other headers from Tari's jenkins page, but I don't think this is a problem, is it?
There is no actual implementation provided for any of the math functions. Having declarations allows it to work in cases where the compiler can compute things at compile-time though (which isn't a guaranteed optimization..), so you'll probably want to use a lookup table of some fashion instead.
But why is there a math.h on the jenkins page which includes a sin(x) function, if it doesn't work in the end?
Tari wrote:
Having declarations allows it to work in cases where the compiler can compute things at compile-time
Oh ok I didn't understand that sentence.
I am pretty sure I needed the math functions for my Eigenmath port, and in fact, its Makefile has lm listed in the libraries: https://github.com/gbl08ma/eigenmath/blob/master/Makefile#L49

And I have a libm.a on the libraries folder of my development environment. I just don't know how it got there, it's been a long time since I looked at this...
Use Sun's math library: https://github.com/ComputerNerd/libfxcg/tree/Posix/libm
I remember using tan function somewhere probably when playing with battery life indicator I once wanted to implement but I stopped working on it. I do not recall problems with math.h functions - try searching through sources of existing add-ins to see what worked - I seem to recall working examples with this in archive
Sorry I didn't watch this thread anymore, thanks for all the answers. I solved the problem by coding my own sine and cosine functions using the corresponding taylor series. I will post the source code of the methods tomorrow.

Jamesbeans
These are the two methods I coded:

Code:
 //warning: only input values <= 2 * PI
float mysin(float x) {
   if(x > PI) { return -mysin(x - PI); }
   if(x > PI / 2) { return mysin(PI - x); }
   return x - ((x*x*x) / 6) + ((x*x*x*x*x) / 120) - ((x*x*x*x*x*x*x) / 5040);
}

float mycos(float x) {
   return mysin(x + (PI / 2));
}


At the moment, only input values < 2*PI give reasonable results, so I coded another method which reduces an angle to a value < 2*PI:

Code:
float redAng(float angle) {
   while(angle < 0) {
      angle += 2 * PI;
   }
   while(angle > 2 * PI) {
      angle -= 2 * PI;
   }
   return angle;
}


The accuracy is good, and thus my problem is solved.

Jamesbeans
I don't remember having problems when using trigonometry but I'm pretty sure I overwrote my examples of this when working on that particular project so just for testing I tried the following

Code:
   
double ff = 100.0 * sin(1);
int f = (int)ff;
char result[120];
itoa(f,(unsigned char*)result);
locate_OS(1,5);
Print_OS((const char*)result,0,0);

and it works as expected - I have not thought through how to display doubles or floats so just for testing did integer to string conversion of 100 times the sin result to check that it worked... For itoa if needed for your purposes you may need to include <fxcg/misc.h> in your header and obviously include <math.h> for math functions please - give it a try...

I know you considered your problem solved but it was just approximate solution and i'm even surprised that power function was substituted with multiplications... I just hope that if it is just windows specific tweak with the latest sdk for windows someone would be able to explain what may have gone wrong. Let us know how it goes - I hope we will be able to solve at least such problems on Windows here
I was also wondering if your setup is right:

my math.h is in include folder not lib folder
and in my lib folder I have various .a files like libfxcg.a libc.a libm.a etc

I also remember that makefile configuration can cause problems - look at my setjmp post in this forum - from memory makefile need to list libs in an order starting with libfxcg otherwise compiler complains similarly to what you posted here...

I hope this and setjmp post helps you and other users
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement