dos.library: Ensure that if SYS_Input and SYS_ScriptInput are the same on input,...
[AROS.git] / test / mathtest.c
blobb280fd3cadd3c9d1b2951738a7f5f2fe068ea5b8
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;
46 QUAD * double_resptr = (QUAD *)&double_res;
47 QUAD * double_resptr2 = (QUAD *)&double_res2;
48 QUAD QArg1;
50 Darg1 = (double *)&QArg1;
52 #define DEF_FFPOne 0x80000041UL
53 #define DEF_FFPTwo 0x80000042UL
54 #define DEF_FFPMinusOne 0x800000C1UL
55 #define DEF_FFPOnehalf 0x80000040UL
56 #define DEF_FFPNull 0x00000000UL
58 #define DEF_SPOne 0x3f800000UL
59 #define DEF_SPTwo 0x40000000UL
60 #define DEF_SPOnehalf 0x3f000000UL
62 #define DEF_DPOne 0x3ff0000000000000ULL
63 #define DEF_DPMinusOne 0xbff0000000000000ULL
64 #define DEF_DPTwo 0x4000000000000000ULL
65 #define DEF_DPThree 0x4008000000000000ULL
66 #define DEF_DPFour 0x4010000000000000ULL
67 #define DEF_DPTwenty 0x4034000000000000ULL
69 ptr = (LONG *)&FFPOne; *ptr = DEF_FFPOne;
70 ptr = (LONG *)&FFPTwo; *ptr = DEF_FFPTwo;
71 ptr = (LONG *)&FFPMinusOne; *ptr = DEF_FFPMinusOne;
72 ptr = (LONG *)&FFPOnehalf; *ptr = DEF_FFPOnehalf;
73 ptr = (LONG *)&FFPNull; *ptr = DEF_FFPNull;
75 ptr = (LONG *)&SPOne; *ptr = DEF_SPOne;
76 ptr = (LONG *)&SPOnehalf; *ptr = DEF_SPOnehalf;
77 ptr = (LONG *)&SPTwo; *ptr = DEF_SPTwo;
79 /* if you deactivate #define float LONG something very funny happens here:
80 printf("two: %x <-> %x \n",*ptr,SPTwo);
81 printf("two: %x <-> %x \n",SPTwo,*ptr);
84 #define CHECK(func, args, cres) \
85 float_res = func args; \
86 if (*float_resptr != cres) \
87 printf ("FAIL: " #func " " #args " in line %d (got=0x%08lx expected=0x%08lx)\n", \
88 __LINE__, (unsigned long)*float_resptr, (unsigned long)cres); \
89 else \
90 printf ("OK : " #func " " #args "\n");
93 When using doubles or QUADs it is important to pay attention to the Endianess of the processor,
94 otherwise you'll never see what you want to see.
97 #define CHECK_DOUBLE1A(func, arg1, cres) \
98 double_res = func (arg1); \
99 if (*double_resptr != cres) \
101 if (0 != AROS_BIG_ENDIAN) \
103 printf ("FAIL: " #func " " #arg1 " in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
104 __LINE__, \
105 (unsigned long)(((QUAD)*double_resptr)>>32),(unsigned long)*(((LONG *)double_resptr)+1), \
106 (unsigned long)(((QUAD)cres)>>32),(unsigned long)cres); \
108 else \
110 printf ("(little endian) FAIL: " #func " " #arg1 " in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
111 __LINE__, \
112 (unsigned long)*(((LONG *)double_resptr)+1),(unsigned long)*(((LONG *)double_resptr)), \
113 (unsigned long)(((QUAD)cres)>>32),(unsigned long)cres); \
116 else \
117 printf ("OK : " #func " " #arg1 "\n");
119 #define CHECK_DOUBLE1B(func, arg1, cres) \
120 QArg1 = arg1; \
121 double_res = func (*Darg1); \
122 if (*double_resptr != cres) \
124 if (0 != AROS_BIG_ENDIAN) \
126 printf ("FAIL: " #func " " #arg1 " in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
127 __LINE__, \
128 (unsigned long)(((QUAD)*double_resptr)>>32),(unsigned long)*(((LONG *)double_resptr)+1), \
129 (unsigned long)(((QUAD)cres)>>32),(unsigned long)cres); \
131 else \
133 printf ("(little endian) FAIL: " #func " " #arg1 " in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
134 __LINE__, \
135 (unsigned long)*(((LONG *)double_resptr)+1),(unsigned long)*(((LONG *)double_resptr)), \
136 (unsigned long)(((QUAD)cres)>>32),(unsigned long)cres); \
139 else \
140 printf ("OK : " #func " " #arg1 "\n");
142 #define CHECK_DOUBLE2A(func, arg1, arg2, cres) \
143 double_res = func (arg1, arg2); \
144 double_res2 = cres; \
145 if (double_res != double_res2) \
147 if (0 != AROS_BIG_ENDIAN) \
149 printf ("FAIL: " #func " (" #arg1 "," #arg2 ") in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
150 __LINE__, \
151 (unsigned long)(((QUAD)*double_resptr )>>32),(unsigned long)*(((LONG *)double_resptr )+1), \
152 (unsigned long)(((QUAD)*double_resptr2)>>32),(unsigned long)*(((LONG *)double_resptr2)+1) ); \
154 else \
156 printf ("(little endian) FAIL: " #func " (" #arg1 "," #arg2 ") in line %d (got=0x%08lx%08lx expected=0x%08lx%08lx)\n", \
157 __LINE__, \
158 (unsigned long)*(((LONG *)double_resptr )+1),(unsigned long)*(((LONG *)double_resptr)), \
159 (unsigned long)*(((LONG *)double_resptr2)+1),(unsigned long)*(((LONG *)double_resptr2)) ); \
162 else \
163 printf ("OK : " #func " ( " #arg1 "," #arg2 " ) \n");
170 if (!(MathBase = OpenLibrary("mathffp.library", 0L)))
172 printf ("Couldn't open mathffp.library\n");
173 return (0);
176 printf("Very basic mathffp functionality test...\n");
178 /* this should set the zero-bit*/
179 wanted = DEF_FFPNull; CHECK(SPAbs,(0),wanted);
181 wanted = DEF_FFPNull; CHECK(SPFlt,(0),wanted);
182 wanted = DEF_FFPOne; CHECK(SPFlt,(1),wanted);
183 wanted = DEF_FFPTwo; CHECK(SPFlt,(2),wanted);
184 wanted = DEF_FFPMinusOne; CHECK(SPFlt,(-1),wanted);
185 wanted = DEF_FFPTwo; CHECK(SPAdd,(FFPOne, FFPOne),wanted);
186 wanted = DEF_FFPOnehalf; CHECK(SPDiv,(FFPTwo, FFPOne),wanted);
187 wanted = DEF_FFPTwo; CHECK(SPMul,(FFPOne, FFPTwo),wanted);
188 CloseLibrary(MathBase);
190 if (!(MathTransBase = OpenLibrary("mathtrans.library", 0L)))
192 fprintf (stderr, "Couldn't open mathtrans.library\n");
193 return (0);
196 printf("Very basic mathtrans functionality test...\n");
198 CHECK (SPLog, (FFPTwo), 0xb1721840UL);
199 CHECK (SPLog10, (FFPTwo), 0x9a209b3fUL);
200 CHECK (SPSin, (FFPOne), 0xd76aa440UL);
201 CHECK (SPCos, (FFPOne), 0x8a514040UL);
202 CHECK (SPTan, (FFPOne), 0xc7592341UL);
203 CHECK (SPSinh, (FFPOne), 0x966cfe41UL);
204 CHECK (SPCosh, (FFPOne), 0xc583aa41UL);
205 CHECK (SPTanh, (FFPOne), 0xc2f7d640UL);
206 CHECK (SPExp, (FFPTwo), 0xec732543UL);
207 CHECK (SPAsin, (FFPOnehalf), 0x860a9240UL);
208 CHECK (SPAcos, (FFPOnehalf), 0x860a9241UL);
210 CloseLibrary(MathTransBase);
212 if (!(MathIeeeSingBasBase = OpenLibrary("mathieeesingbas.library", 0L)))
214 printf ("Couldn't open mathieeesingbas.library\n");
215 return (0);
219 if (!(MathIeeeSingTransBase = OpenLibrary("mathieeesingtrans.library", 0L)))
221 printf ("Couldn't open mathieeesingtrans.library\n");
222 return (0);
225 printf("Very basic mathieeesingtrans functionality test...\n");
228 CHECK (IEEESPLog, (SPTwo), 0x3f317218UL);
229 CHECK (IEEESPLog10, (SPTwo), 0x3e9a209aUL);
230 CHECK (IEEESPSin, (SPOne), 0x3f576aa4UL);
231 CHECK (IEEESPCos, (SPOne), 0x3f0a5140UL);
232 CHECK (IEEESPTan, (SPOne), 0x3fc75923UL);
233 CHECK (IEEESPSinh, (SPTwo), 0x40681e7bUL);
234 CHECK (IEEESPCosh, (SPTwo), 0x4070c7d1UL);
235 CHECK (IEEESPTanh, (SPOne), 0x3f42f7d6UL);
236 CHECK (IEEESPExp, (SPTwo), 0x40ec7325UL);
237 CHECK (IEEESPAsin, (SPOnehalf), 0x3f060a92UL);
238 CHECK (IEEESPAcos, (SPOnehalf), 0x3f860a92UL);
240 CloseLibrary(MathIeeeSingTransBase);
242 if (!(MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library", 0L)))
244 printf ("Couldn't open mathieeedoubbas.library\n");
245 return (0);
250 CHECK_DOUBLE1A(IEEEDPFlt, ((LONG)1), DEF_DPOne);
251 CHECK_DOUBLE1A(IEEEDPFlt, ((LONG)2), DEF_DPTwo);
252 CHECK_DOUBLE1A(IEEEDPFlt, ((LONG)3), DEF_DPThree);
253 CHECK_DOUBLE1A(IEEEDPFlt, ((LONG)20), DEF_DPTwenty);
254 CHECK_DOUBLE1B(IEEEDPAbs, ((QUAD)DEF_DPMinusOne), (QUAD)DEF_DPOne);
255 CHECK_DOUBLE1B(IEEEDPNeg, ((QUAD)DEF_DPMinusOne), (QUAD)DEF_DPOne);
256 CHECK_DOUBLE2A(IEEEDPAdd, IEEEDPFlt(1), IEEEDPFlt(1), IEEEDPFlt(2));
257 CHECK_DOUBLE2A(IEEEDPAdd, IEEEDPFlt(123456), IEEEDPFlt(654321), IEEEDPFlt(777777));
258 CHECK_DOUBLE2A(IEEEDPSub, IEEEDPFlt(123456), IEEEDPFlt(654321), IEEEDPFlt(-530865));
259 CHECK_DOUBLE2A(IEEEDPMul, IEEEDPFlt(321), IEEEDPFlt(123456), IEEEDPFlt(39629376));
260 CHECK_DOUBLE2A(IEEEDPMul, IEEEDPFlt(2), IEEEDPFlt(2), IEEEDPFlt(4));
261 CHECK_DOUBLE2A(IEEEDPMul, IEEEDPFlt(20), IEEEDPFlt(20), IEEEDPFlt(400));
264 if (!(MathIeeeDoubTransBase = OpenLibrary("mathieeedoubtrans.library", 0L)))
266 printf ("Couldn't open mathieeedoubtrans.library\n");
267 return (0);
270 CHECK_DOUBLE1A(IEEEDPSqrt, ((double)IEEEDPFlt(4)), DEF_DPTwo);
271 CHECK_DOUBLE1A(IEEEDPSqrt, ((double)IEEEDPFlt(9)), DEF_DPThree);
272 CHECK_DOUBLE1A(IEEEDPCos, ((double)IEEEDPFlt(1)), 0x3fe14a280fb5068bULL);
273 CHECK_DOUBLE1A(IEEEDPSin, ((double)IEEEDPFlt(1)), 0x3feaed548f090ceeULL);
275 CloseLibrary(MathIeeeDoubTransBase);
276 CloseLibrary(MathIeeeDoubBasBase);
278 return (0);