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

Function fx_BigInt_asIntN

xs/sources/xsBigInt.c:149–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147}
148
149void fx_BigInt_asIntN(txMachine* the)
150{
151 txInteger index = (txInteger)fx_BigInt_asAux(the);
152 txBigInt* arg = fxToBigInt(the, mxArgv(1), 1);
153 txBigInt* result;
154 if (fxBigInt_iszero(arg)) {
155 result = fxBigInt_dup(the, arg);
156 }
157 else {
158 txBigInt* bits = fxBigInt_ulsl1(the, C_NULL, (txBigInt *)&gxBigIntOne, index);
159 txBigInt* mask = fxBigInt_usub(the, C_NULL, bits, (txBigInt *)&gxBigIntOne);
160 result = fxBigInt_uand(the, C_NULL, arg, mask);
161 if ((arg->sign) && !fxBigInt_iszero(result))
162 result = fxBigInt_usub(the, C_NULL, bits, result);
163 if (index && fxBigInt_comp(result, fxBigInt_ulsl1(the, C_NULL, (txBigInt *)&gxBigIntOne, index - 1)) >= 0)
164 result = fxBigInt_sub(the, C_NULL, result, bits);
165 result = fxBigInt_fit(the, result);
166 }
167 mxResult->value.bigint = *result;
168 mxResult->kind = XS_BIGINT_KIND;
169// txBigInt* bits = fxBigInt_ulsl1(the, C_NULL, (txBigInt *)&gxBigIntOne, index);
170// txBigInt* result = fxBigInt_mod(the, C_NULL, fxToBigInt(the, mxArgv(1), 1), bits);
171// if (index && fxBigInt_comp(result, fxBigInt_ulsl1(the, C_NULL, (txBigInt *)&gxBigIntOne, index - 1)) >= 0)
172// result = fxBigInt_sub(the, C_NULL, result, bits);
173// mxResult->value.bigint = *result;
174// mxResult->kind = XS_BIGINT_KIND;
175}
176
177void fx_BigInt_asUintN(txMachine* the)
178{

Callers

nothing calls this directly

Calls 10

fx_BigInt_asAuxFunction · 0.85
fxToBigIntFunction · 0.85
fxBigInt_iszeroFunction · 0.85
fxBigInt_dupFunction · 0.85
fxBigInt_ulsl1Function · 0.85
fxBigInt_usubFunction · 0.85
fxBigInt_uandFunction · 0.85
fxBigInt_compFunction · 0.85
fxBigInt_subFunction · 0.85
fxBigInt_fitFunction · 0.85

Tested by

no test coverage detected