Page 1 of 1

Math library

Posted: Thu Aug 14, 2008 9:47 pm
by kyrio
Hi all,

I'm trying to make some float/double operations and later some cos()/sin() calls. I'm working on a CPC with all ROMs disabled, so no firmware call can be made. I guess i have to use the gen_math library but can't manage to make it work (linking errors?, see below), even with this simple piece of code :

Code: Select all

#pragma -zorg=16384
#include "math.h"
double y;
void main() {
   y = 13.2;
   while(1);
}
I'm compiling with the following commands :
zcc.exe" +cpc -lcpcfs -lgen_math -create-app -o3 -o out.bin main.c
zcc.exe" +cpc -lcpcfs -lmz -create-app -o3 -o out.bin main.c
zcc.exe" +cpc -lcpcfs -lm -create-app -o3 -o out.bin main.c

But the best i get are those error traces :
File 'D:\Dev\ade\ade_ws\..\z88dk\lib\clibs\gen_math.lib', Module 'INIT_FLOATPACK', Symbol not defined
Error in expression DEG

File 'D:\Dev\ade\ade_ws\..\z88dk\lib\clibs\gen_math.lib', Module 'INIT_FLOATPACK', Symbol not defined
Error in expression PI

File 'D:\Dev\ade\ade_ws\..\z88dk\lib\clibs\gen_math.lib', Module 'INIT_FLOATPACK', Symbol not defined
Error in expression POW10

File 'D:\Dev\ade\ade_ws\..\z88dk\lib\clibs\gen_math.lib', Module 'INIT_FLOATPACK', Symbol not defined
Error in expression RAD

File 'D:\Dev\ade\ade_ws\..\z88dk\lib\clibs\gen_math.lib', Module 'INIT_FLOATPACK', Symbol not defined
Error in expression ATANC+1

File 'D:\Dev\ade\ade_ws\..\z88dk\lib\clibs\gen_math.lib', Module 'INIT_FLOATPACK', Symbol not defined
Error in expression COSC+1
And a lot more...

I'm nearly sure it's only a problem of zcc library argument but i tried a lot of combination with no positive result. So, help or hints will be appreciated.

Thanks,

Laurent "Kyrio" K.

Posted: Thu Aug 14, 2008 10:09 pm
by dom
Looks like I didn't think that anyone would want to use generic maths on the cpc! - The startup always tries to initialise the CPC math library.

As a temporary fix comment out the call init_floatpack in lib/cpc_crt0.asm

Posted: Fri Aug 15, 2008 6:17 pm
by kyrio
What a fast answer!

Many tanks for it, i can go further now.

I've spent a lot of time with this other problem :

Code: Select all

#include "float.h"
double a, a1, a2, a3;

void main() {
  a = 1.0;
  a1 = 3.1415 * a;
  a2 = M_PI * a;
  a3 = 3.14159265358979323846 * a;
}
Finally, a1 is equal to 3.1415 and a2 and a3 are equal to 0.

It looks like too long float constants are not converted into double values.

But it's not a problem (for me ;)) anymore because of the workaround of redefining a PI constant. But maybe it's a limitation of the gen_math library...

Posted: Sun Aug 17, 2008 10:27 am
by dom
I've not tried this out, but you can use the -doublestr option which will mean that all conversions into doubles will happen at run time rather than compile time.