Math library

Amstrad CPC and NC systems
Post Reply
kyrio
New member
Posts: 2
Joined: Thu Aug 14, 2008 7:32 pm

Math library

Post 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.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Post 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
kyrio
New member
Posts: 2
Joined: Thu Aug 14, 2008 7:32 pm

Post 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...
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Post 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.
Post Reply