mlib update: modify new files to compile on aros
[tangerine.git] / test / mathtest.c
blobcb4dcb76199ae05ac35ab14eee9d39a8dbb24de3
1 #include <proto/exec.h>
2 #include <proto/aros.h>
3 #include <proto/dos.h>
4 #include <stdio.h>
7 double X_Mul(double x, double y)
9 if (x==x) return x*y;
10 return x*y;
13 /* to avoid casts these two lines are absolutely necessary!!*/
14 #define float LONG
16 #include <proto/mathffp.h>
17 #include <proto/mathtrans.h>
18 #include <proto/mathieeesingbas.h>
19 #include <proto/mathieeesingtrans.h>
20 #include <proto/mathieeedoubbas.h>
21 #include <proto/mathieeedoubtrans.h>
23 #include <stdio.h>
25 #include <exec/types.h>
27 struct Library * MathBase;
28 struct Library * MathTransBase;
29 struct Library * MathIeeeSingBasBase;
30 struct Library * MathIeeeSingTransBase;
31 struct Library * MathIeeeDoubBasBase;
32 struct Library * MathIeeeDoubTransBase;
36 int main(int argc, char ** argv)
38 float FFPOne, FFPTwo, FFPOnehalf, FFPMinusOne, FFPNull;
39 float SPOne, SPTwo, SPOnehalf;
40 float float_res;
41 LONG * float_resptr = (LONG *)&float_res;
42 LONG * ptr;
43 LONG wanted;
44 double double_res, double_res2;
45 double * Darg1, * Darg2;
46 QUAD * double_resptr = (QUAD *)&double_res;
47 QUAD * double_resptr2 = (QUAD *)&double_res2;
48 QUAD QArg1, QArg2;
50 Darg1 = (double *)&QArg1;
51 Darg2 = (double *)&QArg2;
53 #define DEF_FFPOne 0x80000041UL
54 #define DEF_FFPTwo 0x80000042UL
55 #define DEF_FFPMinusOne 0x800000C1UL
56 #define DEF_FFPOnehalf 0x80000040UL
57 #define DEF_FFPNull 0x00000000UL
59 #define DEF_SPOne 0x3f800000UL
60 #define DEF_SPTwo 0x40000000UL
61 #define DEF_SPOnehalf 0x3f000000UL
63 #define DEF_DPOne 0x3ff0000000000000ULL
64 #define DEF_DPMinusOne 0xbff0000000000000ULL
65 #define DEF_DPTwo 0x4000000000000000ULL
66 #define DEF_DPThree 0x4008000000000000ULL
67 #define DEF_DPFour 0x4010000000000000ULL
68 #define DEF_DPTwenty 0x4034000000000000ULL
70 ptr = (LONG *)&FFPOne; *ptr = DEF_FFPOne;
71 ptr = (LONG *)&FFPTwo; *ptr = DEF_FFPTwo;
72 ptr = (LONG *)&FFPMinusOne; *ptr = DEF_FFPMinusOne;
73 ptr = (LONG *)&FFPOnehalf; *ptr = DEF_FFPOnehalf;
74 ptr = (LONG *)&FFPNull; *ptr = DEF_FFPNull;
76 ptr = (LONG *)&SPOne; *ptr = DEF_SPOne;
77 ptr = (LONG *)&SPOnehalf; *ptr = DEF_SPOnehalf;
78 ptr = (LONG *)&SPTwo; *ptr = DEF_SPTwo;
80 /* if you deactivate #define float LONG something very funny happens here:
81 printf("two: %x <-> %x \n",*ptr,SPTwo);
82 printf("two: %x <-> %x \n",SPTwo,*ptr);
85 #define CHECK(func, args, cres) \
86 float_res = func args; \
87 if (*float_resptr != cres) \
88 printf ("FAIL: " #func " " #args " in line %d (got=0x%08lx expected=0x%08lx)\n", \
89 __LINE__, *float_resptr, cres); \
90 else \
91 printf ("OK : " #func " " #args "\n");
94 When using doubles or QUADs it is important to pay attention to the Endianess of the processor,
95 otherwise you'll never see what you want to see.
98 #define CHECK_DOUBLE1A(func, arg1, cres) \
99 double_res = func (arg1); \
100 if (*double_resptr != cres) \
102 if (0 != AROS_BIG_ENDIAN) \
104 printf ("FAIL: " #func " " #arg1 " in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
105 __LINE__, \
106 (LONG)(((QUAD)*double_resptr)>>32),*(((LONG *)double_resptr)+1), \
107 (LONG)(((QUAD)cres)>>32),(LONG)cres); \
109 else \
111 printf ("(little endian) FAIL: " #func " " #arg1 " in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
112 __LINE__, \
113 *(((LONG *)double_resptr)+1),*(((LONG *)double_resptr)), \
114 (LONG)(((QUAD)cres)>>32),(LONG)cres); \
117 else \
118 printf ("OK : " #func " " #arg1 "\n");
120 #define CHECK_DOUBLE1B(func, arg1, cres) \
121 QArg1 = arg1; \
122 double_res = func (*Darg1); \
123 if (*double_resptr != cres) \
125 if (0 != AROS_BIG_ENDIAN) \
127 printf ("FAIL: " #func " " #arg1 " in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
128 __LINE__, \
129 (LONG)(((QUAD)*double_resptr)>>32),*(((LONG *)double_resptr)+1), \
130 (LONG)(((QUAD)cres)>>32),(LONG)cres); \
132 else \
134 printf ("(little endian) FAIL: " #func " " #arg1 " in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
135 __LINE__, \
136 *(((LONG *)double_resptr)+1),*(((LONG *)double_resptr)), \
137 (LONG)(((QUAD)cres)>>32),(LONG)cres); \
140 else \
141 printf ("OK : " #func " " #arg1 "\n");
143 #define CHECK_DOUBLE2A(func, arg1, arg2, cres) \
144 double_res = func (arg1, arg2); \
145 double_res2 = cres; \
146 if (double_res != double_res2) \
148 if (0 != AROS_BIG_ENDIAN) \
150 printf ("FAIL: " #func " (" #arg1 "," #arg2 ") in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
151 __LINE__, \
152 (LONG)(((QUAD)*double_resptr )>>32),*(((LONG *)double_resptr )+1), \
153 (LONG)(((QUAD)*double_resptr2)>>32),*(((LONG *)double_resptr2)+1) ); \
155 else \
157 printf ("(little endian) FAIL: " #func " (" #arg1 "," #arg2 ") in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
158 __LINE__, \
159 *(((LONG *)double_resptr )+1),*(((LONG *)double_resptr)), \
160 *(((LONG *)double_resptr2)+1),*(((LONG *)double_resptr2)) ); \
163 else \
164 printf ("OK : " #func " ( " #arg1 "," #arg2 " ) \n");
171 if (!(MathBase = OpenLibrary("mathffp.library", 0L)))
173 printf ("Couldn't open mathffp.library\n");
174 return (0);
177 printf("Very basic mathffp functionality test...\n");
179 /* this should set the zero-bit*/
180 wanted = DEF_FFPNull; CHECK(SPAbs,(0),wanted);
182 wanted = DEF_FFPNull; CHECK(SPFlt,(0),wanted);
183 wanted = DEF_FFPOne; CHECK(SPFlt,(1),wanted);
184 wanted = DEF_FFPTwo; CHECK(SPFlt,(2),wanted);
185 wanted = DEF_FFPMinusOne; CHECK(SPFlt,(-1),wanted);
186 wanted = DEF_FFPTwo; CHECK(SPAdd,(FFPOne, FFPOne),wanted);
187 wanted = DEF_FFPOnehalf; CHECK(SPDiv,(FFPTwo, FFPOne),wanted);
188 wanted = DEF_FFPTwo; CHECK(SPMul,(FFPOne, FFPTwo),wanted);
189 CloseLibrary(MathBase);
191 if (!(MathTransBase = OpenLibrary("mathtrans.library", 0L)))
193 fprintf (stderr, "Couldn't open mathtrans.library\n");
194 return (0);
197 printf("Very basic mathtrans functionality test...\n");
199 CHECK (SPLog, (FFPTwo), 0xb1721840UL);
200 CHECK (SPLog10, (FFPTwo), 0x9a209b3fUL);
201 CHECK (SPSin, (FFPOne), 0xd76aa440UL);
202 CHECK (SPCos, (FFPOne), 0x8a514040UL);
203 CHECK (SPTan, (FFPOne), 0xc7592341UL);
204 CHECK (SPSinh, (FFPOne), 0x966cfe41UL);
205 CHECK (SPCosh, (FFPOne), 0xc583aa41UL);
206 CHECK (SPTanh, (FFPOne), 0xc2f7d640UL);
207 CHECK (SPExp, (FFPTwo), 0xec732543UL);
208 CHECK (SPAsin, (FFPOnehalf), 0x860a9240UL);
209 CHECK (SPAcos, (FFPOnehalf), 0x860a9241UL);
211 CloseLibrary(MathTransBase);
213 if (!(MathIeeeSingBasBase = OpenLibrary("mathieeesingbas.library", 0L)))
215 printf ("Couldn't open mathieeesingbas.library\n");
216 return (0);
220 if (!(MathIeeeSingTransBase = OpenLibrary("mathieeesingtrans.library", 0L)))
222 printf ("Couldn't open mathieeesingtrans.library\n");
223 return (0);
226 printf("Very basic mathieeesingtrans functionality test...\n");
229 CHECK (IEEESPLog, (SPTwo), 0x3f317218UL);
230 CHECK (IEEESPLog10, (SPTwo), 0x3e9a209aUL);
231 CHECK (IEEESPSin, (SPOne), 0x3f576aa4UL);
232 CHECK (IEEESPCos, (SPOne), 0x3f0a5140UL);
233 CHECK (IEEESPTan, (SPOne), 0x3fc75923UL);
234 CHECK (IEEESPSinh, (SPTwo), 0x40681e7bUL);
235 CHECK (IEEESPCosh, (SPTwo), 0x4070c7d1UL);
236 CHECK (IEEESPTanh, (SPOne), 0x3f42f7d6UL);
237 CHECK (IEEESPExp, (SPTwo), 0x40ec7325UL);
238 CHECK (IEEESPAsin, (SPOnehalf), 0x3f060a92UL);
239 CHECK (IEEESPAcos, (SPOnehalf), 0x3f860a92UL);
241 CloseLibrary(MathIeeeSingTransBase);
243 if (!(MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library", 0L)))
245 printf ("Couldn't open mathieeedoubbas.library\n");
246 return (0);
251 CHECK_DOUBLE1A(IEEEDPFlt, ((LONG)1), DEF_DPOne);
252 CHECK_DOUBLE1A(IEEEDPFlt, ((LONG)2), DEF_DPTwo);
253 CHECK_DOUBLE1A(IEEEDPFlt, ((LONG)3), DEF_DPThree);
254 CHECK_DOUBLE1A(IEEEDPFlt, ((LONG)20), DEF_DPTwenty);
255 CHECK_DOUBLE1B(IEEEDPAbs, ((QUAD)DEF_DPMinusOne), (QUAD)DEF_DPOne);
256 CHECK_DOUBLE1B(IEEEDPNeg, ((QUAD)DEF_DPMinusOne), (QUAD)DEF_DPOne);
257 CHECK_DOUBLE2A(IEEEDPAdd, IEEEDPFlt(1), IEEEDPFlt(1), IEEEDPFlt(2));
258 CHECK_DOUBLE2A(IEEEDPAdd, IEEEDPFlt(123456), IEEEDPFlt(654321), IEEEDPFlt(777777));
259 CHECK_DOUBLE2A(IEEEDPSub, IEEEDPFlt(123456), IEEEDPFlt(654321), IEEEDPFlt(-530865));
260 CHECK_DOUBLE2A(IEEEDPMul, IEEEDPFlt(321), IEEEDPFlt(123456), IEEEDPFlt(39629376));
261 CHECK_DOUBLE2A(IEEEDPMul, IEEEDPFlt(2), IEEEDPFlt(2), IEEEDPFlt(4));
262 CHECK_DOUBLE2A(IEEEDPMul, IEEEDPFlt(20), IEEEDPFlt(20), IEEEDPFlt(400));
265 if (!(MathIeeeDoubTransBase = OpenLibrary("mathieeedoubtrans.library", 0L)))
267 printf ("Couldn't open mathieeedoubtrans.library\n");
268 return (0);
271 CHECK_DOUBLE1A(IEEEDPSqrt, ((double)IEEEDPFlt(4)), DEF_DPTwo);
272 CHECK_DOUBLE1A(IEEEDPSqrt, ((double)IEEEDPFlt(9)), DEF_DPThree);
273 CHECK_DOUBLE1A(IEEEDPCos, ((double)IEEEDPFlt(1)), 0x3fe14a280fb5068bULL);
274 CHECK_DOUBLE1A(IEEEDPSin, ((double)IEEEDPFlt(1)), 0x3feaed548f090ceeULL);
276 CloseLibrary(MathIeeeDoubTransBase);
277 CloseLibrary(MathIeeeDoubBasBase);
279 return (0);