| 341 | } |
| 342 | |
| 343 | txUnsigned fxToUnsigned(txMachine* the, txSlot* theSlot) |
| 344 | { |
| 345 | txUnsigned result; |
| 346 | again: |
| 347 | switch (theSlot->kind) { |
| 348 | case XS_UNDEFINED_KIND: |
| 349 | case XS_NULL_KIND: |
| 350 | theSlot->kind = XS_INTEGER_KIND; |
| 351 | result = theSlot->value.integer = 0; |
| 352 | break; |
| 353 | case XS_BOOLEAN_KIND: |
| 354 | theSlot->kind = XS_INTEGER_KIND; |
| 355 | if (theSlot->value.boolean == 0) |
| 356 | result = theSlot->value.integer = 0; |
| 357 | else |
| 358 | result = theSlot->value.integer = 1; |
| 359 | break; |
| 360 | case XS_INTEGER_KIND: |
| 361 | if (theSlot->value.integer >= 0) |
| 362 | return (txUnsigned)theSlot->value.integer; |
| 363 | theSlot->kind = XS_NUMBER_KIND; |
| 364 | theSlot->value.number = theSlot->value.integer; |
| 365 | // continue |
| 366 | mxFallThrough; |
| 367 | case XS_NUMBER_KIND: |
| 368 | theSlot->kind = XS_INTEGER_KIND; |
| 369 | switch (c_fpclassify(theSlot->value.number)) { |
| 370 | case C_FP_INFINITE: |
| 371 | case C_FP_NAN: |
| 372 | case C_FP_ZERO: |
| 373 | result = theSlot->value.integer = 0; |
| 374 | break; |
| 375 | default: { |
| 376 | #define MODULO 4294967296.0 |
| 377 | txNumber aNumber = c_fmod(c_trunc(theSlot->value.number), MODULO); |
| 378 | if (aNumber < 0) |
| 379 | aNumber += MODULO; |
| 380 | result = (txUnsigned)aNumber; |
| 381 | if (((txInteger)result) >= 0) { |
| 382 | theSlot->kind = XS_INTEGER_KIND; |
| 383 | theSlot->value.integer = (txInteger)result; |
| 384 | } |
| 385 | else { |
| 386 | theSlot->kind = XS_NUMBER_KIND; |
| 387 | theSlot->value.number = aNumber; |
| 388 | } |
| 389 | } break; |
| 390 | } |
| 391 | mxFloatingPointOp("number to unsigned"); |
| 392 | break; |
| 393 | case XS_STRING_KIND: |
| 394 | case XS_STRING_X_KIND: |
| 395 | theSlot->kind = XS_NUMBER_KIND; |
| 396 | theSlot->value.number = fxStringToNumber(the, theSlot->value.string, 1); |
| 397 | mxMeterOne(); |
| 398 | goto again; |
| 399 | case XS_SYMBOL_KIND: |
| 400 | result = 0; |
no test coverage detected