Changes in uspace/app/tester/float/softfloat1.c [7218fe6:3e6a98c5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/float/softfloat1.c
r7218fe6 r3e6a98c5 39 39 #include "../tester.h" 40 40 41 #define OPERANDS 41 #define OPERANDS 10 42 42 #define PRECISION 10000 43 43 … … 56 56 cmptype_t *); 57 57 58 #define NUMBERS 58 #define NUMBERS \ 59 59 3.5, -2.1, 100.0, 50.0, -1024.0, 0.0, 768.3156, 1080.499999, -600.0, 1.0 60 60 … … 63 63 }; 64 64 65 static double dop_a[OPERANDS] = 65 static double dop_a[OPERANDS] = { 66 66 NUMBERS 67 67 }; … … 83 83 if (a < b) 84 84 return -1; 85 86 if (a > b) 85 else if (a > b) 87 86 return 1; 88 87 89 88 return 0; 90 89 } 91 90 92 static void uint_to_double_template(void *f, unsigned i, cmptype_t *pic, 93 cmptype_t *pisc) 94 { 95 uint_to_double_op_t op = (uint_to_double_op_t) f; 96 91 static void 92 uint_to_double_template(void *f, unsigned i, cmptype_t *pic, cmptype_t *pisc) 93 { 97 94 double c; 98 95 double_t sc; 96 97 uint_to_double_op_t op = (uint_to_double_op_t) f; 98 99 99 op(uop_a[i], &c, &sc); 100 100 101 101 *pic = (cmptype_t) (c * PRECISION); 102 102 *pisc = (cmptype_t) (sc.val * PRECISION); 103 103 } 104 104 105 static void double_to_uint_template(void *f, unsigned i, cmptype_t *pic, 106 cmptype_t *pisc) 107 { 108 double_to_uint_op_t op = (double_to_uint_op_t) f; 109 105 static void 106 double_to_uint_template(void *f, unsigned i, cmptype_t *pic, cmptype_t *pisc) 107 { 110 108 unsigned int c; 111 109 unsigned int sc; 110 111 double_to_uint_op_t op = (double_to_uint_op_t) f; 112 112 113 op(dop_a[i], &c, &sc); 113 114 114 115 *pic = (cmptype_t) c; 115 116 *pisc = (cmptype_t) sc; … … 117 118 118 119 119 static void float_template_binary(void *f, unsigned i, unsigned j, 120 cmptype_t *pic, cmptype_t *pisc) 121 { 122 float_binary_op_t op = (float_binary_op_t) f; 123 120 static void 121 float_template_binary(void *f, unsigned i, unsigned j, cmptype_t *pic, 122 cmptype_t *pisc) 123 { 124 124 float c; 125 125 float_t sc; 126 127 float_binary_op_t op = (float_binary_op_t) f; 128 126 129 op(fop_a[i], fop_a[j], &c, &sc); 127 130 128 131 *pic = (cmptype_t) (c * PRECISION); 129 132 *pisc = (cmptype_t) (sc.val * PRECISION); 130 133 } 131 134 132 static void double_template_binary(void *f, unsigned i, unsigned j, 133 cmptype_t *pic, cmptype_t *pisc) 134 { 135 double_binary_op_t op = (double_binary_op_t) f; 136 135 static void 136 double_template_binary(void *f, unsigned i, unsigned j, cmptype_t *pic, 137 cmptype_t *pisc) 138 { 137 139 double c; 138 140 double_t sc; 141 142 double_binary_op_t op = (double_binary_op_t) f; 143 139 144 op(dop_a[i], dop_a[j], &c, &sc); 140 145 141 146 *pic = (cmptype_t) (c * PRECISION); 142 147 *pisc = (cmptype_t) (sc.val * PRECISION); 143 148 } 144 149 145 static void double_compare_template(void *f, unsigned i, unsigned j, 146 cmptype_t *pis, cmptype_t *piss) 150 static void 151 double_compare_template(void *f, unsigned i, unsigned j, cmptype_t *pis, 152 cmptype_t *piss) 147 153 { 148 154 double_cmp_op_t op = (double_cmp_op_t) f; … … 158 164 cmptype_t ic; 159 165 cmptype_t isc; 160 161 template(f, i, &ic, &isc); 166 167 template(f, i, &ic, &isc); 162 168 cmptype_t diff = cmpabs(ic - isc); 163 169 164 170 if (diff != 0) { 165 171 TPRINTF("i=%u diff=%" PRIdCMPTYPE "\n", i, diff); … … 176 182 177 183 for (unsigned int i = 0; i < OPERANDS; i++) { 178 for (unsigned int j = 0; j < OPERANDS; j++) { 184 for (unsigned int j = 0; j < OPERANDS; j++) { 179 185 cmptype_t ic; 180 186 cmptype_t isc; 181 182 template(f, i, j, &ic, &isc); 187 188 template(f, i, j, &ic, &isc); 183 189 cmptype_t diff = cmpabs(ic - isc); 184 190 … … 200 206 } 201 207 202 static void double_to_uint_operator(double a, unsigned int *pc,203 204 { 205 double_t sa; 206 207 sa.val = a; 208 208 static void 209 double_to_uint_operator(double a, unsigned int *pc, unsigned int *psc) 210 { 211 double_t sa; 212 213 sa.val = a; 214 209 215 *pc = (unsigned int) a; 210 216 *psc = double_to_uint(sa.data); 211 217 } 212 218 213 static void double_to_int_operator(double a, unsigned int *pc,214 215 { 216 double_t sa; 217 218 sa.val = a; 219 219 static void 220 double_to_int_operator(double a, unsigned int *pc, unsigned int *psc) 221 { 222 double_t sa; 223 224 sa.val = a; 225 220 226 *pc = (int) a; 221 227 *psc = double_to_int(sa.data); … … 231 237 sa.val = a; 232 238 sb.val = b; 233 234 if (sa.data.parts.sign == sb.data.parts.sign) { 239 if (sa.data.parts.sign == sb.data.parts.sign) 235 240 psc->data = add_float(sa.data, sb.data); 236 }else if (sa.data.parts.sign) {241 else if (sa.data.parts.sign) { 237 242 sa.data.parts.sign = 0; 238 243 psc->data = sub_float(sb.data, sa.data); … … 262 267 return; 263 268 } 264 269 265 270 *pc = a / b; 266 271 … … 282 287 sa.val = a; 283 288 sb.val = b; 284 285 if (sa.data.parts.sign == sb.data.parts.sign) { 289 if (sa.data.parts.sign == sb.data.parts.sign) 286 290 psc->data = add_double(sa.data, sb.data); 287 }else if (sa.data.parts.sign) {291 else if (sa.data.parts.sign) { 288 292 sa.data.parts.sign = 0; 289 293 psc->data = sub_double(sb.data, sa.data); … … 313 317 return; 314 318 } 315 319 316 320 *pc = a / b; 317 321 … … 324 328 } 325 329 326 static void double_cmp_operator(double a, double b, cmptype_t *pis,327 330 static void 331 double_cmp_operator(double a, double b, cmptype_t *pis, cmptype_t *piss) 328 332 { 329 333 *pis = dcmp(a, b); 330 334 331 335 double_t sa; 332 336 double_t sb; 333 334 sa.val = a; 335 sb.val = b; 336 337 338 sa.val = a; 339 sb.val = b; 340 337 341 if (is_double_lt(sa.data, sb.data)) 338 342 *piss = -1; … … 348 352 { 349 353 const char *err = NULL; 350 354 351 355 if (!test_template_binary(float_template_binary, float_add_operator)) { 352 356 err = "Float addition failed"; 353 357 TPRINTF("%s\n", err); 354 358 } 355 356 359 if (!test_template_binary(float_template_binary, float_mul_operator)) { 357 360 err = "Float multiplication failed"; 358 361 TPRINTF("%s\n", err); 359 362 } 360 361 363 if (!test_template_binary(float_template_binary, float_div_operator)) { 362 364 err = "Float division failed"; 363 365 TPRINTF("%s\n", err); 364 366 } 365 366 367 if (!test_template_binary(double_template_binary, double_add_operator)) { 367 368 err = "Double addition failed"; 368 369 TPRINTF("%s\n", err); 369 370 } 370 371 371 if (!test_template_binary(double_template_binary, double_mul_operator)) { 372 372 err = "Double multiplication failed"; 373 373 TPRINTF("%s\n", err); 374 374 } 375 376 375 if (!test_template_binary(double_template_binary, double_div_operator)) { 377 376 err = "Double division failed"; 378 377 TPRINTF("%s\n", err); 379 378 } 380 381 379 if (!test_template_binary(double_compare_template, double_cmp_operator)) { 382 380 err = "Double comparison failed"; 383 381 TPRINTF("%s\n", err); 384 382 } 385 386 383 if (!test_template_unary(uint_to_double_template, 387 384 uint_to_double_operator)) { … … 389 386 TPRINTF("%s\n", err); 390 387 } 391 392 388 if (!test_template_unary(double_to_uint_template, 393 389 double_to_uint_operator)) { … … 395 391 TPRINTF("%s\n", err); 396 392 } 397 398 393 if (!test_template_unary(double_to_uint_template, 399 394 double_to_int_operator)) { … … 404 399 return err; 405 400 } 401
Note:
See TracChangeset
for help on using the changeset viewer.