MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxNumberToBigInt

Function fxNumberToBigInt

xs/sources/xsBigInt.c:724–751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

722}
723
724txBigInt* fxNumberToBigInt(txMachine* the, txSlot* slot)
725{
726 txBigInt* bigint = &slot->value.bigint;
727 txNumber number = slot->value.number;
728 txNumber limit = 4294967296;
729 txU1 sign = 0;
730 txU2 size = 1;
731 if (number < 0) {
732 number = -number;
733 sign = 1;
734 }
735 while (number >= limit) {
736 size++;
737 number /= limit;
738 }
739 bigint->data = fxNewChunk(the, fxMultiplyChunkSizes(the, size, sizeof(txU4)));
740 bigint->size = size;
741 while (size > 0) {
742 txU4 part = (txU4)number;
743 number -= part;
744 size--;
745 bigint->data[size] = part;
746 number *= limit;
747 }
748 bigint->sign = sign;
749 slot->kind = XS_BIGINT_KIND;
750 return bigint;
751}
752
753txBigInt* fxStringToBigInt(txMachine* the, txSlot* slot, txFlag whole)
754{

Callers 3

fx_BigIntFunction · 0.85
fxBigIntCompareFunction · 0.85
fxToBigIntFunction · 0.85

Calls 1

fxNewChunkFunction · 0.85

Tested by

no test coverage detected