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